Esempio n. 1
0
        public void TestWalkerFromMessageContractWithPrimitiveMessageParts()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = ServiceContractStore.TransactionManager.BeginTransaction())
            {
                ServiceContractModel root  = CreateServiceContractRoot();
                Message request            = CreateMessageContract("FooMCReq", "FooMCReq");
                PrimitiveMessagePart part1 = CreatePrimitiveMessagePart("FooPart1");
                PrimitiveMessagePart part2 = CreatePrimitiveMessagePart("FooPart2");
                PrimitiveMessagePart part3 = CreatePrimitiveMessagePart("FooPart3");

                request.MessageParts.Add(part1);
                request.MessageParts.Add(part2);
                request.MessageParts.Add(part3);
                root.Messages.Add(request);

                FullDepthElementWalker elementWalker =
                    new FullDepthElementWalker(
                        new ModelElementVisitor(elementList),
                        new EmbeddingReferenceVisitorFilter(),
                        false);

                elementWalker.DoTraverse(request);

                Assert.AreEqual(4, elementList.Count);

                t.Rollback();
            }
        }
Esempio n. 2
0
        public void TestWalkerFromServiceContractWithOperationWithRequestAndResponseWithPrimitiveMessagePart()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = ServiceContractStore.TransactionManager.BeginTransaction())
            {
                ServiceContractModel root            = CreateServiceContractRoot();
                ServiceContract      serviceContract = CreateServiceContract("Foo", "Foo");
                Operation            operation       = CreateOperationContract("FooOP");
                Message request            = CreateMessageContract("FooMCReq", "FooMCReq");
                Message response           = CreateMessageContract("FooMCRes", "FooMCRes");
                PrimitiveMessagePart part1 = CreatePrimitiveMessagePart("FooPart1");
                PrimitiveMessagePart part2 = CreatePrimitiveMessagePart("FooPart2");

                request.MessageParts.Add(part1);
                response.MessageParts.Add(part2);
                operation.Request  = request;
                operation.Response = response;
                serviceContract.Operations.Add(operation);
                root.ServiceContracts.Add(serviceContract);

                FullDepthElementWalker elementWalker =
                    new FullDepthElementWalker(
                        new ModelElementVisitor(elementList),
                        new EmbeddingReferenceVisitorFilter(),
                        false);

                elementWalker.DoTraverse(serviceContract);

                Assert.AreEqual(6, elementList.Count);

                t.Rollback();
            }
        }
Esempio n. 3
0
        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 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 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());
            }
        }
Esempio n. 6
0
        private PrimitiveMessagePart CreatePrimitiveMessagePart(string name)
        {
            PrimitiveMessagePart messagePart = new PrimitiveMessagePart(ServiceContractStore);

            messagePart.Name = name;
            messagePart.Type = "System.String";
            return(messagePart);
        }
