Пример #1
0
		/// <summary>
		/// Removes a relationship definition from the collection
		/// </summary>
		/// <param name="relationshipDef">The Relationship definition to remove</param>
		protected void Remove(IRelationshipDef relationshipDef)
		{
			if (Contains(relationshipDef))
			{
                _relDefs.Remove(relationshipDef.RelationshipName);
			}
		}
Пример #2
0
 /// <summary>
 /// Add an existing relationship to the collection
 /// </summary>
 /// <param name="relationshipDef">The existing relationship to add</param>
 public void Add(IRelationshipDef relationshipDef)
 {
     if (Contains(relationshipDef))
     {
         throw new ArgumentException(String.Format(
             "A relationship definition with the name '{0}' already " +
             "exists.", relationshipDef.RelationshipName));
     }
     _relDefs.Add(relationshipDef.RelationshipName, relationshipDef);
 }
Пример #3
0
        Test_Valid_Relationship_SingleSingleRelationships_CanDetermine_OwningBOHasForeignKey_ReverseDoesNotHave()
        {
            //----------------------Test Setup ----------------------
            const string classDefsString =
                @"
					<classes>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey>
								<prop name=""TestClassID""/>
							</primaryKey>
							<relationship name=""TestRelatedClass"" type=""single"" relatedClass=""TestRelatedClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" reverseRelationship=""TestClass"" owningBOHasForeignKey=""true"" >
								<relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
							</relationship>
						</class>
						<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestRelatedClassID"" type=""Guid"" />
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey>
								<prop name=""TestRelatedClassID""/>
							</primaryKey>
							<relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" reverseRelationship=""TestRelatedClass"" >
								<relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
							</relationship>
						</class>
					</classes>
			"            ;
            XmlClassDefsLoader loader       = CreateXmlClassDefsLoader();
            ClassDefCol        classDefList = loader.LoadClassDefs(classDefsString);
            ClassDefValidator  validator    = new ClassDefValidator(GetDefClassFactory());

            IClassDef        classDef               = classDefList.FindByClassName("TestClass");
            IRelationshipDef relationshipDef        = classDef.RelationshipDefCol["TestRelatedClass"];
            IClassDef        reverseClassDef        = classDefList.FindByClassName("TestRelatedClass");
            IRelationshipDef reverseRelationshipDef = reverseClassDef.RelationshipDefCol["TestClass"];

            //--------------------Assert PreConditions---------------
            Assert.IsTrue(relationshipDef.OwningBOHasForeignKey);
            Assert.IsTrue(reverseRelationshipDef.OwningBOHasForeignKey);

            //--------------------Execute Test-------------------------
            validator.ValidateClassDefs(classDefList);
            //---------------Test Result -----------------------
            Assert.IsFalse(relationshipDef.OwningBOHasForeignKey);
            Assert.IsTrue(reverseRelationshipDef.OwningBOHasForeignKey);
        }
Пример #4
0
        public void Test_Valid_Relationship_SingleSingleRelationships_OnlyOneHasOwningBOHasForeignKey()
        {
            //----------------------Test Setup ----------------------
            const string classDefsString =
                @"
					<classes>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey>
								<prop name=""TestClassID""/>
							</primaryKey>
							<relationship name=""TestRelatedClass"" type=""single"" relatedClass=""TestRelatedClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" owningBOHasForeignKey=""true"" reverseRelationship=""TestClass"">
								<relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
							</relationship>
						</class>
						<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestRelatedClassID"" type=""Guid"" />
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey>
								<prop name=""TestRelatedClassID""/>
							</primaryKey>
							<relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" reverseRelationship=""TestRelatedClass"" owningBOHasForeignKey=""false"" >
								<relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
							</relationship>
						</class>
					</classes>
			"            ;
            XmlClassDefsLoader loader       = CreateXmlClassDefsLoader();
            ClassDefCol        classDefList = loader.LoadClassDefs(classDefsString);
            ClassDefValidator  validator    = new ClassDefValidator(GetDefClassFactory());
            //--------------------Assert PreConditions---------------
            IClassDef        classDef        = classDefList.FindByClassName("TestClass");
            IRelationshipDef relationshipDef = classDef.RelationshipDefCol["TestRelatedClass"];

            Assert.IsTrue(relationshipDef.OwningBOHasForeignKey, "This defaults to true");
            IClassDef        revesreclassDef        = classDefList.FindByClassName("TestClass");
            IRelationshipDef reverserelationshipDef = revesreclassDef.RelationshipDefCol["TestRelatedClass"];

            Assert.IsTrue(reverserelationshipDef.OwningBOHasForeignKey, "This defaults to true");

            //--------------------Execute Test-------------------------
            validator.ValidateClassDefs(classDefList);
            //---------------Test Result -----------------------
            Assert.IsFalse(relationshipDef.OwningBOHasForeignKey, "Should have converted this to false");
            Assert.IsFalse(reverserelationshipDef.OwningBOHasForeignKey, "Should have converted this to false");
        }
