示例#1
0
        public void WriteWithNullJsonTextWriter()
        {
            JsonTextWriter writer         = null;
            ResourceSchema resourceSchema = new ResourceSchema();

            Assert.Throws <ArgumentNullException>(() => { ResourceSchemaWriter.Write(writer, resourceSchema); });
        }
示例#2
0
        public void WritePropertyWithNullWriter()
        {
            JsonTextWriter writer        = null;
            const string   propertyName  = "mockPropertyName";
            const string   propertyValue = "mockPropertyValue";

            Assert.Throws <ArgumentNullException>(() => { ResourceSchemaWriter.WriteProperty(writer, propertyName, propertyValue); });
        }
示例#3
0
        public void WriteWithJsonTextWriterAndNullResourceSchema()
        {
            StringWriter   stringWriter   = new StringWriter();
            JsonTextWriter writer         = new JsonTextWriter(stringWriter);
            ResourceSchema resourceSchema = null;

            Assert.Throws <ArgumentNullException>(() => { ResourceSchemaWriter.Write(writer, resourceSchema); });
        }
示例#4
0
        public void WriteWithEmptyResourceSchema()
        {
            StringWriter   stringWriter   = new StringWriter();
            JsonTextWriter writer         = new JsonTextWriter(stringWriter);
            ResourceSchema resourceSchema = new ResourceSchema();

            ResourceSchemaWriter.Write(writer, resourceSchema);
            Assert.Equal("{}", stringWriter.ToString());
        }
示例#5
0
        public void WritePropertyWithNullPropertyName()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string propertyName  = null;
            const string propertyValue = "mockPropertyValue";

            Assert.Throws <ArgumentException>(() => { ResourceSchemaWriter.WriteProperty(writer, propertyName, propertyValue); });
        }
示例#6
0
        public void WriteDefinitionWithTypeAndEnum()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string definitionName = "mockDefinition";
            JsonSchema   definition     = JsonSchema.CreateSingleValuedEnum("MockEnum1");

            ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
            Assert.Equal("'mockDefinition':{'type':'string','enum':['MockEnum1']}", stringWriter.ToString());
        }
示例#7
0
        public void WriteDefinitionWithEmptyDefinition()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string definitionName = "mockDefinition";
            JsonSchema   definition     = new JsonSchema();

            ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
            Assert.Equal("'mockDefinition':{}", stringWriter.ToString());
        }
示例#8
0
        public void WriteWithId()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            ResourceSchema resourceSchema = new ResourceSchema();

            resourceSchema.Id = "MockId";

            ResourceSchemaWriter.Write(writer, resourceSchema);
            Assert.Equal("{'id':'MockId'}", stringWriter.ToString());
        }
示例#9
0
        public void WritePropertyWithNonWhitespacePropertyValue()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string propertyName  = "mockPropertyName";
            const string propertyValue = "mockPropertyValue";

            ResourceSchemaWriter.WriteProperty(writer, propertyName, propertyValue);

            Assert.Equal("'mockPropertyName':'mockPropertyValue'", stringWriter.ToString());
        }
示例#10
0
        public void WriteWithDescription()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            ResourceSchema resourceSchema = new ResourceSchema();

            resourceSchema.Title       = "MockTitle";
            resourceSchema.Description = "MockDescription";

            ResourceSchemaWriter.Write(writer, resourceSchema);
            Assert.Equal("{'title':'MockTitle','description':'MockDescription'}", stringWriter.ToString());
        }
示例#11
0
        public void WriteWithTitle()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            ResourceSchema resourceSchema = new ResourceSchema();

            resourceSchema.Schema = "MockSchema";
            resourceSchema.Title  = "MockTitle";

            ResourceSchemaWriter.Write(writer, resourceSchema);
            Assert.Equal("{'$schema':'MockSchema','title':'MockTitle'}", stringWriter.ToString());
        }
示例#12
0
        public void WriteDefinitionWithEnumAndRequiredProperty()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string definitionName = "mockDefinition";
            JsonSchema   definition     = new JsonSchema()
                                          .AddEnum("MockEnum1", "MockEnum2")
                                          .AddProperty("mockPropertyName", new JsonSchema(), true);

            ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
            Assert.Equal("'mockDefinition':{'enum':['MockEnum1','MockEnum2'],'properties':{'mockPropertyName':{'oneOf':[{},{'$ref':'https://schema.management.azure.com/schemas/common/definitions.json#/definitions/expression'}]}},'required':['mockPropertyName']}", stringWriter.ToString());
        }
示例#13
0
        public void WriteWithOneDefinition()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            ResourceSchema resourceSchema = new ResourceSchema();

            resourceSchema.AddResourceDefinition("mockResource", new JsonSchema());
            resourceSchema.AddDefinition("mockDefinition", new JsonSchema());

            ResourceSchemaWriter.Write(writer, resourceSchema);
            Assert.Equal("{'resourceDefinitions':{'mockResource':{}},'definitions':{'mockDefinition':{}}}", stringWriter.ToString());
        }
示例#14
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':'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression'}]}},'required':['mockPropertyName'],'description':'MockDescription'}", stringWriter.ToString());
        }
示例#15
0
        public void WriteDefinitionWithTypeAndEnum()
        {
            StringWriter   stringWriter = new StringWriter();
            JsonTextWriter writer       = new JsonTextWriter(stringWriter);

            writer.QuoteChar = '\'';

            const string definitionName = "mockDefinition";
            JsonSchema   definition     = new JsonSchema()
            {
                JsonType = "MockType"
            }
            .AddEnum("MockEnum1", "MockEnum2");

            ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
            Assert.Equal("'mockDefinition':{'type':'MockType','enum':['MockEnum1','MockEnum2']}", stringWriter.ToString());
        }