-Fixed unit test failing because of timezones
-Added IsValid overload that returns a list of error messages
This commit is contained in:
@@ -39,8 +39,8 @@ namespace Newtonsoft.Json.Tests
|
|||||||
|
|
||||||
public class PerformanceTests : TestFixtureBase
|
public class PerformanceTests : TestFixtureBase
|
||||||
{
|
{
|
||||||
//private const int Iterations = 100;
|
private const int Iterations = 100;
|
||||||
private const int Iterations = 5000;
|
//private const int Iterations = 5000;
|
||||||
|
|
||||||
#region Data
|
#region Data
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,15 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
JToken stringToken = JToken.FromObject("pie");
|
JToken stringToken = JToken.FromObject("pie");
|
||||||
JToken integerToken = JToken.FromObject(1);
|
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));
|
||||||
|
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]
|
[Test]
|
||||||
|
|||||||
@@ -856,6 +856,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public void ByteArrays()
|
public void ByteArrays()
|
||||||
{
|
{
|
||||||
Car testerObject = new Car();
|
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};
|
byte[] data = new byte[] {75, 65, 82, 73, 82, 65};
|
||||||
testerObject.Objects = new object[] { data, "prueba" };
|
testerObject.Objects = new object[] { data, "prueba" };
|
||||||
|
|
||||||
@@ -869,7 +870,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Assert.AreEqual(output, @"{
|
Assert.AreEqual(output, @"{
|
||||||
""$type"": """ + carClassRef + @""",
|
""$type"": """ + carClassRef + @""",
|
||||||
""Year"": ""\/Date(-62135596800000+1300)\/"",
|
""Year"": ""\/Date(970707661000)\/"",
|
||||||
""Objects"": {
|
""Objects"": {
|
||||||
""$type"": ""System.Object[], mscorlib"",
|
""$type"": ""System.Object[], mscorlib"",
|
||||||
""$values"": [
|
""$values"": [
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ namespace Newtonsoft.Json.Schema
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Validates the specified <see cref="JToken"/>.
|
/// Validates the specified <see cref="JToken"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user