public void HeterogeneousEnumValidation(string desc, string data, bool expected) { // heterogeneous enum validation Console.Error.WriteLine(desc); string schemaData = "{ 'enum':[ 6, 'foo', [ ], true, { 'foo':12 } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ValidationOfEMailAddresses(string desc, string data, bool expected) { // validation of e-mail addresses Console.Error.WriteLine(desc); string schemaData = "{ 'format':'email' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertiesWithBooleanSchema(string desc, string data, bool expected) { // properties with boolean schema Console.Error.WriteLine(desc); string schemaData = "{ 'properties':{ 'bar':false, 'foo':true } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void OneOfComplexTypes(string desc, string data, bool expected) { // oneOf complex types Console.Error.WriteLine(desc); string schemaData = "{ 'oneOf':[ { 'properties':{ 'bar':{ 'type':'integer' } }, 'required':[ 'bar' ] }, { 'properties':{ 'foo':{ 'type':'string' } }, 'required':[ 'foo' ] } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void OneOfTest(string desc, string data, bool expected) { // oneOf Console.Error.WriteLine(desc); string schemaData = "{ 'oneOf':[ { 'type':'integer' }, { 'minimum':2 } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ValidationOfJSONPointersJSONStringRepresentation(string desc, string data, bool expected) { // validation of JSON-pointers (JSON String Representation) Console.Error.WriteLine(desc); string schemaData = "{ 'format':'json-pointer' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void MinimumValidation(string desc, string data, bool expected) { // minimum validation Console.Error.WriteLine(desc); string schemaData = "{ 'minimum':1.1 }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void NonASCIIPatternWithAdditionalProperties(string desc, string data, bool expected) { // non-ASCII pattern with additionalProperties Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':false, 'patternProperties':{ '^á':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void EmptyArrayOfDependencies(string desc, string data, bool expected) { // empty array of dependencies Console.Error.WriteLine(desc); string schemaData = "{ 'dependencies':{ 'foo':[ ] } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesShouldNotLookInApplicators(string desc, string data, bool expected) { // additionalProperties should not look in applicators Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' }, 'allOf':[ { 'properties':{ 'foo':{ } } } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesBeingFalseDoesNotAllowOtherProperties(string desc, string data, bool expected) { // additionalProperties being false does not allow other properties Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':false, 'patternProperties':{ '^v':{ } }, 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesAreAllowedByDefault(string desc, string data, bool expected) { // additionalProperties are allowed by default Console.Error.WriteLine(desc); string schemaData = "{ 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesCanExistByItself(string desc, string data, bool expected) { // additionalProperties can exist by itself Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesAllowsASchemaWhichShouldValidate(string desc, string data, bool expected) { // additionalProperties allows a schema which should validate Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' }, 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertyNamesValidation(string desc, string data, bool expected) { // propertyNames validation Console.Error.WriteLine(desc); string schemaData = "{ 'propertyNames':{ 'maxLength':3 } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ContainsKeywordValidation(string desc, string data, bool expected) { // contains keyword validation Console.Error.WriteLine(desc); string schemaData = "{ 'contains':{ 'minimum':5 } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void UniqueItemsWithAnArrayOfItemsAndAdditionalItemsFalse(string desc, string data, bool expected) { // uniqueItems with an array of items and additionalItems=false Console.Error.WriteLine(desc); string schemaData = "{ 'additionalItems':false, 'items':[ { 'type':'boolean' }, { 'type':'boolean' } ], 'uniqueItems':true }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void MultipleDependenciesSubschema(string desc, string data, bool expected) { // multiple dependencies subschema Console.Error.WriteLine(desc); string schemaData = "{ 'dependencies':{ 'bar':{ 'properties':{ 'bar':{ 'type':'integer' }, 'foo':{ 'type':'integer' } } } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void InvalidDefinition(string desc, string data, bool expected) { // invalid definition Console.Error.WriteLine(desc); string schemaData = "{ '$ref':'http://json-schema.org/draft-04/schema#' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void DependenciesWithEscapedCharacters(string desc, string data, bool expected) { // dependencies with escaped characters Console.Error.WriteLine(desc); string schemaData = @"{ ""dependencies"":{ ""foo\tbar"":{ ""minProperties"":4 }, ""foo\nbar"":[ ""foo\rbar"" ], ""foo\""bar"":[ ""foo'bar"" ], ""foo'bar"":{ ""required"":[ ""foo\""bar"" ] } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void OneOfWithBooleanSchemasAllFalse(string desc, string data, bool expected) { // oneOf with boolean schemas, all false Console.Error.WriteLine(desc); string schemaData = "{ 'oneOf':[ false, false, false ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void DependenciesTest(string desc, string data, bool expected) { // dependencies Console.Error.WriteLine(desc); string schemaData = "{ 'dependencies':{ 'bar':[ 'foo' ] } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void OneOfWithRequired(string desc, string data, bool expected) { // oneOf with required Console.Error.WriteLine(desc); string schemaData = "{ 'oneOf':[ { 'required':[ 'foo', 'bar' ] }, { 'required':[ 'foo', 'baz' ] } ], 'type':'object' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ConstWith1DoesNotMatchTrue(string desc, string data, bool expected) { // const with 1 does not match true Console.Error.WriteLine(desc); string schemaData = "{ 'const':1 }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void OneOfWithBaseSchema(string desc, string data, bool expected) { // oneOf with base schema Console.Error.WriteLine(desc); string schemaData = "{ 'oneOf':[ { 'minLength':2 }, { 'maxLength':4 } ], 'type':'string' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ConstWithObject(string desc, string data, bool expected) { // const with object Console.Error.WriteLine(desc); string schemaData = "{ 'const':{ 'baz':'bax', 'foo':'bar' } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertiesPatternPropertiesAdditionalPropertiesInteraction(string desc, string data, bool expected) { // properties, patternProperties, additionalProperties interaction Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'integer' }, 'patternProperties':{ 'f.o':{ 'minItems':2 } }, 'properties':{ 'bar':{ 'type':'array' }, 'foo':{ 'maxItems':3, 'type':'array' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void BooleanSchemaTrue(string desc, string data, bool expected) { // boolean schema 'true' Console.Error.WriteLine(desc); string schemaData = "true"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertiesWithEscapedCharacters(string desc, string data, bool expected) { // properties with escaped characters Console.Error.WriteLine(desc); string schemaData = @"{ 'properties':{ 'foo\tbar':{ 'type':'number' }, 'foo\nbar':{ 'type':'number' }, 'foo\fbar':{ 'type':'number' }, 'foo\rbar':{ 'type':'number' }, 'foo\'bar':{ 'type':'number' }, 'foo\\bar':{ 'type':'number' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void SimpleEnumValidation(string desc, string data, bool expected) { // simple enum validation Console.Error.WriteLine(desc); string schemaData = "{ 'enum':[ 1, 2, 3 ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }