Ejemplo n.º 1
0
        public void TestColIsInstantiatedButNotLoaded()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            OrganisationTestBO.LoadDefaultClassDef();
            IClassDef contactPersonClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            RelKeyDef keyDef = new RelKeyDef();

            keyDef.Add(new RelPropDef(contactPersonClassDef.PropDefcol["OrganisationID"], "OrganisationID"));
            MultipleRelationshipDef def = new MultipleRelationshipDef
                                              (TestUtil.GetRandomString(), typeof(ContactPersonTestBO),
                                              keyDef, false, "", DeleteParentAction.DoNothing);

            OrganisationTestBO organisation = new OrganisationTestBO();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IMultipleRelationship rel = (IMultipleRelationship)def.CreateRelationship(organisation, organisation.Props);

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

            IBusinessObjectCollection collection = rel.BusinessObjectCollection;

            Assert.IsNotNull(collection);
            Assert.AreEqual(0, collection.Count);
            Assert.AreSame(contactPersonClassDef, collection.ClassDef);
            Assert.IsNotNull(collection.SelectQuery.Criteria);
            Assert.IsNotNull(collection.SelectQuery.Criteria.Field);
            Assert.AreEqual("OrganisationID", collection.SelectQuery.Criteria.Field.PropertyName);
            Assert.IsNotNull(collection.SelectQuery.Criteria.Field.Source);
            Assert.AreEqual("ContactPersonTestBO", collection.SelectQuery.Criteria.Field.Source.Name);
            Assert.AreEqual(organisation.OrganisationID.Value, collection.SelectQuery.Criteria.FieldValue);
            Assert.IsInstanceOf(typeof(ContactPersonTestBO), collection.CreateBusinessObject());
        }
Ejemplo n.º 2
0
        public void Test_CreateMultipleRelationshipDef_Association()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO.LoadDefaultClassDef();
            RelPropDef relPropDef = new RelPropDef(ClassDef.Get <OrganisationTestBO>().PropDefcol["OrganisationID"], "OrganisationID");
            RelKeyDef  relKeyDef  = new RelKeyDef();

            relKeyDef.Add(relPropDef);
            const int expectedTimeout = 550;
            MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO",
                                                                                  "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Association, expectedTimeout);
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedTimeout, relationshipDef.TimeOut);
            //---------------Execute Test ----------------------
            MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)relationshipDef.CreateRelationship(organisation, organisation.Props);

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTimeout, relationship.TimeOut);
            Assert.AreEqual(InsertParentAction.InsertRelationship, relationship.RelationshipDef.InsertParentAction);
        }
Ejemplo n.º 3
0
        //Relationship
        //-- should this reference the reverse relationship if exists
        //  (i.e. bidirectional navigatable relationship).

        //--

        /// <summary>
        /// Adds a business object to the collection
        /// </summary>
        /// <param name="bo">The business object to add</param>
        protected override bool AddInternal(TBusinessObject bo)
        {
            var boColInternal = ((IBusinessObjectCollectionInternal)this);

            if (!boColInternal.Loading)
            {
                if (!this._relationship.RelKey.Criteria.IsMatch(bo, false))
                {
                    MultipleRelationshipDef def = this._relationship.RelationshipDef as MultipleRelationshipDef;
                    if (def != null)
                    {
                        def.CheckCanAddChild(bo);
                    }
                }
            }
            if (!base.AddInternal(bo))
            {
                return(false);
            }
            if (boColInternal.Loading)
            {
                return(true);
            }

            if (IsForeignKeySetup(bo))
            {
                return(true);
            }

            SetUpForeignKey(bo);
            SetupRelatedObject(bo);
            return(true);
        }