Пример #5
0
        public virtual void Test_WithTypeParameter()
        {
            //---------------Set up test pack-------------------
            XmlClassLoader loader         = new XmlClassLoader(new DtdLoader(), GetDefClassFactory());
            IClassDef      personClassDef =
                loader.LoadClass(
                    @"
				<class name=""ContactPersonTestBO"" assembly=""Habanero.Test.BO"" table=""contact_person"" typeParameter=""Human"">
					<property name=""ContactPersonID"" type=""Guid"" />
					<property name=""Surname"" databaseField=""Surname_field"" compulsory=""true"" />
                    <property name=""FirstName"" databaseField=""FirstName_field"" />
					<property name=""DateOfBirth"" type=""DateTime"" />
					<primaryKey>
						<prop name=""ContactPersonID"" />
					</primaryKey>
			    </class>
			"            );

            ClassDef.ClassDefs.Add(personClassDef);


            const string relXml = @"
					<relationship 
						name=""TestRelationship"" 
						type=""single"" 
                        relatedClass=""ContactPersonTestBO"" 
						relatedAssembly=""Habanero.Test.BO""
                        typeParameter=""Human""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>"                    ;
            //---------------Assert PreConditions---------------
            // Assert.IsTrue(ClassDef.ClassDefs.Contains("Habanero.Test.BO", "ContactPersonTestBO_Human"));

            //---------------Execute Test ----------------------

            IRelationshipDef relDef = _loader.LoadRelationship(relXml, _propDefs);

            //---------------Test Result -----------------------

            Assert.AreEqual(personClassDef.ClassNameExcludingTypeParameter, relDef.RelatedObjectClassName);
            Assert.AreEqual(personClassDef.TypeParameter, relDef.RelatedObjectTypeParameter);
            Assert.AreEqual(personClassDef.AssemblyName, relDef.RelatedObjectAssemblyName);
            //---------------Tear Down -------------------------
        }
Пример #6
0
        public void Test_Valid_Relationship_1_M_Relationships_CanDetermine_OwningBOHasForeignKey_SecondClass_SetAsFalse()
        {
            //----------------------Test Setup ----------------------
            const string       classDefsString = @"
					<classes>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestClassID""/>
                            </primaryKey>
					        <relationship name=""TestRelatedClass"" type=""multiple"" relatedClass=""TestRelatedClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" 
                                            reverseRelationship=""TestClass"" owningBOHasForeignKey=""true"" >
						        <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
					        </relationship>
						</class>
						<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestRelatedClassID"" type=""Guid"" />
							<property  name=""TestClassID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestRelatedClassID""/>
                            </primaryKey>
					        <relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" 
                                            reverseRelationship=""TestRelatedClass"" owningBOHasForeignKey=""false"" >
						        <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
					        </relationship>
						</class>
					</classes>
			"            ;
            XmlClassDefsLoader loader          = CreateXmlClassDefsLoader();
            //--------------------Execute Test-------------------------
            ClassDefCol classDefList = loader.LoadClassDefs(classDefsString);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, classDefList.Count);
            Assert.IsTrue(classDefList.Contains("Habanero.Test.BO.Loaders", "TestClass"), "Class 'TestClass' should have been loaded.");
            Assert.IsTrue(classDefList.Contains("Habanero.Test.BO.Loaders", "TestRelatedClass"), "Class 'TestRelatedClass' should have been loaded.");

            IClassDef        classDef               = classDefList.FindByClassName("TestClass");
            IRelationshipDef relationshipDef        = classDef.RelationshipDefCol["TestRelatedClass"];
            IClassDef        reverseClassDef        = classDefList.FindByClassName("TestRelatedClass");
            IRelationshipDef reverseRelationshipDef = reverseClassDef.RelationshipDefCol["TestClass"];

            Assert.IsFalse(relationshipDef.OwningBOHasForeignKey);
            Assert.IsTrue(reverseRelationshipDef.OwningBOHasForeignKey);
        }
Пример #7
0
 /// <summary>
 /// Constructor to initialise a new relationship
 /// </summary>
 /// <param name="owningBo">The business object from where the
 /// relationship originates</param>
 /// <param name="lRelDef">The relationship definition</param>
 /// <param name="lBOPropCol">The set of properties used to
 /// initialise the RelKey object</param>
 protected Relationship(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
 {
     if (owningBo == null)
     {
         throw new ArgumentNullException("owningBo");
     }
     if (lRelDef == null)
     {
         throw new ArgumentNullException("lRelDef");
     }
     if (lBOPropCol == null)
     {
         throw new ArgumentNullException("lBOPropCol");
     }
     _relDef   = lRelDef;
     _owningBo = owningBo;
     _relKey   = new Lazy <IRelKey>(() => _relDef.RelKeyDef.CreateRelKey(lBOPropCol));
 }
        public void Test_GetValidRelationshipValue_ShouldCreateRelatedBO()
        {
            //---------------Set up test pack-------------------
            var boTestFactory  = new BOTestFactory(typeof(FakeBO));
            var businessObject = (FakeBO)boTestFactory.CreateValidBusinessObject();
            var relationship   = businessObject.Relationships["NonCompulsoryRelationship"] as ISingleRelationship;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            IRelationshipDef relationshipDef        = relationship.RelationshipDef;
            IBusinessObject  validRelationshipValue = boTestFactory.GetValidRelationshipValue(relationshipDef as ISingleValueDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(validRelationshipValue);
            Assert.IsTrue(validRelationshipValue.Status.IsNew);
        }
Пример #9
0
        public void Test_IsOneToOne_WhenNoRevRelTypeLoaded_SetOneToOneSetToFalse_ShouldReturnFalseBug944()
        {
            //---------------Set up test pack-------------------
            var singleRelationshipDef = new FakeSingleRelationshipDef
            {
                ReverseRelationshipName = GetRandomString()
            };
            IRelationshipDef relationshipDef = singleRelationshipDef;

            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof(SingleRelationshipDef), relationshipDef);
            Assert.IsNotNullOrEmpty(relationshipDef.ReverseRelationshipName);
            //---------------Execute Test ----------------------
            bool isOneToOne = relationshipDef.IsOneToOne;

            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToOne);
        }
Пример #10
0
        public void Test_Multiple_InsertAction_Default_ShouldBeInsertRelationship()
        {
            //---------------Set up test pack-------------------
            const string singleRelationshipStringComposition = @"
					<relationship 
						name=""TestRelationship"" 
						type=""multiple"" 
                        relatedClass=""Habanero.Test.BO.Loaders.TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>"                    ;
            //---------------Execute Test ----------------------
            IRelationshipDef relDef = _loader.LoadRelationship(singleRelationshipStringComposition, _propDefs);

            //---------------Test Result -----------------------
            Assert.AreEqual(RelationshipType.Association, relDef.RelationshipType);
            Assert.AreEqual(InsertParentAction.InsertRelationship, relDef.InsertParentAction);
        }
Пример #11
0
        private static IRelationshipDef CreateReverseRelDef(IRelationshipDef rel, IClassDef classDef)
        {
            IRelationshipDef newReverseRelDef;

            if (rel.IsManyToOne)
            {
                newReverseRelDef = new MultipleRelationshipDef(rel.ReverseRelationshipName
                                                               , classDef.ClassType, new RelKeyDef(), true, ""
                                                               , DeleteParentAction.Prevent);
            }
            else
            {
                newReverseRelDef = new SingleRelationshipDef(rel.ReverseRelationshipName
                                                             , classDef.ClassType, new RelKeyDef(), true
                                                             , DeleteParentAction.DoNothing);
            }
            newReverseRelDef.ReverseRelationshipName = rel.RelationshipName;
            return(newReverseRelDef);
        }
