示例#1
0
        internal void SetRelatedObjectInternal(TBusinessObject relatedObject, bool isInternalAdd)
        {
            if (_relatedBo == null)
            {
                GetRelatedObject(isInternalAdd);
            }
            if (_relatedBo == relatedObject)
            {
                return;
            }

            if (relatedObject != null)
            {
                RelationshipDef.CheckCanAddChild(relatedObject);
            }
            if (_relatedBo != null)
            {
                RelationshipDef.CheckCanRemoveChild(_relatedBo);
            }

            RemoveFromReverseRelationship(_relatedBo);

            SetRelatedBoReferenceInternal(relatedObject);

            AddToReverseRelationship(relatedObject, isInternalAdd);

            UpdateForeignKeyAndStoredRelationshipExpression();

            FireUpdatedEvent();
        }
        public virtual void Test_RemovedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef    relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();

            contactPerson.Surname = TestUtil.GetRandomString();
            organisationTestBO.ContactPeople.Remove(contactPerson);

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsTrue(organisationTestBO.Status.IsDirty);

            //---------------Execute Test ----------------------
            organisationTestBO.Save();

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsFalse(organisationTestBO.Status.IsDirty);
        }
        public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_DoesReloadFromDB()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO        organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef           relationshipDef    = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"];
            IMultipleRelationship     rel        = new MultipleRelationship <ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 0);
            IBusinessObjectCollection collection = rel.BusinessObjectCollection;
            DateTime?initialTimeLastLoaded       = collection.TimeLastLoaded;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(collection.TimeLastLoaded);
            Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded);
            MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)organisationTestBO.Relationships["ContactPeople"];

            Assert.AreEqual(0, relationship.TimeOut);
            //---------------Execute Test ----------------------
            ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();
            TestUtil.Wait(100);
            IBusinessObjectCollection secondCollectionCall = rel.BusinessObjectCollection;

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.IsNotNull(secondCollectionCall.TimeLastLoaded);
            Assert.AreEqual(1, secondCollectionCall.Count);
            Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
        private void CheckBusinessObjectCollectionCorrectType(IBusinessObjectCollection newBusinessObjectCollection)
        {
            if (_singleRelationship == null)
            {
                return;
            }

            RelationshipDef relationshipDef = (RelationshipDef)_singleRelationship.RelationshipDef;

            if (newBusinessObjectCollection != null &&
                relationshipDef.RelatedObjectClassType != newBusinessObjectCollection.ClassDef.ClassType)
            {
                string errorMessage = string.Format
                                          ("You cannot set the Business Object Collection to the '{0}' "
                                          + "since it is not of the appropriate type ('{1}') for this '{2}'",
                                          newBusinessObjectCollection.ClassDef.ClassNameFull,
                                          relationshipDef.RelatedObjectClassName, this.GetType().FullName);
                throw new HabaneroDeveloperException(errorMessage, errorMessage);
            }
            //if (_relationshipDef == null) return;

            //if (newBusinessObjectCollection != null && _relationshipDef.RelatedObjectClassType != newBusinessObjectCollection.ClassDef.ClassType)
            //{
            //    string errorMessage = string.Format
            //        ("You cannot set the Business Object Collection to the '{0}' "
            //         + "since it is not of the appropriate type ('{1}') for this '{2}'", newBusinessObjectCollection.ClassDef.ClassNameFull,
            //         _relationshipDef.RelatedObjectClassName, this.GetType().FullName);
            //    throw new HabaneroDeveloperException(errorMessage, errorMessage);
            //}
        }
