-Change BSON writer to write new binary subtype

-Fix BSON reader to read the old binary subtype correctly
-Added JsonNet35BinaryCompadibility to BSON reader for incorrectly written BSON binary values
-Changed JSON schema to use required flags instead of optional as defined in JSON schema spec 3.0
-Changed JSON schema to use divisibleBy instead of maxDecimals as defined in JSON schema spec 3.0
-Fixed detection of serialization specified flag properties
-Updated to latest version of NuGet
This commit is contained in:
JamesNK
2010-12-19 00:29:41 +00:00
parent 2e7b8e5279
commit 5ccd826951
20 changed files with 194 additions and 80 deletions
@@ -89,13 +89,13 @@ namespace Newtonsoft.Json.Tests.Schema
[Test]
public void ValidateFailureWithOutLineInfoBecauseOfEndToken()
{
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{}}}");
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'required':true}}}");
JObject o = JObject.Parse("{}");
List<string> errors = new List<string>();
o.Validate(schema, (sender, args) => errors.Add(args.Message));
Assert.AreEqual("Non-optional properties are missing from object: lol.", errors[0]);
Assert.AreEqual("Required properties are missing from object: lol.", errors[0]);
Assert.AreEqual(1, errors.Count);
}
@@ -116,18 +116,18 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
public void Optional()
public void Required()
{
string json = @"{
""description"":""Optional"",
""optional"":true
""description"":""Required"",
""required"":true
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Optional", schema.Description);
Assert.AreEqual(true, schema.Optional);
Assert.AreEqual("Required", schema.Description);
Assert.AreEqual(true, schema.Required);
}
[Test]
@@ -279,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Schema
""maxItems"":2,
""minLength"":5,
""maxLength"":50,
""maxDecimal"":3,
""divisibleBy"":3,
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
@@ -292,7 +292,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(2, schema.MaximumItems);
Assert.AreEqual(5, schema.MinimumLength);
Assert.AreEqual(50, schema.MaximumLength);
Assert.AreEqual(3, schema.MaximumDecimals);
Assert.AreEqual(3, schema.DivisibleBy);
}
[Test]
@@ -94,10 +94,12 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false,
""properties"": {
""TestField1"": {
""required"": true,
""type"": ""integer"",
""default"": 21
},
""TestProperty1"": {
""required"": true,
""type"": [
""string"",
""null""
@@ -124,15 +126,18 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"",
""properties"": {
""Name"": {
""required"": true,
""type"": [
""string"",
""null""
]
},
""BirthDate"": {
""required"": true,
""type"": ""string""
},
""LastModified"": {
""required"": true,
""type"": ""string""
}
}
@@ -151,36 +156,43 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"",
""properties"": {
""Id"": {
""required"": true,
""type"": ""string""
},
""FName"": {
""required"": true,
""type"": [
""string"",
""null""
]
},
""LName"": {
""required"": true,
""type"": [
""string"",
""null""
]
},
""RoleId"": {
""required"": true,
""type"": ""integer""
},
""NullableRoleId"": {
""required"": true,
""type"": [
""integer"",
""null""
]
},
""NullRoleId"": {
""required"": true,
""type"": [
""integer"",
""null""
]
},
""Active"": {
""required"": true,
""type"": [
""boolean"",
""null""
@@ -370,6 +382,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{
""id"": ""System.IO.DirectoryInfo"",
""required"": true,
""type"": [
""object"",
""null""
@@ -377,6 +390,7 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false,
""properties"": {
""Name"": {
""required"": true,
""type"": [
""string"",
""null""
@@ -386,39 +400,49 @@ namespace Newtonsoft.Json.Tests.Schema
""$ref"": ""System.IO.DirectoryInfo""
},
""Exists"": {
""required"": true,
""type"": ""boolean""
},
""FullName"": {
""required"": true,
""type"": [
""string"",
""null""
]
},
""Extension"": {
""required"": true,
""type"": [
""string"",
""null""
]
},
""CreationTime"": {
""required"": true,
""type"": ""string""
},
""CreationTimeUtc"": {
""required"": true,
""type"": ""string""
},
""LastAccessTime"": {
""required"": true,
""type"": ""string""
},
""LastAccessTimeUtc"": {
""required"": true,
""type"": ""string""
},
""LastWriteTime"": {
""required"": true,
""type"": ""string""
},
""LastWriteTimeUtc"": {
""required"": true,
""type"": ""string""
},
""Attributes"": {
""required"": true,
""type"": ""integer""
}
}
@@ -458,21 +482,27 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false,
""properties"": {
""major"": {
""required"": true,
""type"": ""integer""
},
""minor"": {
""required"": true,
""type"": ""integer""
},
""build"": {
""required"": true,
""type"": ""integer""
},
""revision"": {
""required"": true,
""type"": ""integer""
},
""majorRevision"": {
""required"": true,
""type"": ""integer""
},
""minorRevision"": {
""required"": true,
""type"": ""integer""
}
}
@@ -503,6 +533,7 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"",
""properties"": {
""x"": {
""required"": true,
""type"": ""integer"",
""enum"": [
0,
@@ -552,13 +583,13 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{
""id"": ""Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass"",
""optional"": true,
""type"": [
""object"",
""null""
],
""properties"": {
""Name"": {
""required"": true,
""type"": ""string""
},
""Child"": {
@@ -579,13 +610,13 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{
""id"": ""Newtonsoft.Json.Tests.TestObjects.JsonPropertyWithHandlingValues"",
""required"": true,
""type"": [
""object"",
""null""
],
""properties"": {
""DefaultValueHandlingIgnoreProperty"": {
""optional"": true,
""type"": [
""string"",
""null""
@@ -593,6 +624,7 @@ namespace Newtonsoft.Json.Tests.Schema
""default"": ""Default!""
},
""DefaultValueHandlingIncludeProperty"": {
""required"": true,
""type"": [
""string"",
""null""
@@ -600,13 +632,13 @@ namespace Newtonsoft.Json.Tests.Schema
""default"": ""Default!""
},
""NullValueHandlingIgnoreProperty"": {
""optional"": true,
""type"": [
""string"",
""null""
]
},
""NullValueHandlingIncludeProperty"": {
""required"": true,
""type"": [
""string"",
""null""
@@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
public void Optional()
public void Required()
{
string schemaJson = @"{
""description"":""A person"",
@@ -147,8 +147,8 @@ namespace Newtonsoft.Json.Tests.Schema
""properties"":
{
""name"":{""type"":""string""},
""hobbies"":{""type"":""string"",optional:true},
""age"":{""type"":""integer"",optional:true}
""hobbies"":{""type"":""string"",required:true},
""age"":{""type"":""integer"",required:true}
}
}";
@@ -158,9 +158,9 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(JsonSchemaType.Object, model.Type);
Assert.AreEqual(3, model.Properties.Count);
Assert.AreEqual(false, model.Properties["name"].Optional);
Assert.AreEqual(true, model.Properties["hobbies"].Optional);
Assert.AreEqual(true, model.Properties["age"].Optional);
Assert.AreEqual(false, model.Properties["name"].Required);
Assert.AreEqual(true, model.Properties["hobbies"].Required);
Assert.AreEqual(true, model.Properties["age"].Required);
}
}
}