Exemple #1
0
        public void Test_UpdateStateAsCommitted_Removed_UpdatesCols()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO  organisationTestBO  = new OrganisationTestBO();

            SingleRelationship <OrganisationTestBO>        singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation");
            BusinessObjectCollection <ContactPersonTestBO> people             = organisationTestBO.ContactPeople;

            organisationTestBO.Save();
            contactPersonTestBO.Organisation = organisationTestBO;
            contactPersonTestBO.Save();
            contactPersonTestBO.Organisation = null;
            IRelationship relationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            TransactionalSingleRelationship_Removed tsr = new TransactionalSingleRelationship_Removed(relationship, contactPersonTestBO);

            //---------------Assert PreConditions---------------

            Assert.AreEqual(1, people.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, people.PersistedBusinessObjects.Count);
            Assert.IsTrue(singleRelationship.IsRemoved);
            //---------------Execute Test ----------------------

            tsr.UpdateStateAsCommitted();
            //---------------Test Result -----------------------

            Assert.AreEqual(0, people.RemovedBusinessObjects.Count);
            Assert.AreEqual(0, people.PersistedBusinessObjects.Count);
//            Assert.IsFalse(singleRelationship.IsRemoved);
            //---------------Tear Down -------------------------
        }
        public void Test_UpdateSqlStatement()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO  organisationTestBO  = new OrganisationTestBO();

            SingleRelationship <OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation");

            singleRelationship.SetRelatedObject(organisationTestBO);
            IRelationship relationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            //TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship);
            var generator = CreateUpdateStatementGenerator(contactPersonTestBO, DatabaseConfig.MySql);
            //---------------Assert PreConditions---------------

            //---------------Execute Test ----------------------
            var sql = generator.GenerateForRelationship(relationship, contactPersonTestBO);
            //---------------Test Result -----------------------
            var sqlStatements = sql.ToList();

            Assert.AreEqual(1, sqlStatements.Count);
            Assert.AreEqual("UPDATE `contact_person` SET `OrganisationID` = ?Param0 WHERE `ContactPersonID` = ?Param1", sqlStatements[0].Statement.ToString());
            Assert.AreEqual(organisationTestBO.OrganisationID.Value.ToString("B").ToUpper(), sqlStatements[0].Parameters[0].Value);
            Assert.AreEqual(contactPersonTestBO.ContactPersonID.ToString("B").ToUpper(), sqlStatements[0].Parameters[1].Value);
        }
Exemple #3
0
        private static void AssertIsAggregateRelationship(BusinessObject organisation)
        {
            SingleRelationship <ContactPersonTestBO> aggregationRelationship =
                organisation.Relationships.GetSingle <ContactPersonTestBO>("ContactPerson");

            Assert.AreEqual(RelationshipType.Aggregation, aggregationRelationship.RelationshipDef.RelationshipType);
        }
Exemple #4
0
        public void Test_IsDeletable_WhenSingle_WhenDeleteAction_EQ_PreventDelete_WhenHasRelated_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            SingleRelationship <MyRelatedBo> relationship = (SingleRelationship <MyRelatedBo>)bo.Relationships["MyRelationship"];

            relationship.SetRelatedObject(new MyRelatedBo());
            //---------------Assert Precondition----------------
            Assert.IsFalse(bo.Status.IsDeleted);
            Assert.IsNotNull(relationship.GetRelatedObject());
            Assert.AreEqual(DeleteParentAction.Prevent, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            string message;
            bool   isDeletable = relationship.IsDeletable(out message);

            //---------------Test Result -----------------------
            Assert.IsFalse(isDeletable);
        }
        public virtual void Test_RemovedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisation);

            relationship.OwningBOHasForeignKey = false;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            organisation.ContactPerson = contactPerson;
            organisation.Save();
            contactPerson.Surname      = TestUtil.GetRandomString();
            organisation.ContactPerson = null;

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

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

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsFalse(organisation.Status.IsDirty);
        }
        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);
        }
        public void Test_ParentDirtyIfHasDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisation);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
            Assert.IsFalse(relationship.IsDirty);
            Assert.IsFalse(organisation.Relationships.IsDirty);
            Assert.IsFalse(organisation.Status.IsDirty);

            //---------------Execute Test ----------------------
            contactPerson.FirstName = TestUtil.GetRandomString();

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(relationship.IsDirty);
            Assert.IsTrue(organisation.Relationships.IsDirty);
            Assert.IsTrue(organisation.Status.IsDirty);
        }
