public void ShouldGetActionValueWithDefaultUriSlashEnded() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace + "/"); Operation op1 = new Operation(Store); op1.ServiceContract = rootElement; op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; // commit the tx and trigger the OperationAddRule so the action value will be filled with the default value this.transaction.Commit(); this.transaction = Store.TransactionManager.BeginTransaction(); op1.Name = "op2"; this.transaction.Commit(); this.transaction = null; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method); Assert.AreEqual <string>(rootElement.Namespace + rootElement.Name + "/op2", operation.Action); }
public void TestRequestGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; Message request = new Message(Store); request.Name = "Request1"; op1.Request = request; string content = RunTemplate(rootElement); EnsureType(ref content, "Request1"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); Assert.AreEqual <int>(1, method.GetParameters().Length); Assert.AreEqual <string>("Request1", ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name); Assert.AreEqual <string>("Void", method.ReturnType.Name); }
public void TestAsyncOperationGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); WCFOperationContract wfcOperationContract = new WCFOperationContract(); wfcOperationContract.AsyncPattern = true; op1.ObjectExtender = wfcOperationContract; op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo beginMethod = TypeAsserter.AssertMethod("Begin" + op1.Name, generatedType); Assert.AreEqual <int>(2, beginMethod.GetParameters().Length); Assert.AreEqual <string>("IAsyncResult", beginMethod.ReturnType.Name); MethodInfo endMethod = TypeAsserter.AssertMethod("End" + op1.Name, generatedType); Assert.AreEqual <int>(1, endMethod.GetParameters().Length); Assert.AreEqual <string>("Void", endMethod.ReturnType.Name); }
public void TestFaultMessagesGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; DataContractFault fault1 = new DataContractFault(Store); fault1.Name = "fault1"; //fault1.Type = @"[DSLNAMESPACE]\[MODELELEMENTTYPE]\fault1Type@[PROJECT]\[MODELFILE]"; fault1.Operation = op1; DataContractFault fault2 = new DataContractFault(Store); fault2.Name = "fault2"; //fault2.Type = @"[DSLNAMESPACE]\[MODELELEMENTTYPE]\fault2Type@[PROJECT]\[MODELFILE]"; ; fault2.Operation = op1; processFault = true; ResolveModelElement(fault1.Name); ResolveModelElement(fault2.Name); string content = RunTemplateWithDIS(rootElement); StringAssert.Contains(content, "I" + ServiceContractElementName); StringAssert.Contains(content, ServiceContractElementNamespace); }
public void TestOperationGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); Assert.AreEqual <int>(0, method.GetParameters().Length); Assert.AreEqual <string>("Void", method.ReturnType.Name); OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method); Assert.AreEqual <string>(op1.Action, operation.Action); Assert.IsNull(operation.Name); Assert.AreEqual <bool>(op1.IsOneWay, operation.IsOneWay); Assert.AreEqual <bool>(((WCFOperationContract)op1.ObjectExtender).IsTerminating, operation.IsTerminating); Assert.AreEqual <bool>(((WCFOperationContract)op1.ObjectExtender).IsInitiating, operation.IsInitiating); Assert.AreEqual <ProtectionLevel>(((WCFOperationContract)op1.ObjectExtender).ProtectionLevel, operation.ProtectionLevel); Assert.IsNull(operation.ReplyAction); Assert.IsTrue(operation.HasProtectionLevel); }
public void ShouldGenerateCorrectElementNameInMessageContract() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); XsdMessage rootElement = CreateRoot<XsdMessage>(MessageContractElementName, MessageContractElementNamespace); rootElement.IsWrapped = true; rootElement.Element = "xsd:\\file.xsd?MyType"; rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; rootElement.ServiceContractModel.SerializerType = SerializerType.DataContractSerializer; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); Assert.AreEqual<string>(MessageContractElementName, generatedType.Name); Assert.AreEqual<string>(DefaultNamespace, generatedType.Namespace); Assert.AreEqual<int>(2, generatedType.GetConstructors().Length); MessageContractAttribute messageContract = TypeAsserter.AssertAttribute<MessageContractAttribute>(generatedType); Assert.AreEqual<string>(MessageContractElementName, messageContract.WrapperName); Assert.IsNotNull(messageContract.WrapperNamespace); Assert.IsTrue(messageContract.IsWrapped); PropertyInfo property = generatedType.GetProperty("MyType"); Assert.IsNotNull(property); MessageBodyMemberAttribute bodyAttr = TypeAsserter.AssertAttribute<MessageBodyMemberAttribute>(property); Assert.AreEqual<string>(messageContract.WrapperNamespace, bodyAttr.Namespace); Assert.AreEqual<int>(0, bodyAttr.Order); }
public void TestPrimitiveHeaderGenerationWithDictionaryCollectionType() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); PrimitiveDataTypeCollection collectionElement = CreateDefaultPrimitiveDataTypeCollection(typeof(Dictionary <,>), PrimitiveDataElementType1); TemplateResult result = RunTemplateWithErrors(collectionElement); // should have a warning Assert.AreEqual <int>(1, result.Errors.Length); string content = result.ContentResults; Type generatedType = CompileAndGetType(content); Assert.IsTrue(generatedType.IsClass); Assert.AreEqual <Type>(typeof(Collection <int>), generatedType.BaseType); XmlRootAttribute xmlRootAttr = TypeAsserter.AssertAttribute <XmlRootAttribute>(generatedType); Assert.AreEqual <string>(ElementNamespace, xmlRootAttr.Namespace); Assert.IsFalse(xmlRootAttr.IsNullable); XmlTypeAttribute xmlTypeAttr = TypeAsserter.AssertAttribute <XmlTypeAttribute>(generatedType); Assert.AreEqual <string>(ElementNamespace, xmlTypeAttr.Namespace); }
public void ShouldGenerateStringCollectionPrimitiveMessagePart() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "ASMX"; PrimitiveMessagePart primitivePart = new PrimitiveMessagePart(Store); primitivePart.Name = "TestProperty"; primitivePart.Type = typeof(System.String).ToString(); primitivePart.IsCollection = true; rootElement.MessageParts.Add(primitivePart); string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); PropertyInfo propInfo = generatedType.GetProperty("TestProperty"); Assert.IsNotNull(propInfo); Type expectedType = typeof(List <String>); Assert.AreEqual <Type>(propInfo.PropertyType, expectedType); }
public void TestSoapDocumentMethodAttributeParanmeters() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.ImplementationTechnology = new ServiceContractAsmxExtensionProvider(); rootElement.ServiceContractModel.SerializerType = SerializerType.XmlSerializer; Operation op1 = new Operation(Store); op1.ObjectExtender = new AsmxOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); SoapDocumentMethodAttribute soapAttr = TypeAsserter.AssertAttribute <SoapDocumentMethodAttribute>(method); Assert.AreEqual(soapAttr.ParameterStyle, SoapParameterStyle.Wrapped); Assert.AreEqual <string>(soapAttr.Action, rootElement.Namespace + "/" + op1.Action); }
public void ShouldGenerateCorrectXmlSerializerAttributes() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; PrimitiveMessagePart primitivePart = new PrimitiveMessagePart(Store); primitivePart.Name = "TestProperty"; primitivePart.Type = typeof(System.String).ToString(); rootElement.MessageParts.Add(primitivePart); WCFMessageContract wcfMc = new WCFMessageContract(true); wcfMc.ModelElement = rootElement; rootElement.ObjectExtender = wcfMc; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertAttribute <XmlSerializerFormatAttribute>(generatedType); PropertyInfo property = generatedType.GetProperty(primitivePart.Name); TypeAsserter.AssertAttribute <XmlElementAttribute>(property); }
public void ShouldGenerateKnownTypeAttributeWithXsdExtendedTypes() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.ImplementationTechnology = new ServiceContractWCFExtensionProvider(); rootElement.ServiceContractModel.SerializerType = Microsoft.Practices.ServiceFactory.ServiceContracts.SerializerType.DataContractSerializer; Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; XsdMessage request = new XsdMessage(Store); request.Name = "Request1"; request.Element = @"xsd://SampleData/BaseTypes.xsd?LandmarkPoint"; request.ServiceContractModel = rootElement.ServiceContractModel; WCFXsdMessageContract wcfXsdMc = new WCFXsdMessageContract(); wcfXsdMc.ModelElement = request; request.ObjectExtender = wcfXsdMc; op1.Request = request; string content = RunTemplate(rootElement); EnsureType(ref content, "Request1"); EnsureType(ref content, "LandmarkBase"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); ServiceKnownTypeAttribute attribute = TypeAsserter.AssertAttribute <ServiceKnownTypeAttribute>(method); Assert.AreEqual <string>("LandmarkBase", attribute.Type.Name); }
public void ShouldGenerateAllPrimitiveMessageParts() { Type[] candidateTypes = new Type[] { typeof(System.String), typeof(System.Int16), typeof(System.Int32), typeof(System.Int64), typeof(System.Double), typeof(System.Single) }; string propertyNameFormat = "TestProperty{0}"; ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; foreach (Type partType in candidateTypes) { PrimitiveMessagePart primitivePart = new PrimitiveMessagePart(Store); primitivePart.Name = string.Format(propertyNameFormat, partType.ToString().Replace('.', '_')); primitivePart.Type = partType.ToString(); rootElement.MessageParts.Add(primitivePart); } string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); foreach (Type partType in candidateTypes) { string propertyName = string.Format(propertyNameFormat, partType.ToString().Replace('.', '_')); PropertyInfo propInfo = generatedType.GetProperty(propertyName); Assert.IsNotNull(propInfo, string.Format("Could not locate {0} property in Message Contract", propertyName)); Assert.AreEqual <string>(partType.ToString(), propInfo.PropertyType.ToString()); } }
public void TestMembersWithPrimitiveNullableTypeGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); rootElement.DataMembers.Add(LoadPrimitiveDataElement(PrimitiveDataElementName1, PrimitiveDataElementType1, false, true, true)); string content = RunTemplate(rootElement); Assert.IsTrue(content.Contains("private System.Nullable<int>")); }
public void TestOperationWithoutObjectExtender() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Operation op1 = new Operation(Store); op1.ObjectExtender = null; op1.Request = new Message(Store); Assert.AreEqual(0, op1.ArtifactLinks.Count); }
public void ShouldGeneratePartialClass() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "ASMX"; string content = RunTemplate(rootElement); Assert.IsTrue(content.Contains("public partial class " + MessageContractElementName)); }
public void ShouldGenerateXmlSerializerFormatAttributeWithXmlSerialize() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.SerializerType = Microsoft.Practices.ServiceFactory.ServiceContracts.SerializerType.XmlSerializer; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertAttribute <XmlSerializerFormatAttribute>(generatedType); }
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 ShouldNotGenerateWithUnwrappedMessage() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); XsdMessage rootElement = CreateRoot <XsdMessage>(MessageContractElementName, MessageContractElementNamespace); rootElement.IsWrapped = false; rootElement.Element = "xsd:\\file.xsd?MyType"; rootElement.ServiceContractModel.ProjectMappingTable = "ASMX"; string content = RunTemplate(rootElement); Assert.AreEqual <string>(string.Empty, content); }
public void TestHeaderGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); Assert.AreEqual <string>(ElementName, generatedType.Name); DataContractAttribute dataContract = TypeAsserter.AssertAttribute <DataContractAttribute>(generatedType); Assert.AreEqual <string>(ElementNamespace, dataContract.Namespace); }
public void ShouldCompileWithValidClassName() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "ASMX"; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); Assert.AreEqual <string>(MessageContractElementName, generatedType.Name); Assert.AreEqual <string>(DefaultNamespace, generatedType.Namespace); }
public void TestHeaderGeneration() { string content; ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); content = RunTemplate(rootElement); Assert.IsTrue(content.Contains("public partial interface IName1")); Type generatedType = CompileAndGetType(content); Assert.AreEqual <string>("I" + ServiceContractElementName, generatedType.Name); }
public void TestPrimitiveHeaderGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); PrimitiveDataTypeCollection collectionElement = CreateDefaultPrimitiveDataTypeCollection(typeof(Collection <>), PrimitiveDataElementType1); string content = RunTemplate(collectionElement); Type generatedType = CompileAndGetType(content); Assert.IsTrue(generatedType.IsClass); Assert.AreEqual <Type>(typeof(Collection <int>), generatedType.BaseType); CollectionDataContractAttribute collectionAttr = TypeAsserter.AssertAttribute <CollectionDataContractAttribute>(generatedType); Assert.AreEqual <string>(ElementNamespace, collectionAttr.Namespace); }
public void TestMembersWithPrimitiveNullableTypeGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); rootElement.DataMembers.Add(LoadPrimitiveDataElement(PrimitiveDataElementName1, PrimitiveDataElementType1, null, true, true)); string content = RunTemplate(rootElement); EnsureType(ref content, DataContractLinkedElementType); Type generatedType = CompileAndGetType(content); XmlElementAttribute xmlElementAttr = TypeAsserter.AssertAttribute <XmlElementAttribute>(generatedType.GetProperty(PrimitiveDataElementName1)); Assert.IsTrue(xmlElementAttr.IsNullable); }
public void ShouldNotGenerateWithUnwrappedMessage() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); XsdMessage rootElement = CreateRoot<XsdMessage>(MessageContractElementName, MessageContractElementNamespace); rootElement.IsWrapped = false; rootElement.Element = "xsd:\\file.xsd?MyType"; rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; rootElement.ServiceContractModel.SerializerType = SerializerType.DataContractSerializer; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); MessageContractAttribute messageContract = TypeAsserter.AssertAttribute<MessageContractAttribute>(generatedType); Assert.IsFalse(messageContract.IsWrapped); }
public void TestHeaderGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); Assert.AreEqual <string>("I" + ServiceContractElementName, generatedType.Name); Assert.IsTrue(generatedType.IsInterface); ServiceContractAttribute serviceContract = TypeAsserter.AssertAttribute <ServiceContractAttribute>(generatedType); Assert.AreEqual <string>(ServiceContractElementName, serviceContract.Name); Assert.AreEqual <string>(ServiceContractElementNamespace, serviceContract.Namespace); Assert.AreEqual(ProtectionLevel.None, serviceContract.ProtectionLevel); }
public void TestHeaderGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContractCollection collectionElement = CreateDefaultDataContractCollectionElement(typeof(Collection <>)); string content = RunTemplate(collectionElement); this.EnsureType(ref content, PrimitiveDataElementName1); Type generatedType = CompileAndGetType(content); Assert.IsTrue(generatedType.IsClass); Assert.AreEqual <string>(((WCFDataContractCollection)collectionElement.ObjectExtender).CollectionType.Name, generatedType.BaseType.Name); Assert.IsTrue(generatedType.BaseType.FullName.Contains(PrimitiveDataElementName1)); CollectionDataContractAttribute collectionAttr = TypeAsserter.AssertAttribute <CollectionDataContractAttribute>(generatedType); Assert.AreEqual <string>(ElementNamespace, collectionAttr.Namespace); }
public void TestMembersWithPrimitiveEnumTypeGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml"); DataContract rootElement = CreateDefaultDataContract(); DataContractEnum enumElement = new DataContractEnum(Store); enumElement.Name = PrimitiveDataElementName1; rootElement.DataContractModel.Contracts.Add(enumElement); rootElement.DataMembers.AddRange(LoadLinkedElements(enumElement)); string content = RunTemplate(rootElement); this.EnsureType(ref content, PrimitiveDataElementName1); Type generatedType = CompileAndGetType(content); KnownTypeAttribute knownTypeAttr = TypeAsserter.AssertAttribute <KnownTypeAttribute>(generatedType); Assert.AreEqual <string>(PrimitiveDataElementName1, knownTypeAttr.Type.Name); }
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 ShouldErrorWhenPrimitivePartHasEmptyType() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace); rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; PrimitiveMessagePart primitivePart = new PrimitiveMessagePart(Store); primitivePart.Name = "TestProperty"; primitivePart.Type = string.Empty; rootElement.MessageParts.Add(primitivePart); TemplateResult result = RunTemplateWithErrors(rootElement); Assert.AreEqual <int>(1, result.Errors.Length); //StringAssert.Contains(result.Errors[0], "Cannot generate Message Contract due to invalid type"); }
public void ShouldGenerateCorrectXmlSerializerAttributes() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); XsdMessage rootElement = CreateRoot<XsdMessage>(MessageContractElementName, MessageContractElementNamespace); rootElement.IsWrapped = true; rootElement.Element = "xsd:\\file.xsd?MyType"; rootElement.ServiceContractModel.ProjectMappingTable = "WCF"; rootElement.ServiceContractModel.SerializerType = SerializerType.XmlSerializer; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertAttribute<XmlSerializerFormatAttribute>(generatedType); PropertyInfo property = generatedType.GetProperty("MyType"); Assert.IsNotNull(property); TypeAsserter.AssertAttribute<XmlElementAttribute>(property); }