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 TestXsdMessageUnwrappedRequestGeneration()
		{
			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;
			XsdMessage request = new XsdMessage(Store);
			request.Name = "Request1";
			request.Element = @"xsd://schemas\file.xsd?MyType";
			request.IsWrapped = false;
			request.ServiceContractModel = rootElement.ServiceContractModel;
			AsmxXsdMessageContract wcfXsdMc = new AsmxXsdMessageContract();
			wcfXsdMc.ModelElement = request;
			request.ObjectExtender = wcfXsdMc;

			op1.Request = request;
			string content = RunTemplate(rootElement);

			EnsureType(ref content, "MyType");
			Type generatedType = CompileAndGetType(content);
			MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType);
			Assert.AreEqual<int>(1, method.GetParameters().Length);
			Assert.AreEqual<string>("MyType", ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name);
			Assert.AreEqual<string>("Void", method.ReturnType.Name);
		}
        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);
        }
Beispiel #4
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            XsdMessage           messageContract = e.ModelElement as XsdMessage;
            ServiceContractModel root            = messageContract.ServiceContractModel;

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(messageContract, root.ImplementationTechnology);
            }
        }
Beispiel #5
0
        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 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 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);
		}
Beispiel #8
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);
        }
Beispiel #9
0
        public void TestXsdMessageUnwrappedRequestGeneration()
        {
            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;
            XsdMessage request = new XsdMessage(Store);

            request.Name                 = "Request1";
            request.Element              = @"xsd://schemas\file.xsd?MyType";
            request.IsWrapped            = false;
            request.ServiceContractModel = rootElement.ServiceContractModel;
            AsmxXsdMessageContract wcfXsdMc = new AsmxXsdMessageContract();

            wcfXsdMc.ModelElement  = request;
            request.ObjectExtender = wcfXsdMc;

            op1.Request = request;
            string content = RunTemplate(rootElement);

            EnsureType(ref content, "MyType");
            Type       generatedType = CompileAndGetType(content);
            MethodInfo method        = TypeAsserter.AssertMethod(op1.Name, generatedType);

            Assert.AreEqual <int>(1, method.GetParameters().Length);
            Assert.AreEqual <string>("MyType", ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name);
            Assert.AreEqual <string>("Void", method.ReturnType.Name);
        }
		public void ShouldGenerateKnownTypeAttributeWithXsdExtendedTypesNotDuplicated()
		{
			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;

			XsdMessage response = new XsdMessage(Store);
			response.Name = "Response1";
			response.Element = @"xsd://SampleData/BaseTypes.xsd?LandmarkPoint";
			response.ServiceContractModel = rootElement.ServiceContractModel;
			WCFXsdMessageContract wcfXsdMc2 = new WCFXsdMessageContract();
			wcfXsdMc2.ModelElement = request;
			response.ObjectExtender = wcfXsdMc2;

			op1.Request = request;
			op1.Response = response;
			string content = RunTemplate(rootElement);

			EnsureType(ref content, "Request1");
			EnsureType(ref content, "Response1");
			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);
		}