public void ImplementAdditionalPropertiesTest() { var decl = new CodeTypeDeclaration() { Name = "Top" }; var dec = new AdditionalPropertiesSchemaDecorator(); var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var provider = new SchemaGenerator.NestedClassGenerator(decl, new ISchemaDecorator[0], ""); // Test generation of additional properties. var json = new JsonSchema(); json.AdditionalProperties = new JsonSchema() { Type = JsonSchemaType.Object }; implDetails.Add(json, new SchemaImplementationDetails() { ProposedName = "Sub" }); dec.ImplementAdditionalProperties(decl, json, implDetails, provider); // Confirm inheritance change. Assert.AreEqual(1, decl.BaseTypes.Count); Assert.AreEqual(typeof(string).FullName, decl.BaseTypes[0].TypeArguments[0].BaseType); Assert.AreEqual("Top.Sub", decl.BaseTypes[0].TypeArguments[1].BaseType); // Confirm generation of nested class. provider.GenerateNestedClasses(implDetails); Assert.AreEqual(1, decl.Members.Count); Assert.IsInstanceOf <CodeTypeDeclaration>(decl.Members[0]); }
public void GetClassNameWithoutDetailsTest() { var empty = new List <ISchemaDecorator>(0); var decl = new CodeTypeDeclaration() { Name = "Top" }; var gen = new SchemaGenerator.NestedClassGenerator(decl, empty, "1_"); var schema1 = new JsonSchema(); Assert.AreEqual("Top.NestedClass1_1", gen.GetClassName(schema1, null).BaseType); Assert.AreEqual("Top.NestedClass1_1", gen.GetClassName(schema1, null).BaseType); Assert.AreEqual("Top.NestedClass1_2", gen.GetClassName(new JsonSchema(), null).BaseType); }
public void DecorateClassValidationTest() { var decl = new CodeTypeDeclaration(); var dec = new AdditionalPropertiesSchemaDecorator(); var schema = new MockSchema(); var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var provider = new SchemaGenerator.NestedClassGenerator(decl, new ISchemaDecorator[0], ""); // Test all parameters. Assert.Throws <ArgumentNullException>(() => dec.DecorateClass(null, schema, implDetails, provider)); Assert.Throws <ArgumentNullException>(() => dec.DecorateClass(decl, null, implDetails, provider)); Assert.Throws <ArgumentNullException>(() => dec.DecorateClass(decl, schema, null, provider)); Assert.Throws <ArgumentNullException>(() => dec.DecorateClass(decl, schema, implDetails, null)); dec.DecorateClass(decl, schema, implDetails, provider); }
public void ImplementAdditionalPropertiesValidationTest() { var decl = new CodeTypeDeclaration(); var dec = new AdditionalPropertiesSchemaDecorator(); var json = new JsonSchema(); var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var provider = new SchemaGenerator.NestedClassGenerator(decl, new ISchemaDecorator[0], ""); // Test all parameters. Assert.Throws <ArgumentNullException>( () => dec.ImplementAdditionalProperties(null, json, implDetails, provider)); Assert.Throws <ArgumentNullException>( () => dec.ImplementAdditionalProperties(decl, null, implDetails, provider)); Assert.Throws <ArgumentNullException>( () => dec.ImplementAdditionalProperties(decl, json, null, provider)); Assert.Throws <ArgumentNullException>( () => dec.ImplementAdditionalProperties(decl, json, implDetails, null)); // Test simple operation dec.ImplementAdditionalProperties(decl, json, implDetails, provider); Assert.AreEqual(0, decl.BaseTypes.Count); Assert.AreEqual(0, decl.Members.Count); }