public void ShouldNotRejectSameSource()
		{
			DataContract source = new DataContract(Store);
			bool result = AggregationConnectionBuilder.CanAcceptSourceAndTarget(source, source);

			Assert.IsTrue(result);
		}
		public void ShouldNotRejectSameLink()
		{
			DataContract source = new DataContract(Store);
			DataContract target = new DataContract(Store);
			DataContractBaseCanBeContainedOnContracts link = new DataContractBaseCanBeContainedOnContracts(source, target);
			ModelElementReference dataElement = new ModelElementReference(Store);
			dataElement.SetLinkedElement(link.Id);
			source.DataMembers.Add(dataElement);
			bool result = AggregationConnectionBuilder.CanAcceptSourceAndTarget(source, target);

			Assert.IsTrue(result);
		}
        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
        }
		private DataContract CreateDataContract(string name)
		{
			DataContract dataContract = new DataContract(DataContractStore);
			dataContract.Name = name;
			return dataContract;
		}
		protected override ModelElement ResolveModelElement(string instanceNamespace)
		{
			if (this.processFault)
			{
				return ResolveFaultElement(instanceNamespace);
			}

			using (Transaction transaction = DataContractStore.TransactionManager.BeginTransaction())
			{
				DataContract dc = new DataContract(DataContractStore);
				dc.DataContractModel = new DataContractModel(DataContractStore);
				dc.DataContractModel.ProjectMappingTable = "WCF";
				dc.Name = instanceNamespace;
				WCFDataContract extender = new WCFDataContract();
				dc.ObjectExtender = extender;
				extender.ModelElement = dc;
				transaction.Commit();
				return dc;
			}
		}
		public void ShouldGetNewNameOnSelfReference()
		{
			DataContract source = new DataContract(Store);
			source.Name = "DC";
			AggregationConnectionBuilder.Connect(source, source);

			Assert.AreEqual(1, source.DataMembers.Count);
			ModelElementReference dataElement = (ModelElementReference)source.DataMembers[0];
			Assert.AreEqual("DC", source.Name);
			Assert.AreNotEqual(source.Name, dataElement.Name);
			Assert.AreEqual("DC1", dataElement.Name);
		}
		public void ShouldGetNewNameOnMultipleTargets()
		{
			DataContract source = new DataContract(Store);
			source.Name = "Source";
			DataContract target = new DataContract(Store);
			target.Name = "Target";
			DataContractBaseCanBeContainedOnContracts link = new DataContractBaseCanBeContainedOnContracts(source, target);
			ModelElementReference dataElement = new ModelElementReference(Store);
			dataElement.Name = "DcdeName";
			dataElement.SetLinkedElement(link.Id);
			source.DataMembers.Add(dataElement);
			AggregationConnectionBuilder.Connect(source, target);

			Assert.AreEqual(1, target.DataMembers.Count);
			dataElement = (ModelElementReference)target.DataMembers[0];
			Assert.AreEqual("Source", dataElement.Name);

			AggregationConnectionBuilder.Connect(source, target);

			Assert.AreEqual(2, target.DataMembers.Count);
			dataElement = (ModelElementReference)target.DataMembers[1];
			Assert.AreEqual("Source1", dataElement.Name);

			AggregationConnectionBuilder.Connect(source, target);

			Assert.AreEqual(3, target.DataMembers.Count);
			dataElement = (ModelElementReference)target.DataMembers[2];
			Assert.AreEqual("Source2", dataElement.Name);
		}
Exemplo n.º 8
0
		public static DslModeling::LinkedElementCollection<DataMember> GetDataMembers(DataContract element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<DataMember>, DataMember>(element, DataContractDomainRoleId);
		}
Exemplo n.º 9
0
		public static void SetDataContract(DataMember element, DataContract newDataContract)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, DataMemberDomainRoleId, newDataContract);
		}
