-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
|
||||
{
|
||||
//private const int Iterations = 100;
|
||||
private const int Iterations = 5000;
|
||||
private const int Iterations = 100;
|
||||
//private const int Iterations = 5000;
|
||||
|
||||
#region Data
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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"": [
|
||||
|
||||
@@ -52,6 +52,25 @@ namespace Newtonsoft.Json.Schema
|
||||
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>
|
||||
/// Validates the specified <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user