Clean up DuplicatePropertyNameHandling feature

This commit is contained in:
James Newton-King
2018-11-24 21:25:20 +13:00
parent a1f1b0aa86
commit 88dae52165
10 changed files with 132 additions and 49 deletions
@@ -162,6 +162,39 @@ namespace Newtonsoft.Json.Tests.Linq
await JToken.ReadFromAsync(reader);
}, "Unexpected end of content while loading JObject. Path 'short.error.code', line 6, position 14.");
}
[Test]
public async Task ParseMultipleProperties_EmptySettingsAsync()
{
string json = @"{
""Name"": ""Name1"",
""Name"": ""Name2""
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
JObject o = (JObject)await JToken.ReadFromAsync(reader, new JsonLoadSettings());
string value = (string)o["Name"];
Assert.AreEqual("Name2", value);
}
[Test]
public async Task ParseMultipleProperties_IgnoreDuplicateSettingAsync()
{
string json = @"{
""Name"": ""Name1"",
""Name"": ""Name2""
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
JObject o = (JObject)await JToken.ReadFromAsync(reader, new JsonLoadSettings
{
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Ignore
});
string value = (string)o["Name"];
Assert.AreEqual("Name1", value);
}
}
}