Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
juharris committed Dec 9, 2024
1 parent c1a1209 commit 4df7653
Showing 1 changed file with 82 additions and 82 deletions.
164 changes: 82 additions & 82 deletions dotnet/tests/Tests/BasinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,57 +296,57 @@ public void MyClass_Elements_Replace_String_In_JsonElement_Test()

}

[TestMethod]
public void MyClass_Elements_Array_Replacement_Test()
{
var basin = new Basin<MyClass>();
const string key = "key";
var ac = new AdaptiveCard("1.5")
{
Body = [
new AdaptiveTextBlock("Hello ")],
};
var acJson = JsonConvert.SerializeObject(ac);
Assert.AreEqual("{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello \"}]}", acJson);
var acJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(acJson);
Assert.AreEqual("Hello ", acJsonElement.GetProperty("body")[0].GetProperty("text").GetString());
basin.Items[key] = new MyClass()
{
Elements = [
acJsonElement,
],
};

var newTextBlock = new AdaptiveTextBlock("Replacement");
var newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
Assert.AreEqual("{\"type\":\"TextBlock\",\"text\":\"Replacement\"}", newTextBlockJson);
var newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);

basin.SetCursor(new BasinCursor
{
JsonPath = $"$.['{key}'].elements[0].body[0]",
});
var writeResult = basin.Write(newTextBlockJsonElement);
Assert.IsNotNull(writeResult, "Item not found at the cursor.");
Assert.AreSame(basin.Items[key], writeResult);
Assert.IsNotNull(writeResult.Elements, "Elements is null.");
Assert.AreEqual("Replacement", writeResult.Elements![0].GetProperty("body")[0].GetProperty("text").GetString());
string expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello World!\"}]}";
var expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
var expected = new Dictionary<string, MyClass>
{
[key] = new MyClass()
{
Elements = [
expectedAcJsonElement,
],
},
};
AssertAreDeepEqual(expected, basin.Items);
}

[Ignore("Applying patches is not supported within `JsonElement`s yet.")]
[TestMethod]
[TestMethod]
public void MyClass_Elements_Array_Replacement_Test()
{
var basin = new Basin<MyClass>();
const string key = "key";
var ac = new AdaptiveCard("1.5")
{
Body = [
new AdaptiveTextBlock("Hello ")],
};
var acJson = JsonConvert.SerializeObject(ac);
Assert.AreEqual("{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello \"}]}", acJson);
var acJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(acJson);
Assert.AreEqual("Hello ", acJsonElement.GetProperty("body")[0].GetProperty("text").GetString());
basin.Items[key] = new MyClass()
{
Elements = [
acJsonElement,
],
};

var newTextBlock = new AdaptiveTextBlock("Replacement");
var newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
Assert.AreEqual("{\"type\":\"TextBlock\",\"text\":\"Replacement\"}", newTextBlockJson);
var newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);

basin.SetCursor(new BasinCursor
{
JsonPath = $"$.['{key}'].elements[0].body[0]",
});
var writeResult = basin.Write(newTextBlockJsonElement);
Assert.IsNotNull(writeResult, "Item not found at the cursor.");
Assert.AreSame(basin.Items[key], writeResult);
Assert.IsNotNull(writeResult.Elements, "Elements is null.");
Assert.AreEqual("Replacement", writeResult.Elements![0].GetProperty("body")[0].GetProperty("text").GetString());
string expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello World!\"}]}";
var expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
var expected = new Dictionary<string, MyClass>
{
[key] = new MyClass()
{
Elements = [
expectedAcJsonElement,
],
},
};
AssertAreDeepEqual(expected, basin.Items);
}

[Ignore("Applying patches is not supported within `JsonElement`s yet.")]
[TestMethod]
public void MyClass_Elements_Array_Patches_Tests()
{
var basin = new Basin<MyClass>();
Expand All @@ -372,7 +372,7 @@ public void MyClass_Elements_Array_Patches_Tests()
Assert.AreEqual("{\"type\":\"TextBlock\",\"text\":\"World!\"}", newTextBlockJson);
var newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);

var patchResult = basin.ApplyPatch(new()
var patchResult = basin.ApplyPatch(new()
{
op = "add",
path = $"/{key}/elements/0/body/1",
Expand All @@ -384,34 +384,34 @@ public void MyClass_Elements_Array_Patches_Tests()
Assert.AreEqual("World!", patchResult.Elements![0].GetProperty("body")[1].GetProperty("text").GetString());

newTextBlock = new AdaptiveTextBlock("Hello to the ");
newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);
basin.SetCursor(new BasinCursor
{
JsonPath = $"$.['{key}'].elements[0].body[0]",
});
var writeResult = basin.Write(newTextBlockJsonElement);
Assert.IsNotNull(writeResult, "Item not found at the cursor.");
Assert.AreSame(basin.Items[key], writeResult);
Assert.IsNotNull(writeResult.Elements, "Elements is null.");
Assert.AreEqual("World!", writeResult.Elements![0].GetProperty("body")[0].GetProperty("text").GetString());
string expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello to the \"},{\"type\":\"TextBlock\",\"text\":\"World!\"}]}";
var expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
var expected = new Dictionary<string, MyClass>
{
[key] = new MyClass()
{
Elements = [
expectedAcJsonElement,
],
},
};
AssertAreDeepEqual(expected, basin.Items);

newTextBlock = new AdaptiveTextBlock("World! What's up?");
newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);
basin.SetCursor(new BasinCursor
newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);
basin.SetCursor(new BasinCursor
{
JsonPath = $"$.['{key}'].elements[0].body[0]",
});
var writeResult = basin.Write(newTextBlockJsonElement);
Assert.IsNotNull(writeResult, "Item not found at the cursor.");
Assert.AreSame(basin.Items[key], writeResult);
Assert.IsNotNull(writeResult.Elements, "Elements is null.");
Assert.AreEqual("World!", writeResult.Elements![0].GetProperty("body")[0].GetProperty("text").GetString());
string expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello to the \"},{\"type\":\"TextBlock\",\"text\":\"World!\"}]}";
var expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
var expected = new Dictionary<string, MyClass>
{
[key] = new MyClass()
{
Elements = [
expectedAcJsonElement,
],
},
};
AssertAreDeepEqual(expected, basin.Items);

newTextBlock = new AdaptiveTextBlock("World! What's up?");
newTextBlockJson = JsonConvert.SerializeObject(newTextBlock);
newTextBlockJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(newTextBlockJson);
basin.SetCursor(new BasinCursor
{
JsonPath = $"$.['{key}'].elements[0].body",
Position = 1,
Expand All @@ -421,8 +421,8 @@ public void MyClass_Elements_Array_Patches_Tests()
Assert.AreSame(basin.Items[key], writeResult);
Assert.IsNotNull(writeResult.Elements, "Elements is null.");
Assert.AreEqual("World! What's up?", writeResult.Elements![0].GetProperty("body")[1].GetProperty("text").GetString());
expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello to the \"},{\"type\":\"TextBlock\",\"text\":\"World! What's up?\"}]}";
expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
expectedAcJson = "{\"type\":\"AdaptiveCard\",\"version\":\"1.5\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"Hello to the \"},{\"type\":\"TextBlock\",\"text\":\"World! What's up?\"}]}";
expectedAcJsonElement = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(expectedAcJson);
expected = new Dictionary<string, MyClass>
{
[key] = new MyClass()
Expand Down

0 comments on commit 4df7653

Please sign in to comment.