-Changed StringEnumConverter.AllowIntegerValues to also reject writing enum values with no name

This commit is contained in:
James Newton-King
2017-03-19 16:46:33 +13:00
parent 937b25be20
commit 7673a18e55
16 changed files with 103 additions and 861 deletions
@@ -612,12 +612,21 @@ namespace Newtonsoft.Json.Tests.Converters
{
JsonSerializationException ex = ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<StoreColor>("\"1\"", new StringEnumConverter {AllowIntegerValues = false});
JsonConvert.DeserializeObject<StoreColor>("\"1\"", new StringEnumConverter { AllowIntegerValues = false });
});
Assert.AreEqual("Integer string '1' is not allowed.", ex.InnerException.Message);
}
[Test]
public void AllowIntegerValueAndNonNamedValue()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.SerializeObject((StoreColor)999, new StringEnumConverter { AllowIntegerValues = false });
}, "Integer value 999 is not allowed. Path ''.");
}
public enum EnumWithDifferentCases
{
M,
@@ -1052,7 +1052,7 @@ namespace Newtonsoft.Json.Tests.Converters
[Test]
public void NoRootObject()
{
ExceptionAssert.Throws<JsonSerializationException>(() => { XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"[1]"); }, "XmlNodeConverter can only convert JSON that begins with an object.");
ExceptionAssert.Throws<JsonSerializationException>(() => { XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"[1]"); }, "XmlNodeConverter can only convert JSON that begins with an object. Path '', line 1, position 1.");
}
[Test]