Exemple #8
0
        public void TestGetReverseRelationship_ReverseRelationshipSpecifiedButNotFound()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO.LoadDefaultClassDef();
            IClassDef cpClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

            string reverseRelationshipName = TestUtil.GetRandomString();

            cpClassDef.RelationshipDefCol["Organisation"].ReverseRelationshipName = reverseRelationshipName;

            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            SingleRelationship <OrganisationTestBO> organisationRel =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");

            //---------------Execute Test ----------------------
            try
            {
                organisationRel.GetReverseRelationship(organisation);
                Assert.Fail("Should have failed since a reverse relationship was specified that didn't exist.");
            }
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains(
                    string.Format(
                        "The relationship 'Organisation' on class 'ContactPersonTestBO' has a reverse relationship defined ('{0}')",
                        reverseRelationshipName), ex.Message);
            }
        }
        public void Test_GetDirtyChildren_MarkedForDelete()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname      = TestUtil.GetRandomString();
            myBO.FirstName    = TestUtil.GetRandomString();
            myBO.Organisation = organisationTestBO;
            organisationTestBO.Save();
            ReflectionUtilities.SetPropertyValue(myBO.Status, "IsDeleted", true);
            //ReflectionUtilities.SetPropertyValue(myBO.Status, "IsDirty", true);

            //---------------Assert Preconditions---------------
            Assert.IsTrue(myBO.Status.IsDeleted);
            Assert.IsTrue(myBO.Status.IsDirty);
            //---------------Execute Test ----------------------

            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dirtyChildren.Count);
            Assert.Contains(myBO, (ICollection)dirtyChildren);
        }
Exemple #10
0
        public void Test_SetParentNull_NewChild_BotRelationshipSetUpAsOwning()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <OrganisationTestBO> relationshipOrganisation = GetAggregationRelationshipOrganisation(contactPerson, "Organisation");

            relationshipOrganisation.OwningBOHasForeignKey = true;

            SingleRelationship <ContactPersonTestBO> relationshipContactPerson = GetAggregationRelationshipContactPerson(organisation, "ContactPerson");

            relationshipContactPerson.OwningBOHasForeignKey = true;
            //---------------Assert Preconditon-----------------
            Assert.IsNull(organisation.ContactPerson);
            Assert.IsNull(contactPerson.Organisation);
            Assert.IsNotNull(organisation.OrganisationID);
            //---------------Execute Test ----------------------
            try
            {
                contactPerson.Organisation = organisation;
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The corresponding single (one to one) relationships Organisation ", ex.Message);
                StringAssert.Contains("cannot both be configured as having the foreign key", ex.Message);
            }
        }
Exemple #11
0
        public void Test_UpdateStateAsCommitted()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            OrganisationTestBO  organisationTestBO  = new OrganisationTestBO();

            SingleRelationship <OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation");

            singleRelationship.SetRelatedObject(organisationTestBO);

            IRelationship relationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(relationship, contactPersonTestBO);
            IBOProp relationshipProp = contactPersonTestBO.Props["OrganisationID"];

            //---------------Assert PreConditions---------------
            Assert.IsTrue(relationshipProp.IsDirty);
            Assert.AreNotEqual(relationshipProp.Value, relationshipProp.PersistedPropertyValue);

            //---------------Execute Test ----------------------
            tsr.UpdateStateAsCommitted();

            //---------------Test Result -----------------------
            Assert.IsFalse(relationshipProp.IsDirty);
            Assert.AreEqual(relationshipProp.Value, relationshipProp.PersistedPropertyValue);
        }
        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);
        }
        public void TestCreateSingleRelationship()
        {
            SingleRelationship rel =
                (SingleRelationship)_singleRelationshipDef.CreateRelationship(_mockBo, _mockBo.Props);

            //-------------Execute Test ------------------------
            IBusinessObjectCollection relatedObjects = rel.GetRelatedBusinessObjectCol();

            //-------------Test Result -------------------------
            Assert.IsTrue(relatedObjects.Count == 0);
        }
        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);
        }
Exemple #15
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);
        }
        public void TestCreateSingleRelationshipUsingGenerics()
        {
            //---------------Set up test pack-------------------

            SingleRelationship rel =
                (SingleRelationship)_singleRelationshipDef.CreateRelationship(_mockBo, _mockBo.Props);
            //-------------Execute Test ------------------------
            BusinessObjectCollection <MockBO> relatedObjects = rel.GetRelatedBusinessObjectCol <MockBO>();

            //-------------Test Result -------------------------
            Assert.IsTrue(relatedObjects.Count == 0);
        }
        public void Test_SetChild_NewChild()
        {
            //A new ContactPerson can be set as the contact person of an organisation.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(contactPerson);

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, relationship.GetRelatedObject());
        }
Exemple #18
0
        public void Test_Constructor()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            SingleRelationship <OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation");

            //---------------Execute Test ----------------------
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship, new OrganisationTestBO());

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

            Assert.AreSame(singleRelationship, tsr.Relationship);
            //---------------Tear Down -------------------------
        }
