Example #1
0
        private DataContractMessagePart CreateDataContractMessagePart(string name, string type)
        {
            DataContractMessagePart messagePart = new DataContractMessagePart(ServiceContractStore);

            messagePart.Name = name;
            //messagePart.Type = type;
            return(messagePart);
        }
Example #2
0
        public void TestWalkerFromMessageContractWithDataContractMessagePartsWithDataElements()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = DataContractStore.TransactionManager.BeginTransaction())
            {
                DataContractModel dcRoot        = CreateDataContractRoot();
                DataContract      dataContract1 = CreateDataContract("FooDc");
                PrimitiveDataType element1      = CreatePrimitiveDataElement("FooElement1");
                PrimitiveDataType element2      = CreatePrimitiveDataElement("FooElement2");
                DataContract      dataContract2 = CreateDataContract("FooDc1");
                PrimitiveDataType element3      = CreatePrimitiveDataElement("FooElement1");
                PrimitiveDataType element4      = CreatePrimitiveDataElement("FooElement2");

                dataContract1.DataMembers.Add(element1);
                dataContract1.DataMembers.Add(element2);
                dataContract2.DataMembers.Add(element3);
                dataContract2.DataMembers.Add(element4);
                dcRoot.Contracts.Add(dataContract1);
                dcRoot.Contracts.Add(dataContract2);

                using (Transaction t1 = ServiceContractStore.TransactionManager.BeginTransaction())
                {
                    ServiceContractModel scRoot   = CreateServiceContractRoot();
                    Message request               = CreateMessageContract("FooMCReq", "FooMCReq");
                    DataContractMessagePart part1 =
                        CreateDataContractMessagePart(
                            "FooPart1",
                            GetMockMoniker(dataContract1));
                    DataContractMessagePart part2 =
                        CreateDataContractMessagePart(
                            "FooPart2",
                            GetMockMoniker(dataContract2));


                    request.MessageParts.Add(part1);
                    request.MessageParts.Add(part2);
                    scRoot.Messages.Add(request);

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

                    elementWalker.DoTraverse(request);

                    Assert.AreEqual(3, elementList.Count);                     // 9 elemsn with Resolver

                    t1.Rollback();
                }

                t.Rollback();
            }
        }
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            DataContractMessagePart messagePart = e.ModelElement as DataContractMessagePart;

            if (messagePart.Message != null)
            {
                ServiceContractModel root = messagePart.Message.ServiceContractModel;
                if (root != null && root.ImplementationTechnology != null)
                {
                    ExtensionProviderHelper.AttachObjectExtender(messagePart, root.ImplementationTechnology);
                }
            }
        }
Example #4
0
        public void TestWalkerFromServiceContractWithOperationWithRequestAndResponseWithDataContractMessagePart()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = DataContractStore.TransactionManager.BeginTransaction())
            {
                using (Transaction t1 = 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");
                    DataContract            dataContract  = CreateDataContract("FooDc");
                    DataContract            dataContract1 = CreateDataContract("FooDc1");
                    DataContractMessagePart part1         =
                        CreateDataContractMessagePart(
                            "FooPart1",
                            GetMockMoniker(dataContract));
                    DataContractMessagePart part2 =
                        CreateDataContractMessagePart(
                            "FooPart2",
                            GetMockMoniker(dataContract1));

                    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);                      // 8 elemns with Resolver

                    t1.Rollback();
                }

                t.Rollback();
            }
        }
        public void TestInitialize()
        {
            serviceProvider = new MockMappingServiceProvider();

            attributes = new NameValueCollection();
            attributes.Add("elementNameProperty", "Name");

            #region Data Contract
            dcStore       = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));
            dcDomainModel = dcStore.GetDomainModel <DataContractDslDomainModel>();
            dcTransaction = dcStore.TransactionManager.BeginTransaction();
            dcModel       = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null);
            dcModel.ProjectMappingTable = projectMappingTableName;
            dc = dcStore.ElementFactory.CreateElement(DataContract.DomainClassId) as DataContract;
            primitiveDataElement      = dcStore.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
            primitiveDataElement.Name = primitiveDataElementName;
            dc.DataMembers.Add(primitiveDataElement);
            dcModel.Contracts.Add(dc);
            #endregion

            #region Service Contract
            scStore       = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
            scDomainModel = scStore.GetDomainModel <ServiceContractDslDomainModel>();
            scTransaction = scStore.TransactionManager.BeginTransaction();
            scModel       = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null);
            scModel.ProjectMappingTable = projectMappingTableName;
            msg      = scStore.ElementFactory.CreateElement(Message.DomainClassId) as Message;
            msg.Name = messageName;

            //Create the moniker
            //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE]
            string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                                                  primitiveDataElement.GetType().Namespace,
                                                  primitiveDataElement.GetType().Name,
                                                  primitiveDataElement.Id.ToString(),
                                                  dataContractModelProjectName, dataContractModelFileName);

            part      = scStore.ElementFactory.CreateElement(DataContractMessagePart.DomainClassId) as DataContractMessagePart;
            part.Name = partName;
            part.Type = new MockModelBusReference(primitiveDataElement);

            msg.MessageParts.Add(part);
            scModel.Messages.Add(msg);
            #endregion
        }
