Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs')
-rw-r--r--Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs107
1 files changed, 67 insertions, 40 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
index 36e042a..586f793 100644
--- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
@@ -27,17 +27,24 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+#if !NETFX_CORE
using NUnit.Framework;
+#else
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
+using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+#endif
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;
using System.IO;
using Newtonsoft.Json.Tests.TestObjects;
-#if !SILVERLIGHT
+#if !(SILVERLIGHT || NETFX_CORE)
using System.Data;
#endif
namespace Newtonsoft.Json.Tests.Schema
{
+ [TestFixture]
public class ExtensionsTests : TestFixtureBase
{
[Test]
@@ -77,12 +84,15 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = @"String 'pie' does not match regex pattern 'lol'.")]
public void ValidateWithOutEventHandlerFailure()
{
- JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
- JToken stringToken = JToken.FromObject("pie");
- stringToken.Validate(schema);
+ 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);
+ });
}
[Test]
@@ -194,7 +204,7 @@ namespace Newtonsoft.Json.Tests.Schema
#if !NET20 && !PocketPC
GenerateSchemaAndSerializeFromType(new NullableDateTimeTestClass());
#endif
-#if !SILVERLIGHT
+#if !(SILVERLIGHT || NETFX_CORE)
GenerateSchemaAndSerializeFromType(new DataSet());
#endif
GenerateSchemaAndSerializeFromType(new object());
@@ -202,7 +212,9 @@ namespace Newtonsoft.Json.Tests.Schema
GenerateSchemaAndSerializeFromType("Hi");
GenerateSchemaAndSerializeFromType(new DateTime(2000, 12, 29, 23, 59, 0, DateTimeKind.Utc));
GenerateSchemaAndSerializeFromType(TimeSpan.FromTicks(1000000));
+#if !NETFX_CORE
GenerateSchemaAndSerializeFromType(DBNull.Value);
+#endif
GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues());
}
@@ -227,62 +239,77 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 equals maximum value of 10 and exclusive maximum is true.")]
public void ExclusiveMaximum_Int()
{
- JsonSchema schema = new JsonSchema();
- schema.Maximum = 10;
- schema.ExclusiveMaximum = true;
-
- JValue v = new JValue(10);
- v.Validate(schema);
+ 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;
+
+ JValue v = new JValue(10);
+ v.Validate(schema);
+ });
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 10.1 equals maximum value of 10.1 and exclusive maximum is true.")]
public void ExclusiveMaximum_Float()
{
- JsonSchema schema = new JsonSchema();
- schema.Maximum = 10.1;
- schema.ExclusiveMaximum = true;
-
- JValue v = new JValue(10.1);
- v.Validate(schema);
+ 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;
+
+ JValue v = new JValue(10.1);
+ v.Validate(schema);
+ });
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 equals minimum value of 10 and exclusive minimum is true.")]
public void ExclusiveMinimum_Int()
{
- JsonSchema schema = new JsonSchema();
- schema.Minimum = 10;
- schema.ExclusiveMinimum = true;
-
- JValue v = new JValue(10);
- v.Validate(schema);
+ 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;
+
+ JValue v = new JValue(10);
+ v.Validate(schema);
+ });
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 10.1 equals minimum value of 10.1 and exclusive minimum is true.")]
public void ExclusiveMinimum_Float()
{
- JsonSchema schema = new JsonSchema();
- schema.Minimum = 10.1;
- schema.ExclusiveMinimum = true;
-
- JValue v = new JValue(10.1);
- v.Validate(schema);
+ 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;
+
+ JValue v = new JValue(10.1);
+ v.Validate(schema);
+ });
}
[Test]
- [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 is not evenly divisible by 3.")]
public void DivisibleBy_Int()
{
- JsonSchema schema = new JsonSchema();
- schema.DivisibleBy = 3;
-
- JValue v = new JValue(10);
- v.Validate(schema);
+ ExceptionAssert.Throws<JsonSchemaException>("Integer 10 is not evenly divisible by 3.",
+ () =>
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.DivisibleBy = 3;
+
+ JValue v = new JValue(10);
+ v.Validate(schema);
+ });
}
}
} \ No newline at end of file