Ejemplo n.º 4
0
        public static IClassDef LoadDefaultClassDef_NoReverseRelationship()
        {
            XmlClassLoader itsLoader   = CreateXmlClassLoader();
            IClassDef      itsClassDef =
                itsLoader.LoadClass(
                    @"
				<class name=""OrganisationTestBO"" assembly=""Habanero.Test.BO"" table=""organisation"">
					<property  name=""OrganisationID"" type=""Guid"" />
                    <property name=""Name"" />
					<primaryKey>
						<prop name=""OrganisationID"" />
					</primaryKey>
			    </class>
			"            );
            RelPropDef relPropDef = new RelPropDef(itsClassDef.PropDefcol["OrganisationID"], "OrganisationID");
            RelKeyDef  relKeyDef  = new RelKeyDef();

            relKeyDef.Add(relPropDef);
            MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO",
                                                                                  "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 0);

            itsClassDef.RelationshipDefCol.Add(relationshipDef);
            ClassDef.ClassDefs.Add(itsClassDef);
            return(itsClassDef);
        }
Ejemplo n.º 5
0
        protected static RelationshipDefCol CreateRelationshipDefCol(PropDefCol lPropDefCol)
        {
            RelationshipDefCol relDefCol = new RelationshipDefCol();


            //Define Driver Relationships
            RelKeyDef relKeyDef = new RelKeyDef();
            IPropDef  propDef   = lPropDefCol[PK1_PROP1_NAME];

            RelPropDef lRelPropDef = new RelPropDef(propDef, "DriverFK1");

            relKeyDef.Add(lRelPropDef);

            propDef = lPropDefCol[PK1_PROP2_NAME];

            lRelPropDef = new RelPropDef(propDef, "DriverFK2");
            relKeyDef.Add(lRelPropDef);

            RelationshipDef relDef = new MultipleRelationshipDef("Driver",
                                                                 typeof(Car), relKeyDef, true, "",
                                                                 DeleteParentAction.DereferenceRelated);

            relDefCol.Add(relDef);
            return(relDefCol);
        }
Ejemplo n.º 6
0
        private static RelationshipDefCol CreateRelationshipDefCol(IPropDefCol lPropDefCol)
        {
            RelationshipDefCol relDefCol = new RelationshipDefCol();

            //Define Owner Relationships
            RelKeyDef  relKeyDef;
            IPropDef   propDef;
            RelPropDef lRelPropDef;

            relKeyDef   = new RelKeyDef();
            propDef     = lPropDefCol["ContactPersonID"];
            lRelPropDef = new RelPropDef(propDef, "OwnerId");
            relKeyDef.Add(lRelPropDef);

            //RelationshipDef relDef1 = new MultipleRelationshipDef("Owner", typeof(Car),
            //                         relKeyDef, false, "",
            //                         DeleteParentAction.DereferenceRelated);
            RelationshipDef relDef2 = new MultipleRelationshipDef("Cars", typeof(Car),
                                                                  relKeyDef, false, "Engine.EngineNo",
                                                                  DeleteParentAction.DereferenceRelated);

            //relDefCol.Add(relDef1);
            relDefCol.Add(relDef2);
            relKeyDef = new RelKeyDef();
            // propDef = lPropDefCol["ContactPersonID"];
            lRelPropDef = new RelPropDef(propDef, "ContactPersonID");
            relKeyDef.Add(lRelPropDef);
            RelationshipDef relDef3 = new MultipleRelationshipDef("Addresses", typeof(Address),
                                                                  relKeyDef, false, "",
                                                                  DeleteParentAction.DeleteRelated);

            relDefCol.Add(relDef3);

            return(relDefCol);
        }
Ejemplo n.º 7
0
        public void TestOwningBOHasForeignKey_Multiple_Default()
        {
            //---------------Execute Test ----------------------
            MultipleRelationshipDef relDef = new MultipleRelationshipDef
                                                 ("rel", typeof(MyRelatedBo), new RelKeyDef(), true, "", DeleteParentAction.Prevent);

            //---------------Test Result -----------------------
            Assert.IsFalse(relDef.OwningBOHasForeignKey);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 8
0
        public void Test_IsCompulsory_AlwaysTrueForMultiple()
        {
            //---------------Set up test pack-------------------
            MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef(TestUtil.GetRandomString(),
                                                                                  TestUtil.GetRandomString(), TestUtil.GetRandomString(), new RelKeyDef(), false, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 10000);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var isCompulsory = relationshipDef.IsCompulsory;

            //---------------Test Result -----------------------
            Assert.IsFalse(isCompulsory);
        }
Ejemplo n.º 9
0
        public void Test_CreateMultipleRelationshipDef_Composition()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef(TestUtil.GetRandomString(),
                                                                                  TestUtil.GetRandomString(), TestUtil.GetRandomString(), new RelKeyDef(), false, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 10000);

            //---------------Test Result -----------------------
            Assert.AreEqual(RelationshipType.Composition, relationshipDef.RelationshipType);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Removes the specified business object from the collection
        /// </summary>
        /// <param name="bo">The business object to remove</param>
        public override bool Remove(TBusinessObject bo)
        {
            MultipleRelationshipDef def = this._relationship.RelationshipDef as MultipleRelationshipDef;
            var boColInternal           = ((IBusinessObjectCollectionInternal)this);

            if (!bo.Status.IsNew && def != null && !boColInternal.Loading && (def.RelationshipType == RelationshipType.Composition))
            {
                string message = "The " + def.RelatedObjectClassName +
                                 " could not be removed since the " + def.RelationshipName +
                                 " relationship is set up as a composition relationship (RemoveChildAction.Prevent)";
                throw new HabaneroDeveloperException(message, message);
            }
            return(RemoveInternal(bo));
        }
Ejemplo n.º 11
0
        public void AddPreventDeleteRelationship()
        {
            RelKeyDef  relKeyDef   = new RelKeyDef();
            RelPropDef lRelPropDef = new RelPropDef(ClassDef.PropDefcol["ContactPersonID"], "ContactPersonID");

            relKeyDef.Add(lRelPropDef);
            RelationshipDef relDef = new MultipleRelationshipDef("AddressesNoDelete", typeof(Address),
                                                                 relKeyDef, false, "", DeleteParentAction.Prevent);

            ClassDef.RelationshipDefCol = new RelationshipDefCol();
            ClassDef.RelationshipDefCol.Add(relDef);

            Relationships.Add(new MultipleRelationship <Address>(this, relDef, Props));
        }
Ejemplo n.º 12
0
        public void TestConstruct_WithTimeout_ShouldSetUpTimeout()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            const int expectedTimout       = 10000;
            MultipleRelationshipDef relDef = new MultipleRelationshipDef
                                                 ("rel", "", "", new RelKeyDef(), true, "", DeleteParentAction.Prevent, InsertParentAction.DoNothing, RelationshipType.Association,
                                                 expectedTimout);

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTimout, relDef.TimeOut);
        }
