diff options
author | JamesNK <james@newtonking.com> | 2012-02-11 03:49:46 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2012-02-11 03:49:46 +0400 |
commit | 2dd26baa770528f30331e0a07e7f639b3e78c1a8 (patch) | |
tree | 764762fd33ef63e2635fe4f9534f2b65abca5294 | |
parent | 68a200127af905242b9e74157d7d10e9469a2119 (diff) |
-Fixed unit test failing because of timezones
-Added IsValid overload that returns a list of error messages
4 files changed, 31 insertions, 4 deletions
diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index b8fa9f4..5b1d8ed 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -39,8 +39,8 @@ namespace Newtonsoft.Json.Tests public class PerformanceTests : TestFixtureBase
{
- //private const int Iterations = 100;
- private const int Iterations = 5000;
+ private const int Iterations = 100;
+ //private const int Iterations = 5000;
#region Data
diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index 1314733..99f3a5b 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -47,8 +47,15 @@ namespace Newtonsoft.Json.Tests.Schema JToken stringToken = JToken.FromObject("pie");
JToken integerToken = JToken.FromObject(1);
- Assert.AreEqual(false, stringToken.IsValid(schema));
+ IList<string> errorMessages;
Assert.AreEqual(true, integerToken.IsValid(schema));
+ Assert.AreEqual(true, integerToken.IsValid(schema, out errorMessages));
+ Assert.AreEqual(0, errorMessages.Count);
+
+ Assert.AreEqual(false, stringToken.IsValid(schema));
+ Assert.AreEqual(false, stringToken.IsValid(schema, out errorMessages));
+ Assert.AreEqual(1, errorMessages.Count);
+ Assert.AreEqual("Invalid type. Expected Integer but got String.", errorMessages[0]);
}
[Test]
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index e256e0d..9d52d82 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -856,6 +856,7 @@ namespace Newtonsoft.Json.Tests.Serialization public void ByteArrays()
{
Car testerObject = new Car();
+ testerObject.Year = new DateTime(2000, 10, 5, 1, 1, 1, DateTimeKind.Utc);
byte[] data = new byte[] {75, 65, 82, 73, 82, 65};
testerObject.Objects = new object[] { data, "prueba" };
@@ -869,7 +870,7 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(output, @"{
""$type"": """ + carClassRef + @""",
- ""Year"": ""\/Date(-62135596800000+1300)\/"",
+ ""Year"": ""\/Date(970707661000)\/"",
""Objects"": {
""$type"": ""System.Object[], mscorlib"",
""$values"": [
diff --git a/Src/Newtonsoft.Json/Schema/Extensions.cs b/Src/Newtonsoft.Json/Schema/Extensions.cs index 054d42d..a93e8f2 100644 --- a/Src/Newtonsoft.Json/Schema/Extensions.cs +++ b/Src/Newtonsoft.Json/Schema/Extensions.cs @@ -53,6 +53,25 @@ namespace Newtonsoft.Json.Schema }
/// <summary>
+ /// Determines whether the <see cref="JToken"/> is valid.
+ /// </summary>
+ /// <param name="source">The source <see cref="JToken"/> to test.</param>
+ /// <param name="schema">The schema to test with.</param>
+ /// <param name="errorMessages">When this method returns, contains any error messages generated while validating. </param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="JToken"/> is valid; otherwise, <c>false</c>.
+ /// </returns>
+ public static bool IsValid(this JToken source, JsonSchema schema, out IList<string> errorMessages)
+ {
+ IList<string> errors = new List<string>();
+
+ source.Validate(schema, (sender, args) => errors.Add(args.Message));
+
+ errorMessages = errors;
+ return (errorMessages.Count == 0);
+ }
+
+ /// <summary>
/// Validates the specified <see cref="JToken"/>.
/// </summary>
/// <param name="source">The source <see cref="JToken"/> to test.</param>
|