Example #1
0
        /// <summary>
        /// Validates the model element.
        /// </summary>
        /// <param name="modelElement">The model element.</param>
        /// <param name="validationController">The validation controller.</param>
        /// <returns></returns>
        public static bool ValidateModelElement(ModelElement modelElement, ValidationController validationController)
        {
            Guard.ArgumentNotNull(modelElement, "modelElement");
            Guard.ArgumentNotNull(validationController, "validationController");

            bool isValid = true;
            HashSet <ModelElement> elementList   = new HashSet <ModelElement>();
            FullDepthElementWalker elementWalker =
                new FullDepthElementWalker(new ModelElementVisitor(elementList), new EmbeddingReferenceVisitorFilter(), false);

            elementWalker.DoTraverse(modelElement);
            validationController.ClearMessages();
            isValid = validationController.Validate(elementList, ValidationCategories.Menu);
            elementList.Clear();

            return(isValid);
        }
Example #2
0
		/// <summary>
		/// Validates the model element.
		/// </summary>
		/// <param name="modelElement">The model element.</param>
		/// <param name="validationController">The validation controller.</param>
		/// <returns></returns>
        public static bool ValidateModelElement(ModelElement modelElement, ValidationController validationController)
        {
            Guard.ArgumentNotNull(modelElement, "modelElement");
            Guard.ArgumentNotNull(validationController, "validationController");

            bool isValid = true;
            HashSet<ModelElement> elementList = new HashSet<ModelElement>();
            FullDepthElementWalker elementWalker =
                new FullDepthElementWalker(new ModelElementVisitor(elementList), new EmbeddingReferenceVisitorFilter(), false);

            elementWalker.DoTraverse(modelElement);
            validationController.ClearMessages();
            isValid = validationController.Validate(elementList, ValidationCategories.Menu);
            elementList.Clear();
            
            return isValid;
        }
		public void TestWalkerFromDomainModel()
		{
			List<ModelElement> elementList = new List<ModelElement>();

			using(Transaction t = ServiceContractStore.TransactionManager.BeginTransaction())
			{
				ServiceContractModel root = CreateServiceContractRoot();

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

				elementWalker.DoTraverse(root);

				Assert.AreEqual(1, elementList.Count);

				t.Rollback();
			}
		}
		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 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 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();
			}
		}
		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 TestWalkerFromServiceContractWithOperationWithRequestAndResponseWithPrimitiveMessageParts()
		{
			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");
				PrimitiveMessagePart part3 = CreatePrimitiveMessagePart("FooPart3");
				PrimitiveMessagePart part4 = CreatePrimitiveMessagePart("FooPart4");

				request.MessageParts.Add(part1);
				request.MessageParts.Add(part2);
				request.MessageParts.Add(part3);
				response.MessageParts.Add(part4);
				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(8, elementList.Count);

				t.Rollback();
			}
		}
		public void TestWalkerFromServiceContractWithOperationsWithDifferentRequestAndResponse()
		{
			List<ModelElement> elementList = new List<ModelElement>();

			using(Transaction t = ServiceContractStore.TransactionManager.BeginTransaction())
			{
				ServiceContractModel root = CreateServiceContractRoot();
				ServiceContract serviceContract = CreateServiceContract("Foo", "Foo");
				Operation operation1 = CreateOperationContract("FooOP1");
				Operation operation2 = CreateOperationContract("FooOP2");

				operation1.Request = CreateMessageContract("FooMCReq1", "FooMCReq1");
				operation1.Response = CreateMessageContract("FooMCRes1", "FooMCRes1");
				operation2.Request = CreateMessageContract("FooMCReq2", "FooMCReq2");
				operation2.Response = CreateMessageContract("FooMCRes2", "FooMCRes2");

				serviceContract.Operations.Add(operation1);
				serviceContract.Operations.Add(operation2);
				root.ServiceContracts.Add(serviceContract);

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

				elementWalker.DoTraverse(serviceContract);

				Assert.AreEqual(7, elementList.Count);

				t.Rollback();
			}
		}
		public void TestWalkerFromServiceContractWithOperations()
		{
			List<ModelElement> elementList = new List<ModelElement>();

			using(Transaction t = ServiceContractStore.TransactionManager.BeginTransaction())
			{
				ServiceContractModel root = CreateServiceContractRoot();
				ServiceContract serviceContract = CreateServiceContract("Foo", "Foo");

				serviceContract.Operations.Add(CreateOperationContract("FooOP1"));
				serviceContract.Operations.Add(CreateOperationContract("FooOP2"));
				root.ServiceContracts.Add(serviceContract);

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

				elementWalker.DoTraverse(serviceContract);

				Assert.AreEqual(3, elementList.Count);

				t.Rollback();
			}
		}