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);
        }
Exemplo n.º 2
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);
        }
        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 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);
        }
        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 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);
        }
Exemplo n.º 11
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"));
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        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 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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 20
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);
        }
        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);
        }
Exemplo n.º 22
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);
        }
		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);
        }
Exemplo n.º 25
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 NullServiceContractGeneratesServiceContract()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            Service rootElement = CreateDefaultService();

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

            extender.ModelElement       = rootElement;
            rootElement.ObjectExtender  = extender;
            rootElement.ServiceContract = null;

            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);

            TypeAsserter.AssertInterface(ServiceContractInterfaceName, generatedType, 0);
        }
Exemplo n.º 28
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 TestOperationWithoutResponse()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            Service rootElement = CreateDefaultService();

            rootElement.ServiceContract = CreateServiceContract(rootElement.ServiceContractModel, ServiceContractName, OperationName, RequestName, null);
            string content = RunTemplate(rootElement);

            EnsureType(ref content, ServiceContractInterfaceName);
            EnsureType(ref content, RequestName);
            string implementationContent = this.GetImplementationContent(ImplementationKind.Request);
            Type   generatedType         = CompileAndGetType(content + implementationContent);

            TypeAsserter.AssertInterface(GetFullServiceContractInterfaceName(), generatedType);
            MethodInfo method = TypeAsserter.AssertMethod(OperationName, generatedType);

            Assert.AreEqual <string>(RequestName, ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name);
            Assert.AreEqual <string>("Void", method.ReturnType.Name);
        }
        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);
        }