Пример #12
0
        private void SetReverseRelationshipName(IRelationshipDef relDef)
        {
            IEnumerable <AutoMapManyToOneAttribute> attributes = this.PropertyWrapper.GetAttributes <AutoMapManyToOneAttribute>();
            AutoMapManyToOneAttribute mToOneAttribute          = attributes.FirstOrDefault();

            if (mToOneAttribute != null && !string.IsNullOrEmpty(mToOneAttribute.ReverseRelationshipName))
            {
                relDef.ReverseRelationshipName = mToOneAttribute.ReverseRelationshipName;
                return;
            }
            var reverseRelPropInfo = this.PropertyWrapper.GetMultipleReverseRelPropInfo();

            if (reverseRelPropInfo != null)
            {
                relDef.ReverseRelationshipName = reverseRelPropInfo.Name;
                return;
            }
            relDef.ReverseRelationshipName = StringUtilities.Pluralize(this.PropertyWrapper.DeclaringClassName);
        }
Пример #13
0
        public void TestRelationshipType_Multiple_Composition()
        {
            //---------------Set up test pack-------------------
            const string singleRelationshipStringComposition = @"
					<relationship 
						name=""TestRelationship"" 
						type=""multiple"" 
                        relationshipType=""Composition""
                        relatedClass=""Habanero.Test.BO.Loaders.TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>"                    ;
            //---------------Execute Test ----------------------
            IRelationshipDef relDef = _loader.LoadRelationship(singleRelationshipStringComposition, _propDefs);

            //---------------Test Result -----------------------
            Assert.AreEqual(RelationshipType.Composition, relDef.RelationshipType);
            //---------------Tear Down -------------------------
        }
Пример #14
0
        public void Test_ReverseRelationship()
        {
            //---------------Set up test pack-------------------
            const string singleRelationshipStringComposition = @"
					<relationship 
						name=""TestRelationship"" 
						type=""single"" 
                        relatedClass=""Habanero.Test.BO.Loaders.TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO""
                        owningBOHasForeignKey=""false""
                        reverseRelationship=""MyReverseRelationship""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>"                    ;
            //---------------Execute Test ----------------------
            IRelationshipDef relDef = _loader.LoadRelationship(singleRelationshipStringComposition, _propDefs);

            //---------------Test Result -----------------------
            Assert.AreEqual("MyReverseRelationship", relDef.ReverseRelationshipName);
        }
Пример #15
0
        private static Result ReverseRelationshipHasSameProps(IRelationshipDef relationshipDef, IRelationshipDef reverseRelationshipDef)
        {
            if (relationshipDef.RelKeyDef.Count != reverseRelationshipDef.RelKeyDef.Count)
            {
                return(new Result(false, "relationship KeyCount : " + relationshipDef.RelKeyDef.Count + " reverseRelationshpDef KeyCount : " + reverseRelationshipDef.RelKeyDef.Count));
            }
            foreach (var relPropDef in relationshipDef.RelKeyDef)
            {
                var localRelDef = relPropDef;
                var foundMatch  = reverseRelationshipDef.RelKeyDef.Any(reverseRelPropDef => reverseRelPropDef.DoKeyPropsMatch(localRelDef));

                if (!foundMatch)
                {
                    return(new Result(false, "- No matching RelProp found for " + relPropDef.OwnerPropertyName + " -> " + relPropDef.RelatedClassPropName
                                      + Environment.NewLine + "Relationship " + relationshipDef.RelationshipName + relationshipDef.GetRelPropDefString() +
                                      Environment.NewLine + "ReverseRelationship " + reverseRelationshipDef.RelationshipName + reverseRelationshipDef.GetRelPropDefString()));
                }
            }
            return(new Result(true, ""));
        }
Пример #16
0
        private void ValidateRelKeyDef
            (IClassDef classDef, ClassDefCol classDefs, IRelationshipDef relationshipDef, IClassDef relatedObjectClassDef,
            IDictionary <IClassDef, IPropDefCol> loadedFullPropertyLists)
        {
            var allPropsForClassDef        = GetAllClassDefProps(loadedFullPropertyLists, classDef, classDefs);
            var allPropsForRelatedClassDef = GetAllClassDefProps
                                                 (loadedFullPropertyLists, relatedObjectClassDef, classDefs);

            // Check Relationship Properties
            foreach (IRelPropDef relPropDef in relationshipDef.RelKeyDef)
            {
                string ownerPropertyName = relPropDef.OwnerPropertyName;
                if (!allPropsForClassDef.Contains(ownerPropertyName))
                {
                    throw new InvalidXmlDefinitionException
                              (String.Format
                                  ("In a 'relatedProperty' element for the '{0}' relationship of "
                                  + "the '{1}' class, the property '{2}' given in the "
                                  + "'property' attribute does not exist for the class or for any of it's superclasses. "
                                  + "Either add the property definition or check the spelling and "
                                  +
                                  "capitalisation of the specified property. Check in the ClassDefs.xml file or fix in Firestarter",
                                  relationshipDef.RelationshipName, classDef.ClassName, ownerPropertyName));
                }
                string relatedClassPropName = relPropDef.RelatedClassPropName;
                if (!allPropsForRelatedClassDef.Contains(relatedClassPropName))
                {
                    throw new InvalidXmlDefinitionException
                              (String.Format
                                  ("In a 'relatedProperty' element for the '{0}' relationship of "
                                  + "the '{1}' class, the property '{2}' given in the "
                                  +
                                  "'relatedProperty' attribute does not exist for the Related class '{3}' or for any of it's superclasses. "
                                  + "Either add the property definition or check the spelling and "
                                  +
                                  "capitalisation of the specified property. Check in the ClassDefs.xml file or fix in Firestarter",
                                  relationshipDef.RelationshipName, classDef.ClassName, relatedClassPropName,
                                  relatedObjectClassDef.ClassNameFull));
                }
            }
        }
Пример #17
0
        public void Test_Multiple_InsertAction_DoNothing()
        {
            //---------------Set up test pack-------------------
            const string singleRelationshipStringAssociation = @"
					<relationship 
						name=""TestRelationship"" 
						type=""multiple"" 
                        relatedClass=""Habanero.Test.BO.Loaders.TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO""
                        owningBOHasForeignKey=""false""
                        insertAction=""DoNothing""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>"                    ;
            //---------------Execute Test ----------------------
            IRelationshipDef relDef = _loader.LoadRelationship(singleRelationshipStringAssociation, _propDefs);

            //---------------Test Result -----------------------
            Assert.AreEqual(RelationshipType.Association, relDef.RelationshipType);
            Assert.AreEqual(InsertParentAction.DoNothing, relDef.InsertParentAction);
        }
