-Refactor ExceptionAssert
This commit is contained in:
@@ -85,13 +85,12 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
[Test]
|
||||
public void ValidateWithOutEventHandlerFailure()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>(@"String 'pie' does not match regex pattern 'lol'.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
|
||||
JToken stringToken = JToken.FromObject("pie");
|
||||
stringToken.Validate(schema);
|
||||
});
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
|
||||
JToken stringToken = JToken.FromObject("pie");
|
||||
stringToken.Validate(schema);
|
||||
}, @"String 'pie' does not match regex pattern 'lol'.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -237,75 +236,70 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
[Test]
|
||||
public void ExclusiveMaximum_Int()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 equals maximum value of 10 and exclusive maximum is true.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Maximum = 10;
|
||||
schema.ExclusiveMaximum = true;
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Maximum = 10;
|
||||
schema.ExclusiveMaximum = true;
|
||||
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
});
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
}, "Integer 10 equals maximum value of 10 and exclusive maximum is true.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExclusiveMaximum_Float()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>("Float 10.1 equals maximum value of 10.1 and exclusive maximum is true.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Maximum = 10.1;
|
||||
schema.ExclusiveMaximum = true;
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Maximum = 10.1;
|
||||
schema.ExclusiveMaximum = true;
|
||||
|
||||
JValue v = new JValue(10.1);
|
||||
v.Validate(schema);
|
||||
});
|
||||
JValue v = new JValue(10.1);
|
||||
v.Validate(schema);
|
||||
}, "Float 10.1 equals maximum value of 10.1 and exclusive maximum is true.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExclusiveMinimum_Int()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 equals minimum value of 10 and exclusive minimum is true.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Minimum = 10;
|
||||
schema.ExclusiveMinimum = true;
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Minimum = 10;
|
||||
schema.ExclusiveMinimum = true;
|
||||
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
});
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
}, "Integer 10 equals minimum value of 10 and exclusive minimum is true.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExclusiveMinimum_Float()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>("Float 10.1 equals minimum value of 10.1 and exclusive minimum is true.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Minimum = 10.1;
|
||||
schema.ExclusiveMinimum = true;
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.Minimum = 10.1;
|
||||
schema.ExclusiveMinimum = true;
|
||||
|
||||
JValue v = new JValue(10.1);
|
||||
v.Validate(schema);
|
||||
});
|
||||
JValue v = new JValue(10.1);
|
||||
v.Validate(schema);
|
||||
}, "Float 10.1 equals minimum value of 10.1 and exclusive minimum is true.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DivisibleBy_Int()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 is not evenly divisible by 3.",
|
||||
() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.DivisibleBy = 3;
|
||||
ExceptionAssert.Throws<JsonSchemaException>(() =>
|
||||
{
|
||||
JsonSchema schema = new JsonSchema();
|
||||
schema.DivisibleBy = 3;
|
||||
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
});
|
||||
JValue v = new JValue(10);
|
||||
v.Validate(schema);
|
||||
}, "Integer 10 is not evenly divisible by 3.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -384,19 +384,18 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
[Test]
|
||||
public void UnresolvedReference()
|
||||
{
|
||||
ExceptionAssert.Throws<Exception>(@"Could not resolve schema reference 'MyUnresolvedReference'.",
|
||||
() =>
|
||||
{
|
||||
string json = @"{
|
||||
ExceptionAssert.Throws<Exception>(() =>
|
||||
{
|
||||
string json = @"{
|
||||
""id"":""CircularReferenceArray"",
|
||||
""description"":""CircularReference"",
|
||||
""type"":[""array""],
|
||||
""items"":{""$ref"":""MyUnresolvedReference""}
|
||||
}";
|
||||
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
});
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
}, @"Could not resolve schema reference 'MyUnresolvedReference'.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -597,13 +596,11 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
}
|
||||
}";
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Could not resolve schema reference '#/array/10'.",
|
||||
() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
});
|
||||
ExceptionAssert.Throws<JsonException>(() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
}, "Could not resolve schema reference '#/array/10'.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -617,13 +614,11 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
}
|
||||
}";
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Could not resolve schema reference '#/array/-1'.",
|
||||
() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
});
|
||||
ExceptionAssert.Throws<JsonException>(() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
}, "Could not resolve schema reference '#/array/-1'.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -637,13 +632,11 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
}
|
||||
}";
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Could not resolve schema reference '#/array/one'.",
|
||||
() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
});
|
||||
ExceptionAssert.Throws<JsonException>(() =>
|
||||
{
|
||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||
builder.Read(new JsonTextReader(new StringReader(json)));
|
||||
}, "Could not resolve schema reference '#/array/one'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,12 +260,11 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
[Test]
|
||||
public void CircularReferenceError()
|
||||
{
|
||||
ExceptionAssert.Throws<Exception>(@"Unresolved circular reference for type 'Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.",
|
||||
() =>
|
||||
{
|
||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||
generator.Generate(typeof(CircularReferenceClass));
|
||||
});
|
||||
ExceptionAssert.Throws<Exception>(() =>
|
||||
{
|
||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||
generator.Generate(typeof(CircularReferenceClass));
|
||||
}, @"Unresolved circular reference for type 'Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user