Clean up DuplicatePropertyNameHandling feature
This commit is contained in:
@@ -1770,11 +1770,11 @@ third line", jsonTextReader.Value);
|
||||
}
|
||||
";
|
||||
|
||||
JsonLoadSettings settings = new JsonLoadSettings { DuplicatePropertyNamesHandling = DuplicatePropertyNamesHandling.Throw };
|
||||
JsonLoadSettings settings = new JsonLoadSettings { DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error };
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
await ExceptionAssert.ThrowsAsync<JsonException>( async () => await JToken.ReadFromAsync(reader, settings));
|
||||
await ExceptionAssert.ThrowsAsync<JsonReaderException>(async () => await JToken.ReadFromAsync(reader, settings));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1761,12 +1761,11 @@ third line", jsonTextReader.Value);
|
||||
}
|
||||
";
|
||||
|
||||
JsonLoadSettings settings = new JsonLoadSettings {DuplicatePropertyNamesHandling = DuplicatePropertyNamesHandling.Throw};
|
||||
JsonLoadSettings settings = new JsonLoadSettings {DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error};
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(() => JObject.Parse(json, settings));
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
ExceptionAssert.Throws<JsonException>(() =>
|
||||
{
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
JToken.ReadFrom(reader, settings);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1604,6 +1604,37 @@ Parameter name: arrayIndex");
|
||||
Assert.AreEqual("Name2", value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseMultipleProperties_EmptySettings()
|
||||
{
|
||||
string json = @"{
|
||||
""Name"": ""Name1"",
|
||||
""Name"": ""Name2""
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json, new JsonLoadSettings());
|
||||
string value = (string)o["Name"];
|
||||
|
||||
Assert.AreEqual("Name2", value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseMultipleProperties_IgnoreDuplicateSetting()
|
||||
{
|
||||
string json = @"{
|
||||
""Name"": ""Name1"",
|
||||
""Name"": ""Name2""
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json, new JsonLoadSettings
|
||||
{
|
||||
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Ignore
|
||||
});
|
||||
string value = (string)o["Name"];
|
||||
|
||||
Assert.AreEqual("Name1", value);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
|
||||
[Test]
|
||||
public void WriteObjectNullDBNullValue()
|
||||
|
||||
Reference in New Issue
Block a user