Ejemplo n.º 13
0
        public static ClassDef CreateClassDefWithShapeRelationship()
        {
            PropDefCol lPropDefCol = CreateBOPropDef();

            KeyDef lKeyDef = new KeyDef();

            lKeyDef.IgnoreIfNull = true;
            lKeyDef.Add(lPropDefCol["PK2Prop1"]);
            lKeyDef.Add(lPropDefCol["PK2Prop2"]);
            KeyDefCol keysCol = new KeyDefCol();

            keysCol.Add(lKeyDef);

            lKeyDef = new KeyDef();
            lKeyDef.IgnoreIfNull = false;

            lKeyDef.Add(lPropDefCol["PK3Prop"]);
            keysCol.Add(lKeyDef);

            PrimaryKeyDef primaryKey = new PrimaryKeyDef();

            primaryKey.IsGuidObjectID = true;
            primaryKey.Add(lPropDefCol["ContactPersonID"]);


            //Releationships
            RelationshipDefCol relDefs = new RelationshipDefCol();

            RelKeyDef  relKeyDef   = new RelKeyDef();
            IPropDef   propDef     = lPropDefCol["ContactPersonID"];
            RelPropDef lRelPropDef = new RelPropDef(propDef, "OwnerId");

            relKeyDef.Add(lRelPropDef);

            RelationshipDef relDef = new MultipleRelationshipDef("Shapes", typeof(Shape),
                                                                 relKeyDef, false, "",
                                                                 DeleteParentAction.DereferenceRelated);

            //relDefCol.Add(relDef1);
            relDefs.Add(relDef);

            ClassDef lClassDef = new ClassDef(typeof(ContactPerson), primaryKey, "contact_person", lPropDefCol, keysCol, relDefs);

            ClassDef.ClassDefs.Add(lClassDef);
            return(lClassDef);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Map the relationship including the Relationship props.
        /// </summary>
        /// <returns></returns>
        public IRelationshipDef MapOneToMany()
        {
            var propertyType = this.PropertyWrapper.PropertyType;

            if (!MustBeMapped())
            {
                return(null);
            }

            var singleReverseRelPropInfos = this.PropertyWrapper.GetSingleReverseRelPropInfos();

            if (singleReverseRelPropInfos.Count > 1)
            {
                throw new InvalidDefinitionException("The Relationship '" + this.PropertyWrapper.Name
                                                     + "' could not be automapped since there are multiple Single relationships on class '"
                                                     + this.PropertyWrapper.RelatedClassType + "' that reference the BusinessObject Class '"
                                                     + this.PropertyWrapper.DeclaringClassName + "'. Please map using ClassDef.XML or Attributes");
            }
            var relationshipAttribute = this.PropertyWrapper.GetAttribute <AutoMapOneToManyAttribute>();
            MultipleRelationshipDef relDef;

            if (propertyType.IsGenericType)
            {
                var relatedClassType = this.PropertyWrapper.RelatedClassType.UnderlyingType;
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, relatedClassType, new RelKeyDef(), true, "", DeleteParentAction.Prevent);
            }
            else
            {
                string className = StringUtilities.Singularize(this.PropertyWrapper.Name);
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, this.PropertyWrapper.AssemblyQualifiedName, className
                                                     , new RelKeyDef(), true, "", DeleteParentAction.Prevent);
            }
            if (relationshipAttribute != null)
            {
                relDef.RelationshipType = relationshipAttribute.RelationshipType;
                DeleteParentAction deleteParentAction = relationshipAttribute.DeleteParentAction;
                relDef.DeleteParentAction = deleteParentAction;
            }
            relDef.ReverseRelationshipName = GetReverseRelationshipName();

            var relPropDef = CreateRelPropDef();

            relDef.RelKeyDef.Add(relPropDef);
            return(relDef);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void Test_CheckCanAdd_NullObject()
        {
            //---------------Set up test pack-------------------
            MultipleRelationshipDef relDef = new MultipleRelationshipDef
                                                 ("rel", typeof(MyRelatedBo), new RelKeyDef(), true, "", DeleteParentAction.Prevent);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                relDef.CheckCanAddChild(null);
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("could not be added since the  business object is null", ex.Message);
            }
            //---------------Test Result -----------------------
        }