Example #6
0
        public void TestWalkerFromMessageContractWithDataContractCollectionMessagePart()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = DataContractStore.TransactionManager.BeginTransaction())
            {
                DataContractModel      dcRoot                 = CreateDataContractRoot();
                DataContract           dataContract           = CreateDataContract("FooDc");
                DataContractCollection dataContractCollection = CreateDataContractCollection("FooDcc");
                dataContractCollection.DataContract = dataContract;

                dcRoot.Contracts.Add(dataContract);
                dcRoot.Contracts.Add(dataContractCollection);

                using (Transaction t1 = ServiceContractStore.TransactionManager.BeginTransaction())
                {
                    ServiceContractModel scRoot   = CreateServiceContractRoot();
                    Message request               = CreateMessageContract("FooMCReq", "FooMCReq");
                    DataContractMessagePart part1 =
                        CreateDataContractMessagePart(
                            "FooPart1",
                            GetMockMoniker(dataContract));

                    request.MessageParts.Add(part1);
                    scRoot.Messages.Add(request);

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

                    elementWalker.DoTraverse(request);

                    Assert.AreEqual(2, elementList.Count);                     // 4 elemsn with Resolver

                    t1.Rollback();
                }

                t.Rollback();
            }
        }
		public void CanAddDataContractMessageContractPart()
		{
			ServiceContract serviceContract = new ServiceContract(Store);
			serviceContract.ServiceContractModel = new ServiceContractModel(Store);

			Message message = new Message(Store);
			DataContractMessagePart dcMessagePart = new DataContractMessagePart(Store);

            string moniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                dcMessagePart.GetType().Namespace,
                dcMessagePart.GetType().Name,
                dcMessagePart.Id.ToString(),
                dataContractModelProjectName, dataContractModelFileName);

            //dcMessagePart.Type = moniker;

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

			Assert.AreEqual<int>(serviceContract.ServiceContractModel.Messages[0].MessageParts.Count, 1);
		}
Example #8
0
        public void ShouldGenerateDataContractMessagePart()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

            Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace);

            rootElement.ServiceContractModel.ProjectMappingTable = "ASMX";

            DataContractMessagePart part = new DataContractMessagePart(Store);

            part.Name = "TestProperty";
            //part.Type = @"mel://Microsoft.Practices.ServiceFactory.DataContracts\DataContract\[email protected]\dc.datacontract";

            rootElement.MessageParts.Add(part);

            string content = RunTemplateWithDIS(rootElement);

            //StringAssert.Contains(content, "FooDC TestProperty");
            StringAssert.Contains(content, MessageContractElementName);
            StringAssert.Contains(content, MessageContractElementNamespace);
        }
