|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Linq;
|
| 7 | +using System.Text.Json.Nodes; |
7 | 8 | using Microsoft.Identity.Client.Cache;
|
8 | 9 | using Microsoft.Identity.Client.Internal;
|
9 | 10 | using Microsoft.Identity.Client.OAuth2;
|
@@ -164,6 +165,33 @@ public void Deserialize_TokenResponse()
|
164 | 165 | Assert.AreEqual("eyJ1aWQiOiI2ZWVkYTNhMS1jM2I5LTRlOTItYTk0ZC05NjVhNTBjMDZkZTciLCJ1dGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3In0", response.ClientInfo);
|
165 | 166 |
|
166 | 167 | }
|
167 |
| - } |
168 | 168 |
|
| 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 | + } |
169 | 197 | }
|
0 commit comments