示例#5
0
        public void TestWithUnknownRelatedType()
        {
            //---------------Set up test pack-------------------
            DefClassFactory       defClassFactory = new DefClassFactory();
            XmlRelationshipLoader loader          = new XmlRelationshipLoader(new DtdLoader(), defClassFactory, "TestClass");
            IPropDefCol           propDefs        = defClassFactory.CreatePropDefCol();

            propDefs.Add(defClassFactory.CreatePropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));

            RelationshipDef relDef =
                (RelationshipDef)loader.LoadRelationship(
                    @"<relationship 
						name=""TestRelationship"" 
						type=""single"" 
						relatedClass=""Habanero.Test.BO.Loaders.NonExistantTestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO"" 
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />

					</relationship>"                    ,
                    propDefs);

            //---------------Execute Test ----------------------
            try
            {
                Type classType = relDef.RelatedObjectClassType;

                Assert.Fail("Expected to throw an UnknownTypeNameException");
            }
            //---------------Test Result -----------------------
            catch (UnknownTypeNameException ex)
            {
                StringAssert.Contains("Unable to load the related object type while attempting to load a relationship definition", ex.Message);
            }
        }
        public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_UsingRelationship_DoesResetTheTimeLastLoaded()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef    relationshipDef    = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"];
            //IMultipleRelationship rel = new MultipleRelationship<ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 0);
            IBusinessObjectCollection collection = organisationTestBO.ContactPeople;
            DateTime?initialTimeLastLoaded       = collection.TimeLastLoaded;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(collection.TimeLastLoaded);
            Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded);
            //---------------Execute Test ----------------------
            TestUtil.Wait(100);
            IBusinessObjectCollection secondCollectionCall = organisationTestBO.ContactPeople;

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.IsNotNull(secondCollectionCall.TimeLastLoaded);
            Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
        public void Test_ResetParent_NewChild_SetToNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            contactPerson.Organisation = organisation;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(contactPerson.Organisation);

            //---------------Execute Test ----------------------
            //try
            //{
            contactPerson.Organisation = null;
            //    Assert.Fail("expected Err");
            //}
            //---------------Test Result -----------------------
            //catch (HabaneroDeveloperException ex)
            //{
            //    StringAssert.Contains
            //        ("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
            //    StringAssert.Contains
            //        ("could not be removed since the " + compositionRelationship.RelationshipName
            //         + " relationship is set up as ", ex.Message);
            //}
            Assert.IsNull(contactPerson.Organisation);
        }
示例#8
0
 /// <summary>
 /// Constructor for a new initialiser
 /// </summary>
 /// <param name="parentObject">The parent for the relationship</param>
 /// <param name="relationship">The relationship object</param>
 /// <param name="correspondingRelationshipName">The corresponding
 /// relationship name</param>
 public RelationshipObjectInitialiser(IBusinessObject parentObject, RelationshipDef relationship,
                                      string correspondingRelationshipName)
 {
     _parentObject = parentObject;
     _relationship = relationship;
     _correspondingRelationshipName = correspondingRelationshipName;
 }
        public void Test_RemoveMethod()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            compositionRelationship.SetRelatedObject(contactPerson);

            //---------------Assert Precondition----------------
            Assert.AreEqual(contactPerson.OrganisationID, organisation.OrganisationID);
            Assert.AreSame(organisation.ContactPerson, contactPerson);
            Assert.AreEqual(RelationshipType.Composition, compositionRelationship.RelationshipDef.RelationshipType);

            //---------------Execute Test ----------------------
            //try
            //{
            compositionRelationship.SetRelatedObject(null);
            //    Assert.Fail("expected Err");
            //}
            ////---------------Test Result -----------------------
            //catch (HabaneroDeveloperException ex)
            //{
            //    StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
            //    StringAssert.Contains("could not be removed since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            //}
            Assert.IsNull(compositionRelationship.GetRelatedObject());
        }
        public void Test_AddedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves_OnlyIDChanged()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = ContactPersonTestBO.CreateSavedContactPerson();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            organisationTestBO.ContactPeople.Add(contactPerson);

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsTrue(organisationTestBO.Status.IsDirty);

            //---------------Execute Test ----------------------
            organisationTestBO.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsFalse(organisationTestBO.Status.IsDirty);

            //---------------Tear Down -------------------------
        }
        public virtual void Test_AddDirtyChildrenToTransactionCommitter_AddedChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            relationship.BusinessObjectCollection.Add(contactPerson);
            SingleRelationship <OrganisationTestBO> reverseRelationship =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");


            TransactionCommitter tc = (TransactionCommitter)BORegistry.DataAccessor.CreateTransactionCommitter();

            //---------------Assert PreConditions---------------
            Assert.AreEqual(0, tc.OriginalTransactions.Count);
            Assert.IsNotNull(reverseRelationship);

            //---------------Execute Test ----------------------
            relationship.AddDirtyChildrenToTransactionCommitter(tc);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, tc.OriginalTransactions.Count);

            Assert.IsInstanceOf(typeof(TransactionalSingleRelationship_Added), tc.OriginalTransactions[0]);
            Assert.AreSame(relationship, ((TransactionalSingleRelationship_Added)tc.OriginalTransactions[0]).Relationship);
        }
        private static MultipleRelationship <ContactPersonTestBO> GetAggregateRelationship(OrganisationTestBO organisationTestBO, out BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            MultipleRelationship <ContactPersonTestBO> aggregateRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)aggregateRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Aggregation;
            cpCol = aggregateRelationship.BusinessObjectCollection;
            return(aggregateRelationship);
        }
        private MultipleRelationship <ContactPersonTestBO> GetRelationship(OrganisationTestBO organisationTestBO, RelationshipType relationshipType, out BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            cpCol = relationship.BusinessObjectCollection;
            return(relationship);
        }
        private static MultipleRelationship <ContactPersonTestBO> GetCompositionRelationship(out BusinessObjectCollection <ContactPersonTestBO> cpCol, OrganisationTestBO organisationTestBO)
        {
            MultipleRelationship <ContactPersonTestBO> compositionRelationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            cpCol = compositionRelationship.BusinessObjectCollection;
            return(compositionRelationship);
        }
        protected MultipleRelationship <ContactPersonTestBO> GetRelationship(OrganisationTestBO organisationTestBO)
        {
            RelationshipType relationshipType = GetRelationshipType();
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            return(relationship);
        }
        private SingleRelationship <ContactPersonTestBO> GetCompositionRelationship(OrganisationTestBO organisationTestBO)
        {
            RelationshipType relationshipType = RelationshipType.Composition;
            SingleRelationship <ContactPersonTestBO> compositionRelationship =
                organisationTestBO.Relationships.GetSingle <ContactPersonTestBO>("ContactPerson");
            RelationshipDef relationshipDef = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            return(compositionRelationship);
        }