Ejemplo n.º 17
0
        /// <summary>
        /// A method for removing the busines object without doing any checks for relationship type.
        /// This is needed for cases where a parent business object that has created composite children has
        /// <see cref="IBusinessObject.CancelEdits"/> called. The parent business objects should
        /// then cancel all its children
        /// </summary>
        /// <param name="bo">The child business object that needs to be removed from the collection.</param>
        /// <returns>true if the business object is removed, otherwise false.</returns>
        internal bool RemoveInternal(TBusinessObject bo)
        {
            var boColInternal = ((IBusinessObjectCollectionInternal)this);

            if (!base.Remove(bo))
            {
                return(false);
            }
            if (boColInternal.Loading)
            {
                return(true);
            }
            DereferenceBO(bo);
            MultipleRelationshipDef def = this._relationship.RelationshipDef as MultipleRelationshipDef;

            if (!(!bo.Status.IsNew && def != null && !boColInternal.Loading && (def.RelationshipType == RelationshipType.Composition)))
            {
                RemoveRelatedObject(bo);
            }
            return(true);
        }
Ejemplo n.º 18
0
        private static ClassDef CreateClassDef(long number, bool hasSingleRelationship,
                                               bool hasMultipleRelationship, bool hasMultipleRelationshipWithPreventDelete)
        {
            const string  assemblyName   = "Habanero.Test.BO";
            const string  className      = "TestBO";
            const string  idPropName     = "MyBoID";
            const string  fkPropertyName = "MyParentBoID";
            string        suffix         = number.ToString();
            PropDefCol    propDefCol     = new PropDefCol();
            PrimaryKeyDef primaryKeyDef  = new PrimaryKeyDef();

            primaryKeyDef.IsGuidObjectID = false;
            RelationshipDefCol relationshipDefCol = new RelationshipDefCol();
            PropDef            idPropDef          = new PropDef(idPropName, typeof(string), PropReadWriteRule.ReadWrite, "");

            propDefCol.Add(idPropDef);
            primaryKeyDef.Add(idPropDef);
            //propDef = new PropDef("MyProp", typeof(string), PropReadWriteRule.ReadWrite, "" );
            //propDefCol.Add(propDef);
            PropDef propDef = new PropDef(fkPropertyName, typeof(string), PropReadWriteRule.ReadWrite, "");

            propDefCol.Add(propDef);
            if (hasSingleRelationship)
            {
                string     relatedClassSuffix = (number - 1).ToString();
                RelKeyDef  relKeyDef          = new RelKeyDef();
                RelPropDef relPropDef         = new RelPropDef(propDef, idPropName);
                relKeyDef.Add(relPropDef);
                SingleRelationshipDef singleRelationshipDef = new SingleRelationshipDef(
                    "MyParent", assemblyName,
                    className + relatedClassSuffix, relKeyDef, false, DeleteParentAction.Prevent);
                relationshipDefCol.Add(singleRelationshipDef);
            }
            if (hasMultipleRelationship)
            {
                string     relatedClassSuffix = (number + 1).ToString();
                RelKeyDef  relKeyDef          = new RelKeyDef();
                RelPropDef relPropDef         = new RelPropDef(idPropDef, fkPropertyName);
                relKeyDef.Add(relPropDef);
                MultipleRelationshipDef multipleRelationshipDef =
                    new MultipleRelationshipDef("MyBO" + relatedClassSuffix,
                                                assemblyName, className + relatedClassSuffix, relKeyDef, false,
                                                "", DeleteParentAction.DeleteRelated);
                relationshipDefCol.Add(multipleRelationshipDef);
            }
            if (hasMultipleRelationshipWithPreventDelete)
            {
                string     relatedClassSuffix = (number + 1).ToString();
                RelKeyDef  relKeyDef          = new RelKeyDef();
                RelPropDef relPropDef         = new RelPropDef(idPropDef, fkPropertyName);
                relKeyDef.Add(relPropDef);
                MultipleRelationshipDef multipleRelationshipDef =
                    new MultipleRelationshipDef("MyPreventBO" + relatedClassSuffix,
                                                assemblyName, className + relatedClassSuffix, relKeyDef, false,
                                                "", DeleteParentAction.Prevent);
                relationshipDefCol.Add(multipleRelationshipDef);
            }
            ClassDef classDef = new ClassDef(assemblyName, className + suffix,
                                             primaryKeyDef, propDefCol, new KeyDefCol(), relationshipDefCol, new UIDefCol());

            return(classDef);
        }
Ejemplo n.º 19
0
 private static bool PreventDeleteRelationshipCondition(MultipleRelationshipDef multipleRelationshipDef)
 {
     return(multipleRelationshipDef.DeleteParentAction == DeleteParentAction.Prevent);
 }