Пример #18
0
        public void Test_Valid_Relationship_1_1_NoReverse_RelatatedProp_IsPartOfCompositePrimaryKey()
        {
            //----------------------Test Setup ----------------------
            const string classDefsString =
                @"
					<classes>

						<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestRelatedClassID"" type=""Guid"" />
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey isObjectID=""false"">
								<prop name=""TestRelatedClassID""/>
								<prop name=""TestClassID""/>
							</primaryKey>
							<relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"" 
											owningBOHasForeignKey=""true"" >
								<relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
							</relationship>
						</class>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
							<primaryKey>
								<prop name=""TestClassID""/>
							</primaryKey>
						</class>
					</classes>
			"            ;
            XmlClassDefsLoader loader          = CreateXmlClassDefsLoader();
            ClassDefCol        classDefList    = loader.LoadClassDefs(classDefsString);
            ClassDefValidator  validator       = new ClassDefValidator(GetDefClassFactory());
            IClassDef          reverseClassDef = classDefList.FindByClassName("TestRelatedClass");
            IRelationshipDef   relationshipDef = reverseClassDef.RelationshipDefCol["TestClass"];

            //---------------Assert PreConditions---------------
            Assert.IsTrue(relationshipDef.OwningBOHasForeignKey);
            //--------------------Execute Test-------------------------
            validator.ValidateClassDefs(classDefList);
            //---------------Test Result -----------------------
            Assert.IsTrue(relationshipDef.OwningBOHasForeignKey);
        }
Пример #19
0
        public void Test_Build_WithRelProp_ShouldCreateRelDefWithOneProp()
        {
            //---------------Set up test pack-------------------
            const string relationshipName = "Drivers";
            const string propertyName     = "VehicleID";
            const string relatedPropName  = "CarID";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var multipleRelationshipDef      = new RelationshipsBuilderStub <Car>().WithMultipleRelationship(c => c.Drivers).WithRelProp(propertyName, relatedPropName);
            IRelationshipDef relationshipDef = multipleRelationshipDef.Build();


            //---------------Test Result -----------------------
            Assert.AreEqual(relationshipName, relationshipDef.RelationshipName);
            Assert.AreEqual(1, relationshipDef.RelKeyDef.Count);
            IRelPropDef relPropDef = relationshipDef.RelKeyDef[propertyName];

            Assert.IsNotNull(relPropDef);
            Assert.AreEqual(propertyName, relPropDef.OwnerPropertyName);
            Assert.AreEqual(relatedPropName, relPropDef.RelatedClassPropName);
        }
Пример #20
0
        ///<summary>
        /// Creates a Reverse Relationship when required.
        ///</summary>
        ///<param name="classDefCol"></param>
        ///<param name="classDef"></param>
        ///<param name="relationship"></param>
        ///<returns></returns>
        public static IRelationshipDef CreateReverseRelationship(ClassDefCol classDefCol, IClassDef classDef, IRelationshipDef relationship)
        {
            IRelationshipDef rel = relationship;

            if (!ContainsRelatedClass(relationship, classDefCol))
            {
                return(null);
            }

            IClassDef relatedClassDef          = RelatedObjectClassDef(classDefCol, relationship);
            bool      foundReverseRelationship = relatedClassDef.RelationshipDefCol.Any(
                def => def.RelationshipName == rel.ReverseRelationshipName);

            if (foundReverseRelationship)
            {
                return(null);
            }

            IRelationshipDef newReverseRelDef = CreateReverseRelDef(rel, classDef);


            relatedClassDef.RelationshipDefCol.Add(newReverseRelDef);
            IRelPropDef relPropDef = relationship.RelKeyDef.FirstOrDefault();

            if (relPropDef != null)
            {
                var reverseRelPropDef = new RelPropDef(relPropDef.RelatedClassPropName, relPropDef.OwnerPropertyName);
                newReverseRelDef.RelKeyDef.Add(reverseRelPropDef);
                bool hasPropDef = relatedClassDef.PropDefColIncludingInheritance.Any(
                    propDef => propDef.PropertyName == reverseRelPropDef.OwnerPropertyName);
                if (!hasPropDef)
                {
                    var fkPropDef = new PropDef(reverseRelPropDef.OwnerPropertyName, typeof(Guid), PropReadWriteRule.ReadWrite, null);
                    relatedClassDef.PropDefcol.Add(fkPropDef);
                }
            }
            return(newReverseRelDef);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateRelProp()
        {
            //---------------Set up test pack-------------------
            Type           boWithM21          = typeof(FakeManyToOneBoRelNoFK);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];

            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();

            Assert.IsNotNull(relationshipDef);
            relationshipDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef relPropDef = relationshipDef.RelKeyDef.FirstOrDefault();

            Assert.IsNotNull(relPropDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];

            reverseRelDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef revereRelPropDef = reverseRelDef.RelKeyDef.FirstOrDefault();

            Assert.IsNotNull(revereRelPropDef, "ReverseRelationship ShouldHave Been Created");
            Assert.AreEqual(relPropDef.OwnerPropertyName, revereRelPropDef.RelatedClassPropName);
            Assert.AreEqual(relPropDef.RelatedClassPropName, revereRelPropDef.OwnerPropertyName);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateReverseRel()
        {
            //---------------Set up test pack-------------------
            Type           boWithM21          = typeof(FakeManyToOneBoRelNoFK);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];

            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();

            Assert.IsNotNull(relationshipDef);

            Assert.IsNotNullOrEmpty(relationshipDef.ReverseRelationshipName);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            cDefNoDefinedRel.RelationshipDefCol.ShouldHaveCount(1);

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];

            Assert.AreEqual(relationshipDef.ReverseRelationshipName, reverseRelDef.RelationshipName);
            Assert.AreEqual(relationshipDef.RelationshipName, reverseRelDef.ReverseRelationshipName);
            Assert.IsInstanceOf(typeof(MultipleRelationshipDef), reverseRelDef);
            Assert.AreEqual(RelationshipType.Association, reverseRelDef.RelationshipType);
            Assert.AreEqual(DeleteParentAction.Prevent, reverseRelDef.DeleteParentAction);
            Assert.IsFalse(reverseRelDef.OwningBOHasForeignKey);
        }
