public void DecorateClassGenerationTest() { var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var decorator = new ArraySchemaDecorator(); var internalClassProvider = new ObjectInternalClassProvider(); var decl = new CodeTypeDeclaration(); var schema = new MockSchema(); schema.Name = "test"; schema.SchemaDetails = new JsonSchema(); schema.SchemaDetails.Type = JsonSchemaType.Array; schema.SchemaDetails.Items = new List <JsonSchema>(); schema.SchemaDetails.Items.Clear(); schema.SchemaDetails.Items.Add( new JsonSchema { Description = "Test", Id = "TestSchema", Type = JsonSchemaType.Object }); implDetails.Add(schema.SchemaDetails, new SchemaImplementationDetails()); implDetails.Add(schema.SchemaDetails.Items[0], new SchemaImplementationDetails()); Assert.DoesNotThrow(() => decorator.DecorateClass(decl, schema, implDetails, internalClassProvider)); Assert.That(decl.BaseTypes.Count, Is.EqualTo(1)); Assert.That(decl.BaseTypes[0].BaseType, Is.EqualTo(typeof(List <>).FullName)); // Subtype will only be created later on by the NestedClassGenerator, // and therefore cannot be tested here }
public void DecorateClassTestEdgeCases() { var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var decorator = new ArraySchemaDecorator(); var internalClassProvider = new ObjectInternalClassProvider(); CodeTypeDeclaration declaration = null; var schema = new MockSchema(); schema.Name = "test"; schema.SchemaDetails = null; Assert.Throws( typeof(ArgumentNullException), () => decorator.DecorateClass(new CodeTypeDeclaration(), schema, implDetails, internalClassProvider)); schema.SchemaDetails = new JsonSchema(); schema.SchemaDetails.Type = JsonSchemaType.Float; Assert.DoesNotThrow( () => decorator.DecorateClass( declaration = new CodeTypeDeclaration(), schema, implDetails, internalClassProvider)); Assert.That(declaration.BaseTypes.Count, Is.EqualTo(0)); schema.SchemaDetails.Type = JsonSchemaType.Array; schema.SchemaDetails.Items = new List <JsonSchema>(); schema.SchemaDetails.Items.Add(new JsonSchema()); schema.SchemaDetails.Items.Add(new JsonSchema()); Assert.DoesNotThrow( () => decorator.DecorateClass( declaration = new CodeTypeDeclaration(), schema, implDetails, internalClassProvider)); Assert.That(declaration.BaseTypes.Count, Is.EqualTo(0)); }
public void DecorateClassTest() { var implDetails = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var decorator = new ArraySchemaDecorator(); var declaration = new CodeTypeDeclaration(); var schema = new MockSchema { SchemaDetails = new JsonSchema() }; var internalClassProvider = new ObjectInternalClassProvider(); Assert.Throws( typeof(ArgumentNullException), () => decorator.DecorateClass(null, schema, implDetails, internalClassProvider)); Assert.Throws( typeof(ArgumentNullException), () => decorator.DecorateClass(declaration, null, implDetails, internalClassProvider)); Assert.Throws( typeof(ArgumentNullException), () => decorator.DecorateClass(declaration, schema, null, internalClassProvider)); Assert.Throws( typeof(ArgumentNullException), () => decorator.DecorateClass(declaration, schema, implDetails, null)); decorator.DecorateClass(declaration, schema, implDetails, internalClassProvider); }