Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void AddRequiredWithTwoValuesWhenSecondPropertyDoesntExist()
        {
            JsonSchema jsonSchema = new JsonSchema();

            jsonSchema.AddProperty("a", new JsonSchema());
            Assert.Throws <ArgumentException>(() => { jsonSchema.AddRequired("a", "b"); });
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        public void AddPropertyWithWhitespacePropertyName()
        {
            JsonSchema jsonSchema = new JsonSchema();

            Assert.Throws <ArgumentException>(() => { jsonSchema.AddProperty("     ", null); });
        }
Beispiel #7
0
 public void AddRequiredWithTwoValuesWhenSecondPropertyDoesntExist()
 {
     JsonSchema jsonSchema = new JsonSchema();
     jsonSchema.AddProperty("a", new JsonSchema());
     Assert.Throws<ArgumentException>(() => { jsonSchema.AddRequired("a", "b"); });
 }
Beispiel #8
0
 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());
        }