-Refactor ExceptionAssert

This commit is contained in:
James Newton-King
2014-09-12 21:33:53 +12:00
parent 4b9ce67ab7
commit dfb2ac17a5
43 changed files with 979 additions and 1482 deletions
@@ -105,9 +105,7 @@ namespace Newtonsoft.Json.Tests.Serialization
circularList.Add(new CircularList { null });
circularList.Add(new CircularList { new CircularList { circularList } });
ExceptionAssert.Throws<JsonSerializationException>(
"Self referencing loop detected with type '" + classRef + "'. Path '[2][0]'.",
() => { JsonConvert.SerializeObject(circularList, Formatting.Indented); });
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.SerializeObject(circularList, Formatting.Indented); }, "Self referencing loop detected with type '" + classRef + "'. Path '[2][0]'.");
}
[Test]
@@ -240,13 +238,11 @@ namespace Newtonsoft.Json.Tests.Serialization
]
}";
ExceptionAssert.Throws<JsonSerializationException>(
@"Cannot preserve reference to array or readonly list, or list created from a non-default constructor: System.String[][]. Path '$values', line 3, position 15.",
() =>
{
JsonConvert.DeserializeObject<string[][]>(json,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All });
});
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<string[][]>(json,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All });
}, @"Cannot preserve reference to array or readonly list, or list created from a non-default constructor: System.String[][]. Path '$values', line 3, position 15.");
}
public class CircularDictionary : Dictionary<string, CircularDictionary>
@@ -262,9 +258,7 @@ namespace Newtonsoft.Json.Tests.Serialization
circularDictionary.Add("other", new CircularDictionary { { "blah", null } });
circularDictionary.Add("self", circularDictionary);
ExceptionAssert.Throws<JsonSerializationException>(
@"Self referencing loop detected with type '" + classRef + "'. Path ''.",
() => { JsonConvert.SerializeObject(circularDictionary, Formatting.Indented); });
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.SerializeObject(circularDictionary, Formatting.Indented); }, @"Self referencing loop detected with type '" + classRef + "'. Path ''.");
}
[Test]
@@ -290,17 +284,15 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = @"{
""$id"":";
ExceptionAssert.Throws<JsonSerializationException>(
@"Unexpected end when deserializing object. Path '$id', line 2, position 9.",
() =>
{
JsonConvert.DeserializeObject<string[][]>(json,
new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.All,
MetadataPropertyHandling = MetadataPropertyHandling.Default
});
});
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<string[][]>(json,
new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.All,
MetadataPropertyHandling = MetadataPropertyHandling.Default
});
}, @"Unexpected end when deserializing object. Path '$id', line 2, position 9.");
}
public class CircularReferenceClassConverter : JsonConverter
@@ -1065,12 +1057,10 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}";
ExceptionAssert.Throws<JsonSerializationException>(
"Error reading object reference '1'. Path 'Data.Prop2.MyProperty', line 9, position 20.",
() => JsonConvert.DeserializeObject<PropertyItemIsReferenceObject>(json, new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Default
}));
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<PropertyItemIsReferenceObject>(json, new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Default
}), "Error reading object reference '1'. Path 'Data.Prop2.MyProperty', line 9, position 20.");
}
}