Example #9
0
        public void CanAddDataContractMessageContractPart()
        {
            ServiceContract serviceContract = new ServiceContract(Store);

            serviceContract.ServiceContractModel = new ServiceContractModel(Store);

            Message message = new Message(Store);
            DataContractMessagePart dcMessagePart = new DataContractMessagePart(Store);

            string moniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                                           dcMessagePart.GetType().Namespace,
                                           dcMessagePart.GetType().Name,
                                           dcMessagePart.Id.ToString(),
                                           dataContractModelProjectName, dataContractModelFileName);

            //dcMessagePart.Type = moniker;

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

            Assert.AreEqual <int>(serviceContract.ServiceContractModel.Messages[0].MessageParts.Count, 1);
        }
        /// <summary>
        /// Does the validate.
        /// </summary>
        /// <param name="objectToValidate">The object to validate.</param>
        /// <param name="currentTarget">The current target.</param>
        /// <param name="key">The key.</param>
        /// <param name="validationResults">The validation results.</param>
        protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            this.MessageTemplate = currentMessageTemplate;

            base.DoValidate(objectToValidate, currentTarget, key, validationResults);

            if (!validationResults.IsValid)
            {
                return;
            }

            DataContractMessagePart part = currentTarget as DataContractMessagePart;

            if (part == null ||
                part.Message.ServiceContractModel.ImplementationTechnology == null)
            {
                return;
            }

            string dcImplementationTechnology = GetDcImplementationTechnology(objectToValidate);

            if (IsASMX(part.Message.ServiceContractModel.ImplementationTechnology.Name))
            {
                if (part.Message.ServiceContractModel.SerializerType.Equals(SerializerType.XmlSerializer))
                {
                    if (IsWCF(dcImplementationTechnology))
                    {
                        this.LogValidationResult(
                            validationResults,
                            string.Format(CultureInfo.CurrentCulture, Resources.ImplementationTechnologyAndSerializerValidatorMessage, part.Name),
                            currentTarget,
                            key);
                    }
                }
            }
            else if (IsWCF(part.Message.ServiceContractModel.ImplementationTechnology.Name))
            {
                if (part.Message.ServiceContractModel.SerializerType.Equals(SerializerType.DataContractSerializer))
                {
                    if (IsASMX(dcImplementationTechnology))
                    {
                        this.LogValidationResult(
                            validationResults,
                            string.Format(CultureInfo.CurrentCulture, Resources.ImplementationTechnologyAndSerializerValidatorMessage, part.Name),
                            currentTarget,
                            key);
                    }
                }
                else
                {
                    if (IsWCF(dcImplementationTechnology))
                    {
                        this.LogValidationResult(
                            validationResults,
                            Resources.InvalidExtensionAndSerializerCrossModelMessage,
                            currentTarget,
                            key);
                    }
                }
            }
        }
		private DataContractMessagePart CreateDataContractMessagePart(string name, string type)
		{
			DataContractMessagePart messagePart = new DataContractMessagePart(ServiceContractStore);
			messagePart.Name = name;
			//messagePart.Type = type;
			return messagePart;
		}
		public void ShouldGenerateDataContractMessagePart()
		{
			ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");

			Message rootElement = CreateRoot<Message>(MessageContractElementName, MessageContractElementNamespace);
			rootElement.ServiceContractModel.ProjectMappingTable = "ASMX";

			DataContractMessagePart part = new DataContractMessagePart(Store);
			part.Name = "TestProperty";
			//part.Type = @"mel://Microsoft.Practices.ServiceFactory.DataContracts\DataContract\[email protected]\dc.datacontract";

			rootElement.MessageParts.Add(part);

			string content = RunTemplateWithDIS(rootElement);

			//StringAssert.Contains(content, "FooDC TestProperty");
            StringAssert.Contains(content, MessageContractElementName);
            StringAssert.Contains(content, MessageContractElementNamespace);
		}
        public void TestInitialize()
        {
            serviceProvider = new MockMappingServiceProvider();

			attributes = new NameValueCollection();
			attributes.Add("elementNameProperty", "Name");

            #region Data Contract
            dcStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));
            dcDomainModel = dcStore.GetDomainModel<DataContractDslDomainModel>();
            dcTransaction = dcStore.TransactionManager.BeginTransaction();
            dcModel = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null);
            dcModel.ProjectMappingTable = projectMappingTableName;
            dc = dcStore.ElementFactory.CreateElement(DataContract.DomainClassId) as DataContract;
			primitiveDataElement = dcStore.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
            primitiveDataElement.Name = primitiveDataElementName;
			dc.DataMembers.Add(primitiveDataElement);
			dcModel.Contracts.Add(dc);
            #endregion

			#region Service Contract
			scStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
			scDomainModel = scStore.GetDomainModel<ServiceContractDslDomainModel>();
			scTransaction = scStore.TransactionManager.BeginTransaction();
			scModel = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null);
			scModel.ProjectMappingTable = projectMappingTableName;
			msg = scStore.ElementFactory.CreateElement(Message.DomainClassId) as Message;
			msg.Name = messageName;

            //Create the moniker
            //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE]
            string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                primitiveDataElement.GetType().Namespace,
                primitiveDataElement.GetType().Name,
                primitiveDataElement.Id.ToString(),
                dataContractModelProjectName, dataContractModelFileName);

			part = scStore.ElementFactory.CreateElement(DataContractMessagePart.DomainClassId) as DataContractMessagePart;
			part.Name = partName;
            part.Type = new MockModelBusReference(primitiveDataElement);
			
            msg.MessageParts.Add(part);
			scModel.Messages.Add(msg);
            #endregion
        }