Exemple #19
0
        public void Test_SetChild_AggregateDoesNotOwnForeignKey_NewChild()
        {
            //A new Heart can be set as the heart of a person.  This is allowed in Habanero for flexibility, but
            // it is rather recommended that the Person creates the Heart.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <OrganisationTestBO> relationship = GetAggregationRelationshipOrganisation(contactPerson, "Organisation");

            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(organisationTestBO);
            //---------------Test Result -----------------------
            Assert.AreSame(organisationTestBO, relationship.GetRelatedObject());
        }
Exemple #20
0
        public void Test_SetChild_PersistedChild()
        {
            //An already persisted Heart can be set as the heart of a person (since you can transplant hearts)
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship =
                GetAggregationRelationshipContactPerson(organisationTestBO, "ContactPerson");
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(contactPerson);

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, relationship.GetRelatedObject());
        }
Exemple #21
0
        public void Test_Criteria_OneProp_NullValue()
        {
            //--------------- Set up test pack ------------------
            MyBO.LoadClassDefWithRelationship();
            MyRelatedBo.LoadClassDef();
            MyRelatedBo myRelatedBo = new MyRelatedBo();
            SingleRelationship <MyBO> relationship = myRelatedBo.Relationships.GetSingle <MyBO>("MyRelationship");
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            Criteria relCriteria = relationship.RelKey.Criteria;

            //--------------- Test Result -----------------------
            StringAssert.AreEqualIgnoringCase("MyBoID IS NULL", relCriteria.ToString());
        }
        public void TestGetSingle_Generic()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO         bo1 = (MyBO)classDef.CreateNewBusinessObject();
            const string relationshipName = "MyRelationship";

            //---------------Execute Test ----------------------
            SingleRelationship <MyRelatedBo> relationship = bo1.Relationships.GetSingle <MyRelatedBo>(relationshipName);

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

            Assert.IsNotNull(relationship);
            Assert.AreEqual(relationshipName, relationship.RelationshipName);
        }
        public void Test_GetDirtyChildren_AddedChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            organisationTestBO.ContactPerson = contactPerson;

            //---------------Execute Test ----------------------
            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dirtyChildren.Count);

            //---------------Tear Down -------------------------
        }
        public void Test_ResetParent_NewChild_SetToNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisation);

            relationship.OwningBOHasForeignKey = false;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

            //---------------Execute Test ----------------------
            contactPerson.Organisation = null;
            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
Exemple #25
0
        public void Test_GetDirtyChildren_Created()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisationTestBO, "ContactPerson");
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname      = TestUtil.GetRandomString();
            myBO.FirstName    = TestUtil.GetRandomString();
            myBO.Organisation = organisationTestBO;
            //---------------Execute Test ----------------------

            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.Contains(myBO, (ICollection)dirtyChildren);
            Assert.AreEqual(1, dirtyChildren.Count);
        }
        public void Test_NotDirty_IfChildIsAddedThenRemoved()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisation);

            relationship.SetRelatedObject(contactPerson);
            IList <ContactPersonTestBO> children = relationship.GetDirtyChildren();

            //---------------Assert preconditions---------------
            Assert.AreEqual(1, children.Count);
            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(null);
            children = relationship.GetDirtyChildren();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, children.Count);
        }
Exemple #27
0
        public void Test_RemoveMethod()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisation, "ContactPerson");
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            relationship.SetRelatedObject(contactPerson);
            //---------------Assert Precondition----------------
            Assert.AreEqual(contactPerson.OrganisationID, organisation.OrganisationID);
            Assert.AreSame(organisation.ContactPerson, contactPerson);
            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(null);
            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.OrganisationID);
            Assert.IsNull(organisation.ContactPerson);
            Assert.IsNotNull(organisation.OrganisationID);
            Assert.IsNull(contactPerson.Organisation);
        }
        public void Test_GetDirtyChildren_Edited()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO contactPerson = new ContactPersonTestBO();

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

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

            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dirtyChildren.Count);
        }
        public void TestGetSingle_Generic_Fail()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO   bo1 = (MyBO)classDef.CreateNewBusinessObject();
            string relationshipName = "MyMultipleRelationship";

            //---------------Execute Test ----------------------
            try
            {
                SingleRelationship <MyRelatedBo> relationship = bo1.Relationships.GetSingle <MyRelatedBo>(relationshipName);
                Assert.Fail("Should have failed because we're accessing a multiple relationship as a single.");
                //---------------Test Result -----------------------
            }
            catch (InvalidRelationshipAccessException)
            {
            }
        }
        public void Test_DirtyIfHasCreatedChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisationTestBO);
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname   = TestUtil.GetRandomString();
            myBO.FirstName = TestUtil.GetRandomString();

            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsDirty);

            //---------------Execute Test ----------------------
            myBO.Organisation = organisationTestBO;
            bool isDirty = relationship.IsDirty;

            //---------------Test Result -----------------------
            Assert.IsTrue(isDirty);
        }