public void AddRequiredWithThreeValuesWhenAllPropertiesExist() { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.AddProperty("a", new JsonSchema()); jsonSchema.AddProperty("b", new JsonSchema()); jsonSchema.AddProperty("c", new JsonSchema()); jsonSchema.AddRequired("a", "b", "c"); Assert.Equal(new List<string>() { "a", "b", "c" }, jsonSchema.Required); }
public void AddRequiredWithThreeValuesWhenAllPropertiesExist() { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.AddProperty("a", new JsonSchema()); jsonSchema.AddProperty("b", new JsonSchema()); jsonSchema.AddProperty("c", new JsonSchema()); jsonSchema.AddRequired("a", "b", "c"); Assert.Equal(new List <string>() { "a", "b", "c" }, jsonSchema.Required); }
public void AddRequiredWithTwoValuesWhenSecondPropertyDoesntExist() { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.AddProperty("a", new JsonSchema()); Assert.Throws <ArgumentException>(() => { jsonSchema.AddRequired("a", "b"); }); }
public void AddPropertyOverwriteWithSamePropertyNameButDifferentCasing() { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.AddProperty("Type", new JsonSchema().AddProperty("foo1", new JsonSchema())); jsonSchema.AddProperty("Name", new JsonSchema().AddProperty("foo2", new JsonSchema())); jsonSchema.AddPropertyWithOverwrite("type", new JsonSchema().AddProperty("bar", new JsonSchema()), true); jsonSchema.AddPropertyWithOverwrite("name", new JsonSchema().AddProperty("baz", new JsonSchema()), true); Assert.True(jsonSchema.Properties.Count == 2); Assert.Equal(new List <string>() { "type", "name" }, jsonSchema.Properties.Keys); }
public void WriteDefinitionWithRequiredPropertyAndDescription() { StringWriter stringWriter = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(stringWriter); writer.QuoteChar = '\''; const string definitionName = "mockDefinition"; JsonSchema definition = new JsonSchema(); definition.AddProperty("mockPropertyName", new JsonSchema(), true); definition.Description = "MockDescription"; ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition); Assert.Equal("'mockDefinition':{'properties':{'mockPropertyName':{'oneOf':[{},{'$ref':'https://schema.management.azure.com/schemas/common/definitions.json#/definitions/expression'}]}},'required':['mockPropertyName'],'description':'MockDescription'}", stringWriter.ToString()); }
public void AddPropertyWithWhitespacePropertyName() { JsonSchema jsonSchema = new JsonSchema(); Assert.Throws <ArgumentException>(() => { jsonSchema.AddProperty(" ", null); }); }
public void AddRequiredWithTwoValuesWhenSecondPropertyDoesntExist() { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.AddProperty("a", new JsonSchema()); Assert.Throws<ArgumentException>(() => { jsonSchema.AddRequired("a", "b"); }); }
public void AddPropertyWithWhitespacePropertyName() { JsonSchema jsonSchema = new JsonSchema(); Assert.Throws<ArgumentException>(() => { jsonSchema.AddProperty(" ", null); }); }
public void WriteDefinitionWithRequiredPropertyAndDescription() { StringWriter stringWriter = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(stringWriter); writer.QuoteChar = '\''; const string definitionName = "mockDefinition"; JsonSchema definition = new JsonSchema(); definition.AddProperty("mockPropertyName", new JsonSchema(), true); definition.Description = "MockDescription"; ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition); Assert.Equal("'mockDefinition':{'properties':{'mockPropertyName':{'oneOf':[{},{'$ref':'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression'}]}},'required':['mockPropertyName'],'description':'MockDescription'}", stringWriter.ToString()); }