-Refactor ExceptionAssert
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user