-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
@@ -400,19 +400,18 @@ namespace Newtonsoft.Json.Tests
[Test]
public void ThrowExceptionWhenNoValidationEventHandler()
{
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 exceeds maximum value of 5. Line 1, position 2.",
() =>
{
string schemaJson = @"{
ExceptionAssert.Throws<JsonSchemaException>(() =>
{
string schemaJson = @"{
""type"":""integer"",
""maximum"":5
}";
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("10")));
reader.Schema = JsonSchema.Parse(schemaJson);
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("10")));
reader.Schema = JsonSchema.Parse(schemaJson);
Assert.IsTrue(reader.Read());
});
Assert.IsTrue(reader.Read());
}, "Integer 10 exceeds maximum value of 5. Line 1, position 2.");
}
[Test]
@@ -1621,18 +1620,17 @@ namespace Newtonsoft.Json.Tests
[Test]
public void ReadAsInt32Failure()
{
ExceptionAssert.Throws<JsonSchemaException>("Integer 5 exceeds maximum value of 2. Line 1, position 1.",
() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
s.Maximum = 2;
ExceptionAssert.Throws<JsonSchemaException>(() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
s.Maximum = 2;
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
{
Schema = s
};
reader.ReadAsInt32();
});
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
{
Schema = s
};
reader.ReadAsInt32();
}, "Integer 5 exceeds maximum value of 2. Line 1, position 1.");
}
[Test]
@@ -1652,18 +1650,17 @@ namespace Newtonsoft.Json.Tests
[Test]
public void ReadAsDecimalFailure()
{
ExceptionAssert.Throws<JsonSchemaException>("Float 5.5 is not evenly divisible by 1. Line 1, position 3.",
() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
s.DivisibleBy = 1;
ExceptionAssert.Throws<JsonSchemaException>(() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
s.DivisibleBy = 1;
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
{
Schema = s
};
reader.ReadAsDecimal();
});
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
{
Schema = s
};
reader.ReadAsDecimal();
}, "Float 5.5 is not evenly divisible by 1. Line 1, position 3.");
}
[Test]