示例#17
0
        /// <summary>
        /// Loads a business object using the relationship given. The relationship will be converted into a
        /// Criteria object that defines the relationship and this will be used to load the related object.
        /// </summary>
        /// <param name="relationship">The relationship to use to load the object</param>
        /// <returns>An object of the type defined by the relationship if one was found, otherwise null</returns>
        public IBusinessObject GetRelatedBusinessObject(ISingleRelationship relationship)
        {
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            if (relationshipDef.RelatedObjectClassDef != null)
            {
                return(GetBusinessObject(relationshipDef.RelatedObjectClassDef, Criteria.FromRelationship(relationship)));
            }
            return(null);
        }
示例#18
0
        private static SingleRelationship <OrganisationTestBO> GetAggregationRelationshipOrganisation
            (BusinessObject businessObject, string relationshipName)
        {
            const RelationshipType relationshipType = RelationshipType.Aggregation;
            SingleRelationship <OrganisationTestBO> aggregationRelationship =
                businessObject.Relationships.GetSingle <OrganisationTestBO>(relationshipName);
            RelationshipDef relationshipDef = (RelationshipDef)aggregationRelationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            return(aggregationRelationship);
        }
示例#19
0
        protected MultipleRelationship <ContactPersonTestBO> GetCompositionRelationship(OrganisationTestBO organisationTestBO, out BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            RelationshipType relationshipType = RelationshipType.Composition;
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            cpCol = relationship.BusinessObjectCollection;
            return(relationship);
        }
        protected static SingleRelationship <ContactPersonTestBO> GetAssociationRelationship(OrganisationTestBO organisationTestBO)
        {
            const RelationshipType relationshipType = RelationshipType.Association;
            SingleRelationship <ContactPersonTestBO> compositionRelationship =
                organisationTestBO.Relationships.GetSingle <ContactPersonTestBO>("ContactPerson");
            RelationshipDef relationshipDef = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType      = relationshipType;
            relationshipDef.OwningBOHasForeignKey = false;
            return(compositionRelationship);
        }
        private static MultipleRelationship <ContactPersonTestBO> GetAssociationRelationship
            (BusinessObject organisationTestBO, out BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            const RelationshipType relationshipType = RelationshipType.Association;
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = relationshipType;
            cpCol = relationship.BusinessObjectCollection;
            return(relationship);
        }
