Skip to content

Commit 4084879

Browse files
committed
more tests
1 parent f85ab44 commit 4084879

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/client/Microsoft.Identity.Client/Internal/IdToken.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.Identity.Client.Utils;
1010
using System.Text.Json;
1111

12-
1312
namespace Microsoft.Identity.Client.Internal
1413
{
1514
internal static class IdTokenClaim
@@ -76,7 +75,6 @@ public string GetUniqueId()
7675

7776
public ClaimsPrincipal ClaimsPrincipal { get; private set; }
7877

79-
8078
private static IdToken ClaimsToToken(List<Claim> claims)
8179
{
8280
var principal = new ClaimsPrincipal(new ClaimsIdentity(claims));

tests/Microsoft.Identity.Test.Unit/UtilTests/JsonHelperTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Text.Json.Nodes;
78
using Microsoft.Identity.Client.Cache;
89
using Microsoft.Identity.Client.Internal;
910
using Microsoft.Identity.Client.OAuth2;
@@ -164,6 +165,33 @@ public void Deserialize_TokenResponse()
164165
Assert.AreEqual("eyJ1aWQiOiI2ZWVkYTNhMS1jM2I5LTRlOTItYTk0ZC05NjVhNTBjMDZkZTciLCJ1dGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3In0", response.ClientInfo);
165166

166167
}
167-
}
168168

169+
[DataTestMethod]
170+
[DataRow("{\"name\":\"John\", \"age\":30}", "{\"age\":40, \"city\":\"New York\"}", "{\"name\":\"John\", \"age\":40, \"city\":\"New York\"}")]
171+
[DataRow("[1, 2, 3]", "[4, 5, 6]", "[1, 2, 3, 4, 5, 6]")]
172+
[DataRow("[1, 2, 5]", "[3, 5, 6]", "[1, 2, 5, 3, 5, 6]")]
173+
[DataRow("{\"numbers\":[1, 2, 3]}", "{\"numbers\":[4, 5, 6]}", "{\"numbers\":[1, 2, 3, 4, 5, 6]}")]
174+
[DataRow("{\"value\":10}", "{\"value\":20}", "{\"value\":20}")]
175+
[DataRow("{}", "{\"name\":\"John\", \"age\":30}", "{\"name\":\"John\", \"age\":30}")]
176+
[DataRow("{\"name\":\"John\", \"age\":null}", "{\"age\":30, \"city\":null}", "{\"name\":\"John\", \"age\":30, \"city\":null}")]
177+
[DataRow("{\"person\":{\"name\":\"John\", \"age\":30}}", "{\"person\":{\"age\":40, \"city\":\"New York\"}}", "{\"person\":{\"name\":\"John\", \"age\":40, \"city\":\"New York\"}}")]
178+
[DataRow("{\"array\":[{\"id\":1}, {\"id\":2}]}", "{\"array\":[{\"id\":3}, {\"id\":4}]}", "{\"array\":[{\"id\":1}, {\"id\":2}, {\"id\":3}, {\"id\":4}]}")]
179+
[DataRow("{\"mixed\":{\"array\":[1, 2], \"object\":{\"key\":\"value\"}}}", "{\"mixed\":{\"array\":[3, 4], \"object\":{\"key2\":\"value2\"}}}", "{\"mixed\":{\"array\":[1, 2, 3, 4], \"object\":{\"key\":\"value\", \"key2\":\"value2\"}}}")]
180+
[DataRow("{\"nested\":{\"level1\":{\"level2\":{\"level3\":\"value\"}}}}", "{\"nested\":{\"level1\":{\"level2\":{\"level3\":\"newValue\", \"level4\":\"anotherValue\"}}}}", "{\"nested\":{\"level1\":{\"level2\":{\"level3\":\"newValue\", \"level4\":\"anotherValue\"}}}}")]
181+
[DataRow("{\"boolean\":true}", "{\"boolean\":false}", "{\"boolean\":false}")]
182+
[DataRow("{\"nullValue\":null}", "{\"nullValue\":\"notNull\"}", "{\"nullValue\":\"notNull\"}")]
183+
public void Merge_JsonStrings_ShouldMergeCorrectly(string originalJsonStr, string newContentStr, string expectedJsonStr)
184+
{
185+
// Arrange
186+
var originalJson = JsonNode.Parse(originalJsonStr).AsObject();
187+
var newContent = JsonNode.Parse(newContentStr).AsObject();
188+
var expectedJson = JsonNode.Parse(expectedJsonStr).AsObject();
189+
190+
// Act
191+
JsonObject result = JsonHelper.Merge(originalJson, newContent);
192+
193+
// Assert
194+
JsonTestUtils.AssertJsonDeepEquals(expectedJsonStr, result.ToJsonString());
195+
}
196+
}
169197
}

0 commit comments

Comments
 (0)