Пример #23
0
        [Test]  // Checks that deleting this instance has no effect in the related class
        public void Test_SingleRelationshipDeletion_DoNothing_Car()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Driver driver = TestUtilsDriver.CreateSavedDriver();

            TestProjectNoDBSpecificProps.BO.Car boForRelationshipCar = TestUtilsCar.CreateSavedCar();
            driver.Car = boForRelationshipCar;
            driver.Save();

            //---------------Assert Preconditions---------------
            IRelationshipDef relationshipDef = ClassDef.Get <Driver>().RelationshipDefCol["Car"];

            Assert.AreEqual(DeleteParentAction.DoNothing, relationshipDef.DeleteParentAction);
            //---------------Execute Test ----------------------
            driver.MarkForDelete();
            driver.Save();
            //---------------Execute Test ----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();

            try
            {
                Broker.GetBusinessObject <Driver>(driver.ID);
                Assert.Fail("BO should no longer exist and exception should be thrown");
            }
            catch (BusObjDeleteConcurrencyControlException ex)
            {
                StringAssert.Contains("There are no records in the database for the Class: Driver", ex.Message);
            }

            var relatedBO = Broker.GetBusinessObject <TestProjectNoDBSpecificProps.BO.Car>(boForRelationshipCar.ID);

            Assert.AreEqual(relatedBO.ID.ToString(), boForRelationshipCar.ID.ToString());
        }
Пример #24
0
        public void Test_IsCompulsory_WhenNotHasCompulsoryFKProps_ShouldReturnFalse()
        {
            FakeSingleRelationshipDef singleRelationshipDef = new FakeSingleRelationshipDef();
            var relKeyDef = new RelKeyDef();
            var propDef   = new PropDefFake {
                Compulsory = false
            };
            var relPropDef = new RelPropDef(propDef, "SomeThing");

            relKeyDef.Add(relPropDef);
            singleRelationshipDef.SetRelKeyDef(relKeyDef);
            singleRelationshipDef.OwningBOHasForeignKey = true;

            IRelationshipDef relationshipDef = singleRelationshipDef;

            //---------------Assert Precondition----------------
            Assert.IsFalse(propDef.Compulsory);
            Assert.IsTrue(singleRelationshipDef.OwningBOHasForeignKey);
            //---------------Execute Test ----------------------
            bool isCompulsory = relationshipDef.IsCompulsory;

            //---------------Test Result -----------------------
            Assert.IsFalse(isCompulsory);
        }
Пример #25
0
        private void AddChildIfNeeded(string childName, RelationshipCol relationshipCol)
        {
            IRelationshipDefCol relationshipDefCol = ClassDef.RelationshipDefCol;

            if (relationshipDefCol.Contains(childName))
            {
                IRelationshipDef relationshipDef = relationshipDefCol[childName];
#pragma warning disable 168
                IClassDef classDef = relationshipDef.RelatedObjectClassDef;
#pragma warning restore 168
                IMultipleRelationship relationship = (IMultipleRelationship)relationshipDef.CreateRelationship(this, this._boPropCol);
                //_mock.DynamicMock<IMultipleRelationship>();
                //(this, relationshipDef, this._boPropCol);
                //BusinessObjectCollection<BusinessObject> businessObjectCollection = new BusinessObjectCollection<BusinessObject>(classDef);
                //SetupResult.For(relationship.BusinessObjectCollection)
                //    .Return(businessObjectCollection);
                //SetupResult.For(relationship.RelationshipName)
                //    .Return(businessObjectCollection);

                //SetupResult.For(relationship.GetRelatedBusinessObjectCol<BusinessObject>())
                //    .Return(businessObjectCollection);
                relationshipCol.Add(relationship);
            }
        }
