-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
@@ -161,12 +161,10 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(contract.DefaultCreator);
Assert.IsNull(contract.OverrideCreator);
ExceptionAssert.Throws<JsonSerializationException>(
"Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractTestClass. Type is an interface or abstract class and cannot be instantiated. Path 'Value', line 1, position 7.",
() => JsonConvert.DeserializeObject<AbstractTestClass>(@"{Value:'Value!'}", new JsonSerializerSettings
{
ContractResolver = resolver
}));
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<AbstractTestClass>(@"{Value:'Value!'}", new JsonSerializerSettings
{
ContractResolver = resolver
}), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractTestClass. Type is an interface or abstract class and cannot be instantiated. Path 'Value', line 1, position 7.");
contract.DefaultCreator = () => new AbstractImplementationTestClass();
@@ -188,12 +186,10 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(contract.DefaultCreator);
Assert.IsFalse(contract.HasParametrizedCreator);
ExceptionAssert.Throws<JsonSerializationException>(
"Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractListTestClass`1[System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path '', line 1, position 1.",
() => JsonConvert.DeserializeObject<AbstractListTestClass<int>>(@"[1,2]", new JsonSerializerSettings
{
ContractResolver = resolver
}));
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<AbstractListTestClass<int>>(@"[1,2]", new JsonSerializerSettings
{
ContractResolver = resolver
}), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractListTestClass`1[System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path '', line 1, position 1.");
contract.DefaultCreator = () => new AbstractImplementationListTestClass<int>();
@@ -270,12 +266,10 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(contract.DefaultCreator);
Assert.IsFalse(contract.HasParametrizedCreator);
ExceptionAssert.Throws<JsonSerializationException>(
"Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractDictionaryTestClass`2[System.String,System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path 'key1', line 1, position 6.",
() => JsonConvert.DeserializeObject<AbstractDictionaryTestClass<string, int>>(@"{key1:1,key2:2}", new JsonSerializerSettings
{
ContractResolver = resolver
}));
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<AbstractDictionaryTestClass<string, int>>(@"{key1:1,key2:2}", new JsonSerializerSettings
{
ContractResolver = resolver
}), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractDictionaryTestClass`2[System.String,System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path 'key1', line 1, position 6.");
contract.DefaultCreator = () => new AbstractImplementationDictionaryTestClass<string, int>();