示例#22
0
        private static MockBO GetMockBO(out RelationshipDef mRelationshipDef, out RelKeyDef mRelKeyDef)
        {
            MockBO      _mMockBO    = new MockBO();
            IPropDefCol mPropDefCol = _mMockBO.PropDefCol;

            mRelKeyDef = new RelKeyDef();
            IPropDef   propDef     = mPropDefCol["MockBOProp1"];
            RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID");

            mRelKeyDef.Add(lRelPropDef);
            mRelationshipDef = new SingleRelationshipDef("Relation1", typeof(MockBO), mRelKeyDef, false,
                                                         DeleteParentAction.Prevent);
            return(_mMockBO);
        }
        public void Test_CreateMultipleRelationshipWithTimeout()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef    relationshipDef    = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"];
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IMultipleRelationship rel = new MultipleRelationship <ContactPersonTestBO> (organisationTestBO, relationshipDef, organisationTestBO.Props, 30000);

            //---------------Test Result -----------------------
            Assert.IsTrue(true, "Should not give an error when constructing");
        }
        public void Test_SetParent_NewChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Execute Test ----------------------
            contactPerson.Organisation = organisation;

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, organisation.ContactPerson);
            Assert.AreSame(organisation, contactPerson.Organisation);
        }
示例#25
0
        public void init()
        {
            this.SetupDBConnection();

            mMockBo     = new MockBO();
            mPropDefCol = mMockBo.PropDefCol;

            mRelKeyDef = new RelKeyDef();
            IPropDef propDef = mPropDefCol["MockBOProp1"];

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

            mRelKeyDef.Add(lRelPropDef);

            mRelationshipDef = new SingleRelationshipDef
                                   ("Relation1", typeof(MockBO), mRelKeyDef, false, DeleteParentAction.Prevent);
            //DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString();
        }
        public void Test_SetParentNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Assert Precondition----------------
            Assert.IsNull(contactPerson.Organisation);

            //---------------Execute Test ----------------------
            contactPerson.Organisation = null;

            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
        public void Test_CreatedChild_WhenInsertParentAction_InsertRelationship_SavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = organisationTestBO.ContactPeople.CreateBusinessObject();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            contactPerson.Surname            = TestUtil.GetRandomString();
            contactPerson.FirstName          = TestUtil.GetRandomString();
            //---------------AssertPrecondtion------------------
            Assert.AreEqual(InsertParentAction.InsertRelationship, relationshipDef.InsertParentAction);
            //---------------Execute Test ----------------------
            organisationTestBO.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
        }
        public void Test_MarkedForDeleteChild_SavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = organisationTestBO.ContactPeople.CreateBusinessObject();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            contactPerson.Surname            = TestUtil.GetRandomString();
            contactPerson.FirstName          = TestUtil.GetRandomString();
            contactPerson.Save();
            contactPerson.MarkForDelete();

            //---------------Execute Test ----------------------
            organisationTestBO.Save();

            //---------------Test Result -----------------------
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPerson);
        }
示例#29
0
        public void init()
        {
            BORegistry.DataAccessor = new DataAccessorInMemory();
            _fakeBO     = new MockBO();
            _propDefCol = _fakeBO.PropDefCol;

            _RelKeyDef = new RelKeyDef();
            IPropDef propDef = _propDefCol["MockBOID"];

            RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1");

            _RelKeyDef.Add(relPropDef);

            _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO),
                                                                   _RelKeyDef, false, "",
                                                                   DeleteParentAction.DeleteRelated);


            _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO),
                                                               _RelKeyDef, false,
                                                               DeleteParentAction.DeleteRelated);
        }
示例#30
0
        public void Test_LoadInheritedRelationship_UsingInheritedRelatedProps()
        {
            DefClassFactory       defClassFactory = new DefClassFactory();
            XmlRelationshipLoader loader          = new XmlRelationshipLoader(new DtdLoader(), defClassFactory, "TestClass");
            IPropDefCol           propDefs        = defClassFactory.CreatePropDefCol();

            propDefs.Add(defClassFactory.CreatePropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));

            RelationshipDef relDef =
                (RelationshipDef)loader.LoadRelationship(
                    @"<relationship 
						name=""TestRelationship"" 
						type=""single"" 
						relatedClass=""Habanero.Test.BO.Loaders.NonExistantTestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO"" 
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />

					</relationship>"                    ,
                    propDefs);
            Type classType = relDef.RelatedObjectClassType;
        }