public void ShouldInitializeWithDefaultValues() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); Assert.AreEqual <int>(0, strategy.ProjectReferences.Count); Assert.AreEqual <int>(0, strategy.AssemblyReferences.Count); Assert.AreEqual <int>(0, strategy.Errors.Count); }
public void ShouldNotGenerateAndGetErrorWithSchemaNotFound() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("foo.xsd", "SomeElement")); Assert.AreEqual <int>(0, content.Count); Assert.AreEqual <int>(1, strategy.Errors.Count); }
public void ShouldNotGenerateAndGetErrorWithTopElementsWithoutType() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("SampleData\\TopElementNoType.xsd", "otherElement")); Assert.AreEqual <int>(0, content.Count); Assert.AreEqual <int>(1, strategy.Errors.Count); }
public void ShouldInitializeWithDefaultValues() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); Assert.AreEqual<int>(0, strategy.ProjectReferences.Count); Assert.AreEqual<int>(0, strategy.AssemblyReferences.Count); Assert.AreEqual<int>(0, strategy.Errors.Count); }
public void ShouldNotGenerateAndGetErrorWithNoSchema() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink(null, null)); Assert.AreEqual<int>(0, content.Count); Assert.AreEqual<int>(1, strategy.Errors.Count); }
public void ShouldNotGenerateAndGetErrorWithNoSchema() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink(null, null)); Assert.AreEqual <int>(0, content.Count); Assert.AreEqual <int>(1, strategy.Errors.Count); }
public void ShouldNotGenerateAndGetErrorWithSchemaNotFound() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("foo.xsd", "SomeElement")); Assert.AreEqual<int>(0, content.Count); Assert.AreEqual<int>(1, strategy.Errors.Count); }
public void ShouldGenerateWithErrorsOnInvalidSchema() { MyArtifactLink link = new MyArtifactLink("SampleData\\InvalidSchema.xsd", "SomeElement"); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual <int>(0, content.Count); Assert.AreEqual <int>(1, strategy.Errors.Count); }
public void ShouldGenerateWithErrorsOnInvalidSchema() { MyArtifactLink link = new MyArtifactLink("SampleData\\InvalidSchema.xsd", "SomeElement"); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual<int>(0, content.Count); Assert.AreEqual<int>(1, strategy.Errors.Count); }
public void ShouldGenerateWithXmlSerializerImporterFromData() { MyArtifactLinkWithXmlImporterFromData link = new MyArtifactLinkWithXmlImporterFromData("SampleData\\SimpleSchema1.xsd", "element1"); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual <int>(3, content.Count); Assert.AreEqual <int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray()); TypeAsserter.AssertAttribute <XmlRootAttribute>(results.CompiledAssembly.GetType("element1")); }
public void ShouldGenerateTypeWithBaseTypes() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("SampleData\\BaseTypes.xsd", "GetLandmarkPointsByRectResponse")); Assert.AreEqual <int>(15, content.Count); Assert.AreEqual <int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray()); Assert.IsNotNull(results.CompiledAssembly.GetType("GetLandmarkPointsByRectResponse", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LandmarkPoint", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LandmarkBase", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("ShapeType", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LonLatPt", false, false)); }
public void ShouldGenerateOneXmlRootAttribute() { MyArtifactLink link = new MyArtifactLink("SampleData\\OneXmlRootAttribute.xsd", "ImplementsAbstractCT"); Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray()); TypeAsserter.AssertAttribute <XmlRootAttribute>(results.CompiledAssembly.GetType("ImplementsAbstractCT")); Type type = results.CompiledAssembly.GetType("MyAbstractCT"); Assert.AreEqual <int>(0, type.GetCustomAttributes(typeof(XmlRootAttribute), true).Length); }
public void ShouldGenerateTypesRefsFromAttributes() { MyArtifactLink link = new MyArtifactLink("SampleData\\TypeRefsInAttributes.wsdl", "AttachmentAddRq"); Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual <int>(69, content.Count); Assert.AreEqual <int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray()); Assert.AreEqual <int>(69, results.CompiledAssembly.GetTypes().Length); Assert.IsNotNull(results.CompiledAssembly.GetType("AddressType", false, false)); }
public void ThrowOnNullArtifactLink() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); strategy.Generate(null); }
public void ShouldGenerateOneXmlRootAttribute() { MyArtifactLink link = new MyArtifactLink("SampleData\\OneXmlRootAttribute.xsd", "ImplementsAbstractCT"); Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray()); TypeAsserter.AssertAttribute<XmlRootAttribute>(results.CompiledAssembly.GetType("ImplementsAbstractCT")); Type type = results.CompiledAssembly.GetType("MyAbstractCT"); Assert.AreEqual<int>(0, type.GetCustomAttributes(typeof(XmlRootAttribute), true).Length); }
public void ShouldGenerateTypesRefsFromAttributes() { MyArtifactLink link = new MyArtifactLink("SampleData\\TypeRefsInAttributes.wsdl", "AttachmentAddRq"); Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual<int>(69, content.Count); Assert.AreEqual<int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray()); Assert.AreEqual<int>(69, results.CompiledAssembly.GetTypes().Length); Assert.IsNotNull(results.CompiledAssembly.GetType("AddressType", false, false)); }
public void ShouldGenerateTypeWithBaseTypes() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("SampleData\\BaseTypes.xsd", "GetLandmarkPointsByRectResponse")); Assert.AreEqual<int>(15, content.Count); Assert.AreEqual<int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray()); Assert.IsNotNull(results.CompiledAssembly.GetType("GetLandmarkPointsByRectResponse", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LandmarkPoint", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LandmarkBase", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("ShapeType", false, false)); Assert.IsNotNull(results.CompiledAssembly.GetType("LonLatPt", false, false)); }
public void ShouldNotGenerateAndGetErrorWithTopElementsWithoutType() { XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(new MyArtifactLink("SampleData\\TopElementNoType.xsd", "otherElement")); Assert.AreEqual<int>(0, content.Count); Assert.AreEqual<int>(1, strategy.Errors.Count); }
public void ShouldGenerateWithSimpleSchema() { MyArtifactLink link = new MyArtifactLink("SampleData\\SimpleSchema1.xsd", "element1"); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual<int>(3, content.Count); Assert.AreEqual<int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray()); Assert.AreEqual<int>(3, results.CompiledAssembly.GetTypes().Length); TypeAsserter.AssertAttribute<DataContractAttribute>(results.CompiledAssembly.GetType("element1")); }
public void ShouldHandleCircularRefSchema() { MyArtifactLinkWithXmlImporterFromData link = new MyArtifactLinkWithXmlImporterFromData("SampleData\\CircularRefSchema.xsd", "element1"); XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy(); CodeGenerationResults content = strategy.Generate(link); Assert.AreEqual<int>(3, content.Count); Assert.AreEqual<int>(0, strategy.Errors.Count); CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray()); TypeAsserter.AssertAttribute<XmlRootAttribute>(results.CompiledAssembly.GetType("element1")); TypeAsserter.AssertAttribute<XmlTypeAttribute>(results.CompiledAssembly.GetType("complexType1")); TypeAsserter.AssertAttribute<XmlTypeAttribute>(results.CompiledAssembly.GetType("complexType2")); }