Пример #26
0
 /// <summary>
 /// Constrcutor for <see cref="MultipleRelationshipBase"/>
 /// </summary>
 /// <param name="owningBo">The <see cref="IBusinessObject"/> that owns this BO.</param>
 /// <param name="lRelDef">The <see cref="IRelationshipDef"/> that identifies  </param>
 /// <param name="lBOPropCol"></param>
 protected MultipleRelationshipBase(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
     : base(owningBo, lRelDef, lBOPropCol)
 {
 }
Пример #27
0
		/// <summary>
		/// Indicates whether the collection contains the relationship
		/// definition specified
		/// </summary>
		/// <param name="relationshipDef">The Relationship definition to search for</param>
		/// <returns>Returns true if found, false if not</returns>
		protected bool Contains(IRelationshipDef relationshipDef)
		{
            return _relDefs.ContainsKey(relationshipDef.RelationshipName);
		}
 /// <summary>
 /// Constructs the tester with the relationship under test.
 /// </summary>
 /// <param name="relationshipDef"></param>
 public MultipleRelDefTester(IRelationshipDef relationshipDef)
 {
     if (relationshipDef == null) throw new ArgumentNullException("relationshipDef");
     MultipleRelationshipDef = relationshipDef;
 }
Пример #29
0
        private bool HasRelDef(string propertyName)
        {
            IRelationshipDef relationshipDef = GetClassDef().GetRelationship(propertyName);

            return(relationshipDef != null);
        }
Пример #30
0
 private static bool HasReverseRelationship(IRelationshipDef relationshipDef)
 {
     return !string.IsNullOrEmpty(relationshipDef.ReverseRelationshipName);
 }
Пример #31
0
        private static Result ReverseRelationshipHasSameProps(IRelationshipDef relationshipDef, IRelationshipDef reverseRelationshipDef)
        {
            if (relationshipDef.RelKeyDef.Count != reverseRelationshipDef.RelKeyDef.Count) return new Result(false, "relationship KeyCount : " + relationshipDef.RelKeyDef.Count + " reverseRelationshpDef KeyCount : " + reverseRelationshipDef.RelKeyDef.Count);
            foreach (var relPropDef in relationshipDef.RelKeyDef)
            {
                var localRelDef = relPropDef;
                var foundMatch = reverseRelationshipDef.RelKeyDef.Any(reverseRelPropDef => reverseRelPropDef.DoKeyPropsMatch(localRelDef));

                if (!foundMatch) return new Result(false, "- No matching RelProp found for " + relPropDef.OwnerPropertyName + " -> " + relPropDef.RelatedClassPropName 
                        + Environment.NewLine + "Relationship " + relationshipDef.RelationshipName  + relationshipDef.GetRelPropDefString() +
                        Environment.NewLine + "ReverseRelationship " + reverseRelationshipDef.RelationshipName + reverseRelationshipDef.GetRelPropDefString());
            }
            return new Result(true, "");
        }
Пример #32
0
 private static string GetBaseRelationshipMessage(IRelationshipDef relationshipDef, IClassDef relatedClassDef, string reverseRelationshipName, IClassDef classDef)
 {
     return string.Format
         ("The relationship '{0}' could not be loaded because the reverse relationship '{1}' defined for the related class '{2}' and the relationship '{3}' defined for the class '{4}' " ,
          relationshipDef.RelationshipName, reverseRelationshipName, relatedClassDef.ClassNameFull,
          relationshipDef.RelationshipName, classDef.ClassNameFull);
 }
Пример #33
0
 private static bool HasReverseRelationship(IRelationshipDef relationshipDef)
 {
     return(!string.IsNullOrEmpty(relationshipDef.ReverseRelationshipName));
 }
 private  void SetReverseRelationshipName(IRelationshipDef relDef)
 {
     IEnumerable<AutoMapManyToOneAttribute> attributes = this.PropertyWrapper.GetAttributes<AutoMapManyToOneAttribute>();
     AutoMapManyToOneAttribute mToOneAttribute = attributes.FirstOrDefault();
     if (mToOneAttribute != null && !string.IsNullOrEmpty(mToOneAttribute.ReverseRelationshipName))
     {
         relDef.ReverseRelationshipName = mToOneAttribute.ReverseRelationshipName;
         return;
     }
     var reverseRelPropInfo = this.PropertyWrapper.GetMultipleReverseRelPropInfo();
     if (reverseRelPropInfo != null)
     {
         relDef.ReverseRelationshipName = reverseRelPropInfo.Name;
         return;
     }
     relDef.ReverseRelationshipName = StringUtilities.Pluralize(this.PropertyWrapper.DeclaringClassName);
 }
Пример #35
0
        /// <summary>
        /// Checks to see if the relationship and reverse relationship are defined for the same relationship.
        /// </summary>
        /// <param name="relationshipDef"></param>
        /// <param name="relatedClassDef"></param>
        /// <param name="reverseRelationshipName"></param>
        /// <param name="reverseRelationshipDef"></param>
        /// <param name="classDef"></param>
        private static void CheckReverseRelationshipRelKeyDefProps(IRelationshipDef relationshipDef, IClassDef relatedClassDef, string reverseRelationshipName, IRelationshipDef reverseRelationshipDef, IClassDef classDef)
        {
            var relationshipHasSameProps = ReverseRelationshipHasSameProps(relationshipDef, reverseRelationshipDef);

            if (!relationshipHasSameProps.Valid)
            {
                var baseMessage = GetBaseRelationshipMessage(relationshipDef, relatedClassDef, reverseRelationshipName,
                                                             classDef);
                string errorMessage = baseMessage + " do not have the same properties defined as the relationship keys " + relationshipHasSameProps.ErrorMessage;
                throw new InvalidXmlDefinitionException(errorMessage);
            }
        }
 private void SetRelationshipType(IRelationshipDef relDef)
 {
     var att = this.PropertyWrapper.GetAttribute<AutoMapManyToOneAttribute>();
     if (att != null) relDef.RelationshipType = att.RelationshipType;
 }
Пример #37
0
 private void CreateForeignKeyProp(IRelationshipDef relationshipDef)
 {
     var relationshipName = relationshipDef.RelationshipName;
     var propertyName = PropNamingConvention.GetSingleRelOwningPropName(relationshipName);
     var propDef = new PropDef(propertyName, typeof (Guid?), PropReadWriteRule.ReadWrite, null)
     {
         Compulsory = relationshipDef.IsCompulsory
     };
     SetDatabaseFieldName(propDef, relationshipName);
     this.ClassDef.PropDefcol.Add(propDef);
 }
 internal static void SetIsOneToOne(this IRelationshipDef singleRelationshipDef)
 {
     singleRelationshipDef.Stub(def => def.IsOneToOne).Return(true);
 }
Пример #39
0
 private void ValidateRelKeyDef
     (IClassDef classDef, ClassDefCol classDefs, IRelationshipDef relationshipDef, IClassDef relatedObjectClassDef,
      IDictionary<IClassDef, IPropDefCol> loadedFullPropertyLists)
 {
     var allPropsForClassDef = GetAllClassDefProps(loadedFullPropertyLists, classDef, classDefs);
     var allPropsForRelatedClassDef = GetAllClassDefProps
         (loadedFullPropertyLists, relatedObjectClassDef, classDefs);
     // Check Relationship Properties
     foreach (IRelPropDef relPropDef in relationshipDef.RelKeyDef)
     {
         string ownerPropertyName = relPropDef.OwnerPropertyName;
         if (!allPropsForClassDef.Contains(ownerPropertyName))
         {
             throw new InvalidXmlDefinitionException
                 (String.Format
                      ("In a 'relatedProperty' element for the '{0}' relationship of "
                       + "the '{1}' class, the property '{2}' given in the "
                       + "'property' attribute does not exist for the class or for any of it's superclasses. "
                       + "Either add the property definition or check the spelling and "
                       +
                       "capitalisation of the specified property. Check in the ClassDefs.xml file or fix in Firestarter",
                       relationshipDef.RelationshipName, classDef.ClassName, ownerPropertyName));
         }
         string relatedClassPropName = relPropDef.RelatedClassPropName;
         if (!allPropsForRelatedClassDef.Contains(relatedClassPropName))
         {
             throw new InvalidXmlDefinitionException
                 (String.Format
                      ("In a 'relatedProperty' element for the '{0}' relationship of "
                       + "the '{1}' class, the property '{2}' given in the "
                       +
                       "'relatedProperty' attribute does not exist for the Related class '{3}' or for any of it's superclasses. "
                       + "Either add the property definition or check the spelling and "
                       +
                       "capitalisation of the specified property. Check in the ClassDefs.xml file or fix in Firestarter",
                       relationshipDef.RelationshipName, classDef.ClassName, relatedClassPropName,
                       relatedObjectClassDef.ClassNameFull));
         }
     }
 }
Пример #40
0
        private static void ValidateReverseRelationship
            (IClassDef classDef, IRelationshipDef relationshipDef, IClassDef relatedClassDef)
        {

            if (!HasReverseRelationship(relationshipDef)) return;

            string reverseRelationshipName = relationshipDef.ReverseRelationshipName;
            if (!relatedClassDef.RelationshipDefCol.Contains(reverseRelationshipName))
            {
                throw new InvalidXmlDefinitionException
                    (string.Format
                         ("The relationship '{0}' could not be loaded for because the reverse relationship '{1}' defined for class '{2}' is not defined as a relationship for class '{2}'. Please check your ClassDefs.xml or fix in Firestarter.",
                          relationshipDef.RelationshipName, reverseRelationshipName, relatedClassDef.ClassNameFull));
            }

            var reverseRelationshipDef = relatedClassDef.RelationshipDefCol[reverseRelationshipName];
            CheckReverseRelationshipRelKeyDefProps(relationshipDef, relatedClassDef, reverseRelationshipName, reverseRelationshipDef, classDef);
            //            if (!reverseRelationshipDef.OwningBOHasForeignKey) return;
            //
            //            if (OwningClassHasPrimaryKey(reverseRelationshipDef, relatedClassDef))
            //            {
            //                reverseRelationshipDef.OwningBOHasForeignKey = false;
            //                return;
            //            }
            if (relationshipDef.OwningBOHasForeignKey && reverseRelationshipDef.OwningBOHasForeignKey)
            {
                var baseMessage = GetBaseRelationshipMessage(relationshipDef, relatedClassDef, reverseRelationshipName, classDef);
                string errorMessage = baseMessage + "are both set up as owningBOHasForeignKey = true. Please check your ClassDefs.xml or fix in Firestarter.";
                throw new InvalidXmlDefinitionException(errorMessage);
            }
        }
        ///<summary>
        /// Creates a Reverse Relationship when required.
        ///</summary>
        ///<param name="classDefCol"></param>
        ///<param name="classDef"></param>
        ///<param name="relationship"></param>
        ///<returns></returns>
        public static IRelationshipDef CreateReverseRelationship(ClassDefCol classDefCol, IClassDef classDef, IRelationshipDef relationship)
        {
            IRelationshipDef rel = relationship;
            if (!ContainsRelatedClass(relationship, classDefCol)) return null;

            IClassDef relatedClassDef = RelatedObjectClassDef(classDefCol, relationship);
            bool foundReverseRelationship = relatedClassDef.RelationshipDefCol.Any(
                def => def.RelationshipName == rel.ReverseRelationshipName);

            if (foundReverseRelationship) return null;

            IRelationshipDef newReverseRelDef = CreateReverseRelDef(rel, classDef);

            
            relatedClassDef.RelationshipDefCol.Add(newReverseRelDef);
            IRelPropDef relPropDef = relationship.RelKeyDef.FirstOrDefault();
            if (relPropDef != null)
            {
                var reverseRelPropDef = new RelPropDef(relPropDef.RelatedClassPropName, relPropDef.OwnerPropertyName);
                newReverseRelDef.RelKeyDef.Add(reverseRelPropDef);
                bool hasPropDef = relatedClassDef.PropDefColIncludingInheritance.Any(
                    propDef => propDef.PropertyName == reverseRelPropDef.OwnerPropertyName);
                if (!hasPropDef)
                {
                    var fkPropDef = new PropDef(reverseRelPropDef.OwnerPropertyName, typeof (Guid), PropReadWriteRule.ReadWrite, null);
                    relatedClassDef.PropDefcol.Add(fkPropDef);
                }
            }
            return newReverseRelDef;
        }
Пример #42
0
 /// <summary>
 /// Checks to see if the relationship and reverse relationship are defined for the same relationship.
 /// </summary>
 /// <param name="relationshipDef"></param>
 /// <param name="relatedClassDef"></param>
 /// <param name="reverseRelationshipName"></param>
 /// <param name="reverseRelationshipDef"></param>
 /// <param name="classDef"></param>
 private static void CheckReverseRelationshipRelKeyDefProps(IRelationshipDef relationshipDef, IClassDef relatedClassDef, string reverseRelationshipName, IRelationshipDef reverseRelationshipDef, IClassDef classDef)
 {
     var relationshipHasSameProps = ReverseRelationshipHasSameProps(relationshipDef, reverseRelationshipDef);
     if (!relationshipHasSameProps.Valid)
     {
         var baseMessage = GetBaseRelationshipMessage(relationshipDef, relatedClassDef, reverseRelationshipName,
                                                      classDef);
         string errorMessage = baseMessage + " do not have the same properties defined as the relationship keys " + relationshipHasSameProps.ErrorMessage;
         throw new InvalidXmlDefinitionException(errorMessage);
     }
 }
 private static IRelationshipDef CreateReverseRelDef(IRelationshipDef rel, IClassDef classDef)
 {
     IRelationshipDef newReverseRelDef;
     if (rel.IsManyToOne)
     {
         newReverseRelDef = new MultipleRelationshipDef(rel.ReverseRelationshipName
                                                        , classDef.ClassType, new RelKeyDef(), true, ""
                                                        , DeleteParentAction.Prevent);
     }else
     {
         newReverseRelDef = new SingleRelationshipDef(rel.ReverseRelationshipName
                                                      , classDef.ClassType, new RelKeyDef(), true
                                                      , DeleteParentAction.DoNothing);
     }
     newReverseRelDef.ReverseRelationshipName = rel.RelationshipName;
     return newReverseRelDef;
 }
Пример #44
0
 private static bool OwningClassHasPrimaryKey(IRelationshipDef relationshipDef, IClassDef classDef, ClassDefCol classDefCol)
 {
     //For each Property in the Relationship Key check if it is defined as the primary key for the
     //class if it is then check the other properties else this is not a primaryKey
     var primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(classDef, classDefCol);
     foreach (var relPropDef in relationshipDef.RelKeyDef)
     {
         var isInKeyDef = false;
         foreach (IPropDef propDef in primaryKeyDef)
         {
             if (propDef.PropertyName != relPropDef.OwnerPropertyName)
             {
                 isInKeyDef = false;
                 break;
             }
             isInKeyDef = true;
         }
         if (!isInKeyDef) return false;
     }
     return true;
 }
 private static bool ContainsRelatedClass(IRelationshipDef relationship, ClassDefCol classDefCol)
 {
     return classDefCol.Contains(relationship.RelatedObjectAssemblyName, relationship.RelatedObjectClassName);
 }
Пример #46
0
        private bool HasPropInfo(IRelationshipDef relationshipDef)
        {
            var propName = relationshipDef.RelationshipName;

            return(HasPropInfo(propName));
        }
 /// <summary>
 /// The <see cref="ClassDef"/> for the related object.
 /// </summary>
 private static IClassDef RelatedObjectClassDef(ClassDefCol classDefCol, IRelationshipDef relationshipDef)
 {
     return classDefCol[relationshipDef.RelatedObjectAssemblyName, relationshipDef.RelatedObjectClassNameWithTypeParameter];
    
 }
        private static void createRelationshipXml(XmlElement classDMElement, IRelationshipDef relationshipDef)
        {
            //IClassDef relatedClassDef = relationshipDef.RelatedObjectClassDef;//.MyRelatedClass.CurrentClass;
            //if (relatedClassDef == null) return;
            XmlElement relationshipDMElement = XmlUtilities.createXmlElement(classDMElement, "relationship");
            XmlUtilities.setXmlAttribute(relationshipDMElement, "name", relationshipDef.RelationshipName);
            bool isMultiple = false;
            //TODO Mark 28 Sep 2009: Review this and change it to use the IRelationshipDef interface methods or classes
            if (relationshipDef.IsManyToOne || relationshipDef.IsOneToOne)
                XmlUtilities.setXmlAttribute(relationshipDMElement, "type", "single");
            else if (relationshipDef.IsOneToMany)
            {
                XmlUtilities.setXmlAttribute(relationshipDMElement, "type", "multiple");
                isMultiple = true;
            }
            if (isMultiple)
            {
                XmlUtilities.setXmlAttribute(relationshipDMElement, "timeout", relationshipDef.TimeOut, 0);
            }
            XmlUtilities.setXmlAttribute(relationshipDMElement, "relatedClass", relationshipDef.RelatedObjectClassName);
            XmlUtilities.setXmlAttribute(relationshipDMElement, "reverseRelationship", relationshipDef.ReverseRelationshipName);
            XmlUtilities.setXmlAttribute(relationshipDMElement, "relatedAssembly", relationshipDef.RelatedObjectAssemblyName);
            XmlUtilities.setXmlAttribute(relationshipDMElement, "keepReference", relationshipDef.KeepReferenceToRelatedObject, true);
            XmlUtilities.setXmlAttribute(relationshipDMElement, "deleteAction", relationshipDef.DeleteParentAction, DeleteParentAction.Prevent);
            XmlUtilities.setXmlAttribute(relationshipDMElement, "relationshipType", relationshipDef.RelationshipType, RelationshipType.Association);
            // XmlUtilities.setXmlAttribute(relationshipDMElement, "relationshipDescription", relationshipDef.);
            if (isMultiple)
            {
                XmlUtilities.setXmlAttribute(relationshipDMElement, "orderBy", relationshipDef.OrderCriteriaString);
            }
            else
            {
                XmlUtilities.setXmlAttribute(relationshipDMElement, "owningBOHasForeignKey", relationshipDef.OwningBOHasForeignKey, true);
            }

            foreach (IRelPropDef relPropDef in relationshipDef.RelKeyDef)
            {
                if (relPropDef.OwnerPropertyName != null && relPropDef.RelatedClassPropName != null)
                {
                    XmlElement relPropElement = XmlUtilities.createXmlElement(relationshipDMElement, "relatedProperty");
                    XmlUtilities.setXmlAttribute(relPropElement, "property", relPropDef.OwnerPropertyName);
                    XmlUtilities.setXmlAttribute(relPropElement, "relatedProperty", relPropDef.RelatedClassPropName);
                }
            }
            classDMElement.AppendChild(relationshipDMElement);
        }
 protected static void ValidateRelationshipDef(Type type, IRelationshipDef def, string relationshipName)
 {
     if (def == null)
     {
         throw new HabaneroDeveloperException(
             string.Format("The relationship '{0}' for the ClassDef for '{1}' is not defined", relationshipName,
                           type), DEVELOPER_MESSAGE);
     }
 }
Пример #50
0
 private bool HasPropInfo(IRelationshipDef relationshipDef)
 {
     var propName = relationshipDef.RelationshipName;
     return HasPropInfo(propName);
 }
Пример #51
0
 private static IClassDef GetRelatedObjectClassDef(ClassDefCol classDefs, IRelationshipDef relationshipDef)
 {
     IClassDef relatedObjectClassDef;
     try
     {
         relatedObjectClassDef =
             classDefs[relationshipDef.RelatedObjectAssemblyName, relationshipDef.RelatedObjectClassNameWithTypeParameter];
     }
     catch (HabaneroDeveloperException)
     {
         try
         {
             relatedObjectClassDef =
                 ClassDef.ClassDefs[relationshipDef.RelatedObjectAssemblyName, relationshipDef.RelatedObjectClassNameWithTypeParameter];
         }
         catch (HabaneroDeveloperException ex)
         {
             throw new InvalidXmlDefinitionException
                 (string.Format
                      ("The relationship '{0}' could not be loaded because when trying to retrieve its related class the folllowing error was thrown '{1}'",
                       relationshipDef.RelationshipName, ex.Message), ex);
         }
     }
     return relatedObjectClassDef;
 }
Пример #52
0
		/// <summary>
		/// Constructor to initialise a new relationship
		/// </summary>
		/// <param name="owningBo">The business object from where the 
		/// relationship originates</param>
		/// <param name="lRelDef">The relationship definition</param>
		/// <param name="lBOPropCol">The set of properties used to
		/// initialise the RelKey object</param>
		protected Relationship(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
		{
			if (owningBo == null) throw new ArgumentNullException("owningBo");
			if (lRelDef == null) throw new ArgumentNullException("lRelDef");
			if (lBOPropCol == null) throw new ArgumentNullException("lBOPropCol");
			_relDef = lRelDef;
			_owningBo = owningBo;
			_relKey = new Lazy<IRelKey>(() => _relDef.RelKeyDef.CreateRelKey(lBOPropCol));
		}
 internal static void SetIsNotManyToOne(this IRelationshipDef singleRelationshipDef)
 {
     singleRelationshipDef.Stub(def => def.IsManyToOne).Return(false);
 }