public void TestMembersWithPrimitiveNoDataMembersGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); rootElement.DataMembers.AddRange(LoadPrimitiveDataElements(false, false)); string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertField(PrimitiveDataElementType1, PrimitiveDataElementName1, generatedType); TypeAsserter.AssertField(PrimitiveDataElementType2, PrimitiveDataElementName2, generatedType); }
public void TestMembersWithPrimitiveCollectionTypesGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); rootElement.DataMembers.AddRange(LoadPrimitiveDataElements(typeof(List <>), true, false)); string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertField(typeof(List <int>), PrimitiveDataElementName1, generatedType); TypeAsserter.AssertField(typeof(List <string>), PrimitiveDataElementName2, generatedType); XmlArrayItemAttribute xmlArrayAttr = TypeAsserter.AssertAttribute <XmlArrayItemAttribute>(generatedType.GetProperty(PrimitiveDataElementName1)); Assert.AreEqual <string>(PrimitiveDataElementName1, xmlArrayAttr.ElementName); }
public void TestMembersWithPrimitiveInvalidCollectionTypesGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); rootElement.DataMembers.AddRange(LoadPrimitiveDataElements(typeof(Dictionary <,>), true, false)); TemplateResult result = RunTemplateWithErrors(rootElement); // should have a warning Assert.AreEqual <int>(4, result.Errors.Length); string content = result.ContentResults; Type generatedType = CompileAndGetType(content); TypeAsserter.AssertField(typeof(Collection <int>), PrimitiveDataElementName1, generatedType); TypeAsserter.AssertField(typeof(Collection <string>), PrimitiveDataElementName2, generatedType); XmlArrayItemAttribute xmlArrayAttr = TypeAsserter.AssertAttribute <XmlArrayItemAttribute>(generatedType.GetProperty(PrimitiveDataElementName1)); Assert.AreEqual <string>(PrimitiveDataElementName1, xmlArrayAttr.ElementName); }