Exemplo n.º 10
0
		/// <summary>
		/// Constructor
		/// Creates a DataContractHasDataMembers link in the same Partition as the given DataContract
		/// </summary>
		/// <param name="source">DataContract to use as the source of the relationship.</param>
		/// <param name="target">DataMember to use as the target of the relationship.</param>
		public DataContractHasDataMembers(DataContract source, DataMember target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DataContractHasDataMembers.DataContractDomainRoleId, source), new DslModeling::RoleAssignment(DataContractHasDataMembers.DataMemberDomainRoleId, target)}, null)
		{
		}
		protected override ModelElement ResolveModelElement(string instanceNamespace)
		{
			using (Transaction transaction = DataContractStore.TransactionManager.BeginTransaction())
			{
				DataContract dc = new DataContract(DataContractStore);
				dc.DataContractModel = new DataContractModel(DataContractStore);
				dc.DataContractModel.ProjectMappingTable = "ASMX";
				dc.Name = "FooDC";
				AsmxDataContract extender = new AsmxDataContract();
				dc.ObjectExtender = extender;
				extender.ModelElement = dc;
				transaction.Commit();
				return dc;
			}
		}
Exemplo n.º 12
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, DataContract element, global::System.Xml.XmlWriter writer)
		{
			// DataContractHasDataMembers
			global::System.Collections.ObjectModel.ReadOnlyCollection<DataContractHasDataMembers> allDataContractHasDataMembersInstances = DataContractHasDataMembers.GetLinksToDataMembers(element);
			if (!serializationContext.Result.Failed && allDataContractHasDataMembersInstances.Count > 0)
			{
				writer.WriteStartElement("dataMembers");
				global::System.Type typeofDataContractHasDataMembers = typeof(DataContractHasDataMembers);
				foreach (DataContractHasDataMembers eachDataContractHasDataMembersInstance in allDataContractHasDataMembersInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachDataContractHasDataMembersInstance.GetType() != typeofDataContractHasDataMembers)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachDataContractHasDataMembersInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachDataContractHasDataMembersInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachDataContractHasDataMembersInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachDataContractHasDataMembersInstance.DataMember;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
		}
Exemplo n.º 13
0
		/// <summary>
		/// Reads all instances of relationship DataContractHasDataMembers.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory DataContract instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDataContractHasDataMembersInstances(DslModeling::SerializationContext serializationContext, DataContract element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDataMemberOfDataContractHasDataMembersSerializer = serializationContext.Directory.GetSerializer(DataMember.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDataMemberOfDataContractHasDataMembersSerializer != null, "Cannot find serializer for DataMember!");
				DataMember newDataMemberOfDataContractHasDataMembers = newDataMemberOfDataContractHasDataMembersSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as DataMember;
				if (newDataMemberOfDataContractHasDataMembers != null)
				{
					element.DataMembers.Add(newDataMemberOfDataContractHasDataMembers);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataMemberOfDataContractHasDataMembers.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataMemberOfDataContractHasDataMembers.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newDataMemberOfDataContractHasDataMembers, reader);
				}
				else
				{
					global::System.Type typeofDataContractHasDataMembers = typeof(DataContractHasDataMembers);
					DslModeling::DomainRelationshipXmlSerializer newDataContractHasDataMembersSerializer = serializationContext.Directory.GetSerializer(DataContractHasDataMembers.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newDataContractHasDataMembersSerializer != null, "Cannot find serializer for DataContractHasDataMembers!");
					DataContractHasDataMembers newDataContractHasDataMembers = newDataContractHasDataMembersSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DataContractHasDataMembers;
					if (newDataContractHasDataMembers != null)
					{
						if (newDataContractHasDataMembers.GetType() == typeofDataContractHasDataMembers)
						{	// The relationship should be serialized in short-form.
							DataContractDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(DataContractHasDataMembers));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newDataContractHasDataMembers, DataContractHasDataMembers.DataContractDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataContractHasDataMembers.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataContractHasDataMembers.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newDataContractHasDataMembers, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Exemplo n.º 14
0
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies that if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory DataContract instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, DataContract element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "dataMembers", global::System.StringComparison.CurrentCulture) == 0)
				{
					if (reader.IsEmptyElement)
					{	// No instance of this relationship, just skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
					else
					{
						DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <dataMembers>
						ReadDataContractHasDataMembersInstances(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </dataMembers>
					}
				}
			}
		}