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 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 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 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 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 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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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 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);
        }
Beispiel #10
0
        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 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);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        public void ShouldCompileWithValidXmlAttribute()
        {
            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);
            XmlRootAttribute xmlRootAttribute = TypeAsserter.AssertAttribute <XmlRootAttribute>(generatedType);

            Assert.AreEqual <string>(MessageContractElementName, xmlRootAttribute.ElementName);
            Assert.AreEqual <string>(MessageContractElementNamespace, xmlRootAttribute.Namespace);
        }
Beispiel #14
0
        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);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public void TestMembersWithPrimitiveNoDataMembersGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml");

            DataContract rootElement = CreateDefaultDataContract();

            rootElement.DataMembers.AddRange(LoadPrimitiveDataElements(null, false, false));
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);

            TypeAsserter.AssertField(PrimitiveDataElementType1, PrimitiveDataElementName1, generatedType);
            TypeAsserter.AssertField(PrimitiveDataElementType2, PrimitiveDataElementName2, generatedType);
            XmlIgnoreAttribute xmlIgnoreAttr = TypeAsserter.AssertAttribute <XmlIgnoreAttribute>(generatedType.GetProperty(PrimitiveDataElementName1));

            Assert.IsNotNull(xmlIgnoreAttr);
        }
		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);
		}
        public void TestWFCHeaderGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");
            ServiceContract    rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace);
            WCFServiceContract extender    = new WCFServiceContract();

            extender.SessionMode       = SessionMode.Required;
            extender.ModelElement      = rootElement;
            rootElement.ObjectExtender = extender;
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);
            ServiceContractAttribute serviceContract = TypeAsserter.AssertAttribute <ServiceContractAttribute>(generatedType);

            Assert.AreEqual <string>(ServiceContractElementName, serviceContract.Name);
            Assert.AreEqual <string>(ServiceContractElementNamespace, serviceContract.Namespace);
            Assert.AreEqual <SessionMode>(SessionMode.Required, serviceContract.SessionMode);
        }
Beispiel #23
0
        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);
            SerializableAttribute serializableAttr = TypeAsserter.AssertAttribute <System.SerializableAttribute>(generatedType);

            Assert.IsNotNull(serializableAttr);
            XmlRootAttribute xmlRootAttr = TypeAsserter.AssertAttribute <XmlRootAttribute>(generatedType);

            Assert.AreEqual <string>(ElementNamespace, xmlRootAttr.Namespace);
            Assert.IsFalse(xmlRootAttr.IsNullable);
        }
        public void ShouldGenerateCorrectElementNameInMessageContract()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");
            Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace);

            rootElement.ServiceContractModel.ProjectMappingTable = "WCF";

            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);
            MessageContractAttribute messageContract = TypeAsserter.AssertAttribute <MessageContractAttribute>(generatedType);

            Assert.AreEqual <string>(MessageContractElementName, generatedType.Name);
            Assert.AreEqual <string>(DefaultNamespace, generatedType.Namespace);
            Assert.IsFalse(messageContract.HasProtectionLevel);
            Assert.IsNull(messageContract.WrapperName);
            Assert.IsNull(messageContract.WrapperNamespace);
            Assert.IsFalse(messageContract.IsWrapped);
        }
        public void TestReplyActionGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            ServiceContract      rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace);
            Operation            op1         = new Operation(Store);
            WCFOperationContract oc          = new WCFOperationContract();

            oc.ReplyAction      = "foo";
            op1.ObjectExtender  = oc;
            op1.Name            = "op1";
            op1.ServiceContract = rootElement;
            string content = RunTemplate(rootElement);

            Type       generatedType             = CompileAndGetType(content);
            MethodInfo method                    = TypeAsserter.AssertMethod(op1.Name, generatedType);
            OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method);

            Assert.AreEqual <string>(oc.ReplyAction, operation.ReplyAction);
        }
Beispiel #26
0
        public void TestWCFDataElementPropertiesGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml");
            DataContract   rootElement = CreateDefaultDataContract();
            WCFDataElement dataElement = new WCFDataElement();

            dataElement.IsRequired = true;
            dataElement.Order      = 1;
            PrimitiveDataType element = LoadDefaultPrimitiveDataElement();

            element.ObjectExtender = dataElement;
            rootElement.DataMembers.Add(element);
            string content = RunTemplate(rootElement);

            Type generatedType             = CompileAndGetType(content);
            DataMemberAttribute dataMember = TypeAsserter.AssertAttribute <DataMemberAttribute>(generatedType.GetProperty(element.Name));

            Assert.IsTrue(dataMember.IsRequired);
            Assert.AreEqual <int>(1, dataMember.Order);
        }
        public void TestHeaderGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            Service rootElement = CreateDefaultService();

            rootElement.Namespace = ServiceNamespace;
            WCFService extender = new WCFService();

            extender.ModelElement      = rootElement;
            rootElement.ObjectExtender = extender;
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);
            ServiceBehaviorAttribute serviceBehavior = TypeAsserter.AssertAttribute <ServiceBehaviorAttribute>(generatedType);

            Assert.AreEqual <string>(ServiceName, serviceBehavior.Name);
            Assert.AreEqual <string>(ServiceNamespace, serviceBehavior.Namespace);
            Assert.AreEqual <InstanceContextMode>(InstanceContextMode.PerSession, serviceBehavior.InstanceContextMode);
            Assert.AreEqual <ConcurrencyMode>(ConcurrencyMode.Single, serviceBehavior.ConcurrencyMode);
        }
        public void TestHeaderGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            Service rootElement = CreateDefaultService();

            rootElement.Namespace = ServiceNamespace;
            AsmxService extender = new AsmxService();

            extender.ModelElement      = rootElement;
            rootElement.ObjectExtender = extender;
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);

            Assert.AreEqual <Type>(typeof(System.Web.Services.WebService), generatedType.BaseType.BaseType);
            WebServiceAttribute serviceBehavior = TypeAsserter.AssertAttribute <WebServiceAttribute>(generatedType);

            Assert.AreEqual <string>(ServiceName, serviceBehavior.Name);
            Assert.AreEqual <string>(ServiceNamespace, serviceBehavior.Namespace);
        }
Beispiel #29
0
        public void TestEnumDataElementsGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml");

            DataContractEnum rootElement = CreateDefaultDataContractEnum();

            rootElement.EnumNamedValues.AddRange(LoadEnumDataElements());
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);

            TypeAsserter.AssertExistPublicField(EnumElement1Name, generatedType);

            XmlEnumAttribute attrib = TypeAsserter.AssertAttribute <XmlEnumAttribute>(generatedType.GetField(EnumElement1Name));

            Assert.AreEqual <string>(EnumElement1Value, attrib.Name);

            TypeAsserter.AssertExistPublicField(EnumElement2Name, generatedType);
            attrib = TypeAsserter.AssertAttribute <XmlEnumAttribute>(generatedType.GetField(EnumElement2Name));
            Assert.AreEqual <string>(EnumElement2Value, attrib.Name);
        }
Beispiel #30
0
        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 = "ASMX";

            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);
            XmlRootAttribute xmlRoot = TypeAsserter.AssertAttribute <XmlRootAttribute>(generatedType);

            Assert.AreEqual <string>(this.MessageContractElementNamespace, xmlRoot.Namespace);
            Assert.IsFalse(xmlRoot.IsNullable);
        }