Esempio n. 7
0
        private PrimitiveMessagePart CreatePrimitiveMessagePart()
        {
            PrimitiveMessagePart part = Store.ElementFactory.CreateElement(PrimitiveMessagePart.DomainClassId) as PrimitiveMessagePart;

            part.Name = "Part1";

            return(part);
        }
 private bool IsValidPart(PrimitiveMessagePart item, List <PrimitiveMessagePart> parts)
 {
     foreach (PrimitiveMessagePart part in parts)
     {
         if (part.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase) &&
             !part.Type.Equals(item.Type, StringComparison.OrdinalIgnoreCase) ||
             part.IsCollection != item.IsCollection)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 9
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            PrimitiveMessagePart messagePart = e.ModelElement as PrimitiveMessagePart;

            if (messagePart.Message != null)
            {
                ServiceContractModel root = messagePart.Message.ServiceContractModel;
                if (root != null && root.ImplementationTechnology != null)
                {
                    ExtensionProviderHelper.AttachObjectExtender(messagePart, root.ImplementationTechnology);
                }
            }
        }
        protected override void DoValidate(IEnumerable <MessageBase> objectToValidate, object currentTarget, string key, Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResults validationResults)
        {
            ServiceContractModel scm = currentTarget as ServiceContractModel;

            if (scm == null)
            {
                return;
            }

            if (scm.ImplementationTechnology != null &&
                !scm.ImplementationTechnology.Name.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase) ||
                scm.SerializerType != SerializerType.XmlSerializer)
            {
                return;
            }

            List <PrimitiveMessagePart> parts = new List <PrimitiveMessagePart>();

            foreach (MessageBase message in objectToValidate)
            {
                if (message is XsdMessage)
                {
                    continue;
                }

                if (!GetIsWrapped(message))
                {
                    foreach (MessagePart part in message.MessageParts)
                    {
                        PrimitiveMessagePart primitivePart = part as PrimitiveMessagePart;
                        if (primitivePart != null)
                        {
                            if (parts.Count == 0)
                            {
                                parts.Add(primitivePart);
                            }
                            else
                            {
                                if (!IsValidPart(primitivePart, parts))
                                {
                                    validationResults.AddResult(
                                        new ValidationResult(this.MessageTemplate, objectToValidate, key, String.Empty, this)
                                        );
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
		public void CanAddStringPrimitiveMessageContractPart()
		{
			ServiceContract serviceContract = new ServiceContract(Store);
			serviceContract.ServiceContractModel = new ServiceContractModel(Store);

			Message message = new Message(Store);
			PrimitiveMessagePart primitiveMessagePart = new PrimitiveMessagePart(Store);
			primitiveMessagePart.Type = typeof(System.String).ToString();

			message.MessageParts.Add(primitiveMessagePart);
			serviceContract.ServiceContractModel.Messages.Add(message);

			Assert.AreEqual<int>(serviceContract.ServiceContractModel.Messages[0].MessageParts.Count, 1);
		}
Esempio n. 12
0
        public void ReturnSucceedForIsWrappedWithOneBodyPart()
        {
            Message mc = CreateMessageContract();
            PrimitiveMessagePart part = CreatePrimitiveMessagePart();

            mc.MessageParts.Add(part);

            TestIsWrappedValidator validator         = new TestIsWrappedValidator();
            ValidationResults      validationResults = new ValidationResults();

            validator.TestDoValidate(false, mc, "IsWrapped", validationResults);

            Assert.IsTrue(validationResults.IsValid);
        }
Esempio n. 13
0
        public void CanAddStringPrimitiveMessageContractPart()
        {
            ServiceContract serviceContract = new ServiceContract(Store);

            serviceContract.ServiceContractModel = new ServiceContractModel(Store);

            Message message = new Message(Store);
            PrimitiveMessagePart primitiveMessagePart = new PrimitiveMessagePart(Store);

            primitiveMessagePart.Type = typeof(System.String).ToString();

            message.MessageParts.Add(primitiveMessagePart);
            serviceContract.ServiceContractModel.Messages.Add(message);

            Assert.AreEqual <int>(serviceContract.ServiceContractModel.Messages[0].MessageParts.Count, 1);
        }
		public void ShouldGenerateStringPrimitiveMessagePart()
		{
			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);

			string content = RunTemplate(rootElement);

			Type generatedType = CompileAndGetType(content);
			PropertyInfo propInfo = generatedType.GetProperty("TestProperty");
			Assert.IsNotNull(propInfo);
			Assert.AreEqual<string>(propInfo.PropertyType.ToString(), primitivePart.Type);
		}
        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");
        }
Esempio n. 16
0
        public void ReturnFailureForIsWrappedWithBodyParts()
        {
            Message mc = CreateMessageContract();
            PrimitiveMessagePart part  = CreatePrimitiveMessagePart();
            PrimitiveMessagePart part2 = CreatePrimitiveMessagePart();

            part2.Name = "Part2";

            mc.MessageParts.Add(part);
            mc.MessageParts.Add(part2);

            TestIsWrappedValidator validator         = new TestIsWrappedValidator();
            ValidationResults      validationResults = new ValidationResults();

            validator.TestDoValidate(false, mc, "IsWrapped", validationResults);

            Assert.IsFalse(validationResults.IsValid);
        }
		private PrimitiveMessagePart CreatePrimitiveMessagePart(string name)
		{
			PrimitiveMessagePart messagePart = new PrimitiveMessagePart(ServiceContractStore);
			messagePart.Name = name;
			messagePart.Type = "System.String";
			return messagePart;
		}
		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 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 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");
		}