protected MultipleRelationship<ContactPersonTestBO> GetRelationship(
     OrganisationTestBO organisationTestBO, out BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     var relationship = GetRelationship(organisationTestBO);
     cpCol = relationship.BusinessObjectCollection;
     return relationship;
 }
 protected MultipleRelationship<ContactPersonTestBO> GetRelationship(
     out OrganisationTestBO organisationTestBO, 
     out BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     RelationshipCol relationships;
     return GetRelationship(out organisationTestBO, out relationships, out cpCol);
 }
 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;
 }
        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());
        }        
 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;
 }
 public void SetupTest()
 {
     //Runs every time that any testmethod is executed            
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
     OrganisationTestBO.LoadDefaultClassDef();
     BORegistry.DataAccessor = new DataAccessorInMemory();
     _organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
 }
示例#7
0
        public void Test_RemoveMethod()
        {
            //An invoice line cannot be removed from an Invoice.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     compositionRelationship = GetCompositionRelationship(out cpCol);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());

            contactPerson.OrganisationID = organisationTestBO.OrganisationID;
            contactPerson.Save();
            cpCol.LoadAll();
            util.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            util.AssertOneObjectInCurrentPersistedCollection(cpCol);
            var loading = BOColLoaderHelper.GetLoading(cpCol);

            Assert.IsFalse(loading);
            //Assert.IsFalse((bool)ReflectionUtilities.GetPrivatePropertyValue(cpCol, "Loading"));
            //BOColLoaderHelper.ClearCurrentCollection(collection);
            //---------------Execute Test ----------------------
            try
            {
                cpCol.Remove(contactPerson);
                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);
                StringAssert.Contains("RemoveChildAction.Prevent", ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail("HabaneroDeveloperException not thrown. Exception Thrown was : " + ex.Message);
            }
        }
示例#8
0
        public void Test_UpdateStateAsCommitted_UpdateDirtyStatus_IDOnly()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO  organisationTestBO  = OrganisationTestBO.CreateSavedOrganisation();

            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);

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPersonTestBO.Status.IsDirty);
            //---------------Tear Down -------------------------
        }
示例#9
0
        public void Test_DirtyIfHasRemoveChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);
            ContactPersonTestBO myBO = cpCol.CreateBusinessObject();

            myBO.Surname   = TestUtil.GetRandomString();
            myBO.FirstName = TestUtil.GetRandomString();
            myBO.Save();
            organisationTestBO.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsDirty);

            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            Assert.IsTrue(relationship.IsDirty);
        }
示例#10
0
        public void Test_GetDirtyChildren_Edited()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);

            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

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

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

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dirtyChildren.Count);
            Assert.IsTrue(dirtyChildren.Contains(contactPerson));
        }
        public virtual void Test_KeyPressStrategy_UpdatesBusinessObject_WhenEnterKeyPressed()
        {
            //---------------Set up test pack-------------------
            ComboBoxWinStub cmbox = new ComboBoxWinStub();
            BusinessObjectCollection <OrganisationTestBO> boCol;
            RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(cmbox, out boCol);

            mapper.MapperStrategy = GetControlFactory().CreateLookupKeyPressMapperStrategy();
            OrganisationTestBO  newBO = boCol.CreateBusinessObject();
            OrganisationTestBO  organisationTestBO = boCol[0];
            ContactPersonTestBO person             = CreateCPWithRelatedOrganisation(organisationTestBO);

            mapper.BusinessObject = person;
            cmbox.Text            = newBO.ToString();
            //---------------Assert Precondition----------------
            Assert.AreNotSame(newBO, person.Organisation, "For Windows the value should be changed.");
            //---------------Execute Test ----------------------
            cmbox.CallSendKeyBob();
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ComboBoxKeyPressMapperStrategyWin), mapper.MapperStrategy);
            Assert.AreSame(newBO, person.Organisation, "For Windows the value should be changed.");
        }
示例#12
0
        public void Test_GetIBOGridAndEditorControl_ShouldReturnEditorOnForm()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO.LoadDefaultClassDef();
            IControlFactory     controlFactory   = GetControlFactory();
            ExtendedComboBoxWin extendedComboBox = new ExtendedComboBoxWin(controlFactory);
            const string        propName         = "OrganisationID";
            var mapper = new ExtendedComboBoxMapperSpy(
                extendedComboBox, propName, true, controlFactory);

            mapper.BusinessObject = new ContactPersonTestBO();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            mapper.ShowPopupForm();
            var boGridAndEditorControl = mapper.CallGetIBOGridAndEditorControl();
            //---------------Test Result -----------------------

            IFormHabanero form = mapper.PopupForm;

            Assert.AreSame(boGridAndEditorControl, form.Controls[0]);
        }
示例#13
0
        public void TestGetReverseRelationship()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO.LoadDefaultClassDef_WithTwoRelationshipsToContactPerson();
            IClassDef cpClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

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

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

            SingleRelationship <OrganisationTestBO> organisationRel =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");
            MultipleRelationship <ContactPersonTestBO> contactPeopleRel =
                organisation.Relationships.GetMultiple <ContactPersonTestBO>("OtherContactPeople");

            //---------------Execute Test ----------------------
            IRelationship reverseRelationship = organisationRel.GetReverseRelationship(organisation);

            //---------------Test Result -----------------------
            Assert.AreSame(contactPeopleRel, reverseRelationship);
        }
        public void Test_DirtyIfHasDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisationTestBO);

            ContactPersonTestBO contactPerson = new ContactPersonTestBO();

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

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

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

            //---------------Test Result -----------------------
            Assert.IsTrue(relationship.IsDirty);
        }
        public void Test_SetChild_PersistedChild()
        {
            //An already persi`sted Brain cannot be set as the brain of a person.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = GetCompositionRelationship(organisation);

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            try
            {
                compositionRelationship.SetRelatedObject(contactPerson);
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
        }
示例#16
0
        public void Test_CancelEdits()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            MultipleRelationship <ContactPersonTestBO>     contactPersonRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> contactPersonCol          = contactPersonRelationship.BusinessObjectCollection;
            MultipleRelationship <AddressTestBO>           addressRelationship       = organisationTestBO.Relationships.GetMultiple <AddressTestBO>("Addresses");
            BusinessObjectCollection <AddressTestBO>       addressCol = addressRelationship.BusinessObjectCollection;

            contactPersonCol.CreateBusinessObject();
            addressCol.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationships.IsDirty);
            //---------------Execute Test ----------------------
            relationships.CancelEdits();
            //---------------Test Result -----------------------
            Assert.IsFalse(relationships.IsDirty);
        }
示例#17
0
        public void Test_GetDirtyChildren_WhenCreated_WhenInsertParentAction_DoNothing_ShouldNotReturnCreatedChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.InsertParentAction = InsertParentAction.DoNothing;
            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreEqual(InsertParentAction.DoNothing, relationshipDef.InsertParentAction);
            //---------------Execute Test ----------------------
            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dirtyChildren.Count);
        }
        public void Test_CreatedChild_WhenInsertParentAction_DoNothing_DoesNotSavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = organisationTestBO.ContactPeople.CreateBusinessObject();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.InsertParentAction = InsertParentAction.DoNothing;
            relationshipDef.RelationshipType   = RelationshipType.Association;
            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            //---------------AssertPrecondtion------------------
            Assert.AreEqual(InsertParentAction.DoNothing, relationshipDef.InsertParentAction);
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Status.IsNew);
            //---------------Execute Test ----------------------
            organisationTestBO.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Status.IsNew);
        }
        public void ReverseRelationship_GetRelatedObject_BUGFIX_WhenChildAndParentAlreadyLoaded_AndParentSwitchedToLoadedParent_ShouldAddChildToParentRelationship()
        {
            //---------------Set up test pack-------------------
            var contactPersonTestBO   = CreateSavedContactPersonTestBoAndOrganisation();
            var newOrganisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            var organisationTestBO    = contactPersonTestBO.Organisation;

            FixtureEnvironment.ClearBusinessObjectManager();
            organisationTestBO    = ReloadBoFromDB(organisationTestBO);
            contactPersonTestBO   = ReloadBoFromDB(contactPersonTestBO);
            newOrganisationTestBO = ReloadBoFromDB(newOrganisationTestBO);
            contactPersonTestBO.OrganisationID = newOrganisationTestBO.OrganisationID;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var organisation = contactPersonTestBO.Organisation;
            //---------------Test Result -----------------------
            var contactPeople = organisation.ContactPeople;

            Assert.AreEqual(1, contactPeople.Count, "Should have one Contact Person");
            Assert.AreEqual(0, contactPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(1, contactPeople.AddedBusinessObjects.Count);
        }
        public void Test_GetDirtyChildren_Removed()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);

            relationship.OwningBOHasForeignKey = false;
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname      = TestUtil.GetRandomString();
            myBO.FirstName    = TestUtil.GetRandomString();
            myBO.Organisation = organisationTestBO;
            myBO.Save();
            organisationTestBO.ContactPerson = null;

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

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

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dirtyChildren.Count);
        }
示例#21
0
        public void Test_ParentDirtyIfHasDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     compositionRelationship = GetCompositionRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

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

            //---------------Assert Precondition----------------
            Assert.IsFalse(organisationTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(organisationTestBO.Status.IsDirty);
        }
        public void Test_AddMethod_AddNewChild()
        {
            //•(In habanero a new tyre can be added to a car).
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     aggregateRelationship = GetAggregateRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            util.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            util.AssertAllCollectionsHaveNoItems(cpCol);

            //---------------Execute Test ----------------------
            cpCol.Add(contactPerson);

            //---------------Test Result -----------------------
            util.AssertAddedEventFired();
            util.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            Assert.AreSame(contactPerson.Organisation, aggregateRelationship.OwningBO);
        }
示例#23
0
        public void Test_LoadRelatedBoCol()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            ContactPersonTestBO cp =
                (ContactPersonTestBO)cpRelationship.BusinessObjectCollection.CreateBusinessObject();

            cp.FirstName = TestUtil.GetRandomString();
            cp.Surname   = TestUtil.GetRandomString();
            cp.Save();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObjectCollection cpCol =
                BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObjectCollection
                    (typeof(ContactPersonTestBO), cpRelationship);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
        public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutTwo_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, 2);
            IBusinessObjectCollection collection = rel.BusinessObjectCollection;
            DateTime?initialTimeLastLoaded       = collection.TimeLastLoaded;

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

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
        public void Test_DirtyIfHasMarkForDeleteChildren()
        {
            //---------------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;
            myBO.Save();
            myBO = organisationTestBO.ContactPerson;

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

            //---------------Execute Test ----------------------
            ReflectionUtilities.SetPropertyValue(myBO.Status, "IsDeleted", true);
            bool isDirty = relationship.IsDirty;

            //---------------Test Result -----------------------
            Assert.IsTrue(isDirty);
        }
        public void Test_RemoveMethod()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisation);

            relationship.OwningBOHasForeignKey = false;
            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);
        }
示例#27
0
        public void Test_ParentDirtyIfHasMarkForDeleteChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;

            GetAggregationRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO myBO = cpCol.CreateBusinessObject();

            myBO.Surname   = TestUtil.GetRandomString();
            myBO.FirstName = TestUtil.GetRandomString();
            myBO.Save();
            organisationTestBO.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(organisationTestBO.Status.IsDirty);

            //---------------Execute Test ----------------------
            cpCol.MarkForDelete(myBO);
            bool isDirty = organisationTestBO.Status.IsDirty;

            //---------------Test Result -----------------------
            Assert.IsTrue(isDirty);
        }
示例#28
0
        public void Test_UpdateStateAsCommitted_UpdateDirtyStatus_OtherDirtyField()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO  organisationTestBO  = new OrganisationTestBO();

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

            singleRelationship.SetRelatedObject(organisationTestBO);
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship, organisationTestBO);

            contactPersonTestBO.Surname = TestUtil.GetRandomString();

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            //---------------Tear Down -------------------------
        }
示例#29
0
        public void Test_ResetParent_PersistedChild()
        {
            //An already persisted invoice line cannot be added to an Invoice
            // This rule must also be implemented for the reverse relationship.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     compositionRelationship = GetCompositionRelationship(out cpCol, organisationTestBO);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

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

            OrganisationTestBO alternateOrganisationTestBO = OrganisationTestBO.CreateSavedOrganisation();

            //---------------Assert Precondition----------------
            util.AssertAllCollectionsHaveNoItems(cpCol);
            Assert.IsFalse(contactPerson.Status.IsNew);

            //---------------Execute Test ----------------------
            try
            {
                contactPerson.Organisation = alternateOrganisationTestBO;
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail("HabaneroDeveloperException not thrown. Exception Thrown was : " + ex.Message);
            }
        }
        public void Test_ResetParent_PersistedChild()
        {
            //The Tyre may however be transferred from one car to another.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;

            GetAggregateRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

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

            OrganisationTestBO alternateOrganisationTestBO = OrganisationTestBO.CreateSavedOrganisation();


            //---------------Assert Precondition----------------
            util.AssertOneObjectInCurrentPersistedCollection(cpCol);
            Assert.IsFalse(contactPerson.Status.IsNew);
            Assert.AreSame(contactPerson.Organisation, organisationTestBO);
            // Assert.AreEqual(0, cpAltCol.Count);

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

            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.IsFalse(cpCol.Contains(contactPerson));
            util.AssertOneObjectInRemovedAndPersisted(cpCol);
            MultipleRelationship <ContactPersonTestBO>     relationship = alternateOrganisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> cpAltCol     = relationship.BusinessObjectCollection;

            Assert.AreSame(contactPerson.Organisation, relationship.OwningBO);
            Assert.AreSame(alternateOrganisationTestBO, contactPerson.Organisation);
            util.AssertOneObjectInCurrentAndAddedCollection(cpAltCol);
        }
        public void Test_RemovedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves_DB()
        {
            //---------------Set up test pack-------------------
            TestUsingDatabase.SetupDBDataAccessor();
            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;

            //---------------Execute Test ----------------------
            organisation.Save();
            FixtureEnvironment.ClearBusinessObjectManager();
            ContactPersonTestBO loadedContactPerson = Broker.GetBusinessObject <ContactPersonTestBO>(contactPerson.ID);

            //---------------Test Result -----------------------
            Assert.IsNull(loadedContactPerson.OrganisationID);
        }
        public void Test_SetParent_PersistedChild()
        {
            //---------------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.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            try
            {
                contactPerson.Organisation = organisation;
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
            //---------------Test Result -----------------------
        }
        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);
        }
示例#34
0
        public void Test_AddDirtyChildrenToTransactionCommitter()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            MultipleRelationship <ContactPersonTestBO>     contactPersonRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> contactPersonCol          = contactPersonRelationship.BusinessObjectCollection;
            MultipleRelationship <AddressTestBO>           addressRelationship       = organisationTestBO.Relationships.GetMultiple <AddressTestBO>("Addresses");
            BusinessObjectCollection <AddressTestBO>       addressCol = addressRelationship.BusinessObjectCollection;

            contactPersonCol.CreateBusinessObject();
            addressCol.CreateBusinessObject();

            //---------------Execute Test ----------------------
            TransactionCommitterInMemory tc = new TransactionCommitterInMemory(new DataStoreInMemory());

            relationships.AddDirtyChildrenToTransactionCommitter(tc);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, tc.OriginalTransactions.Count);
        }
        public void Test_MustDeregisterForEvents_WhenSetBOToAnotherBO_ThenChangePropValue_ShouldNotUpdateControlValue()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = CreateComboBox();
            BusinessObjectCollection <OrganisationTestBO> boCol;
            RelationshipComboBoxMapper mapper             = GetMapperBoColHasOneItem(cmbox, out boCol);
            OrganisationTestBO         newBO              = boCol.CreateBusinessObject();
            OrganisationTestBO         organisationTestBO = boCol[0];
            ContactPersonTestBO        person             = CreateCPWithRelatedOrganisation(organisationTestBO);

            mapper.BusinessObject = person;
            ContactPersonTestBO newCP = new ContactPersonTestBO();

            //---------------Assert precondition----------------
            Assert.AreSame(organisationTestBO, person.Organisation);
            Assert.AreSame(organisationTestBO, cmbox.SelectedItem);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = newCP;
            person.Organisation   = newBO;
            //---------------Test Result -----------------------
            Assert.AreSame(newBO, person.Organisation);
            Assert.AreSame(null, newCP.Organisation);
            Assert.AreSame(null, cmbox.SelectedItem, "Value is not set after changing bo relationship");
        }
示例#36
0
        public void Test_CreatedBusinessObject_SaveAll()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------

            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname   = TestUtil.GetRandomString();
            newCP.FirstName = TestUtil.GetRandomString();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);
            Assert.AreEqual(InsertParentAction.InsertRelationship, cpRelationship.RelationshipDef.InsertParentAction);
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            //---------------Execute Test ----------------------
            cpCol.SaveAll();

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(newCP.Status.IsNew);
            Assert.IsFalse(newCP.Status.IsDirty);
        }
        public void Test_SetPerson_WithUnsavedOrg_ShouldNotRemoveOrg()
        {
            //---------------Set up test pack-------------------
            ComboBoxWinStub cmbox = new ComboBoxWinStub();
            BusinessObjectCollection <OrganisationTestBO> boCol;
            RelationshipComboBoxMapper mapper = GetMapper(cmbox);

            boCol = GetBoColWithOneItem();

            mapper.BusinessObject = new ContactPersonTestBO();

            OrganisationTestBO  testBO = new OrganisationTestBO();
            ContactPersonTestBO person = CreateCPWithRelatedOrganisation(testBO);

            //---------------Assert Precondition----------------
            Assert.False(boCol.Contains(testBO));
            Assert.AreSame(testBO, person.Organisation);
            Assert.IsNotNull(person.Organisation);
            Assert.IsTrue(person.Organisation.Status.IsNew);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = person;
            //---------------Test Result -----------------------
            Assert.IsNotNull(person.Organisation);
        }
 private static RelatedBusinessObjectCollection<ContactPersonTestBO> CreateRelatedCPCol(OrganisationTestBO organisationTestBO)
 {
     MultipleRelationship<ContactPersonTestBO> relationship = GetContactPersonRelationship(organisationTestBO);
     return BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObjectCollection<ContactPersonTestBO>(relationship);
 }
 private static MultipleRelationship<ContactPersonTestBO> GetContactPersonRelationship(OrganisationTestBO organisationTestBO)
 {
     return organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople");
 }
 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;
 }
 public void Test_WhenReferencedBOKeyChanges_ShouldChangeFK()
 {
     //---------------Set up test pack-------------------
     OrganisationTestBO organisationTestBO = new OrganisationTestBO();
     SetOrganisationID(organisationTestBO, null);
     ContactPersonTestBO contactPerson = new ContactPersonTestBO();
     contactPerson.Organisation = organisationTestBO;
     //---------------Assert preconditions---------------
     //Assert.IsFalse(organisationTestBO.Status.IsNew);
     //Assert.IsTrue(contactPerson.Status.IsNew);
     Assert.IsNull(GetOrganisationID(organisationTestBO));
     Assert.IsNull(GetOrganisationID(contactPerson));
     Assert.AreSame(organisationTestBO, contactPerson.Organisation);
     //Assert.AreEqual(2, BORegistry.BusinessObjectManager.Count);
     //---------------Execute Test ----------------------
     var newOrganisationIDValue = 123456;
     SetOrganisationID(organisationTestBO, newOrganisationIDValue);
     //---------------Test Result -----------------------
     Assert.AreSame(organisationTestBO, contactPerson.Organisation);
     Assert.AreSame(contactPerson, organisationTestBO.ContactPerson);
     Assert.AreEqual(newOrganisationIDValue, GetOrganisationID(organisationTestBO));
     Assert.AreEqual(newOrganisationIDValue, GetOrganisationID(contactPerson));
 }
 private static MultipleRelationship<ContactPersonTestBO> GetContactPersonRelationship()
 {
     if (_organisationTestBO == null)
     {
         _organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     }
     return _organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople");
 }
 private static SingleRelationship<ContactPersonTestBO> GetRelationship(OrganisationTestBO organisationTestBO, RelationshipType relationshipType)
 {
     SingleRelationship<ContactPersonTestBO> relationship =
         organisationTestBO.Relationships.GetSingle<ContactPersonTestBO>("ContactPerson");
     RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;
     relationshipDef.RelationshipType = relationshipType;
     return relationship;
 }
 protected static ContactPersonTestBO CreateRemovedChild_ChildOwnsEdit(OrganisationTestBO organisationTestBO)
 {
     ContactPersonTestBO removedChild = ContactPersonTestBO.CreateUnsavedContactPerson();
     removedChild.Organisation = organisationTestBO;
     organisationTestBO.Save();
     removedChild.Organisation = null;
     return removedChild;
 }
 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 MultipleRelationship<ContactPersonTestBO> GetAggregationRelationship(OrganisationTestBO organisationTestBO, out BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     const RelationshipType relationshipType = RelationshipType.Aggregation;
     return GetRelationship(organisationTestBO, relationshipType, out cpCol);
 }
 protected MultipleRelationship<ContactPersonTestBO> GetRelationship(
     out OrganisationTestBO organisationTestBO, out RelationshipCol relationships,
     out BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     relationships = organisationTestBO.Relationships;
     return GetRelationship(organisationTestBO, out cpCol);
 }
 private static RelatedBusinessObjectCollection<ContactPersonTestBO> CreateCol_OneCP(out ContactPersonTestBO cp, OrganisationTestBO organisation)
 {
     cp = CreateSavedContactPerson(organisation);
     return CreateRelatedCPCol(organisation);
 }
 protected virtual ContactPersonTestBO CreateAddedChild_ChildOwnsEdit(OrganisationTestBO organisationTestBO)
 {
     ContactPersonTestBO addedChild = ContactPersonTestBO.CreateSavedContactPerson();
     addedChild.Organisation = organisationTestBO;
     return addedChild;
 }
 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;
 }
 private static MultipleRelationship<ContactPersonTestBO> GetMultipleRelationship(OrganisationTestBO organisationTestBO, RelationshipType relationshipType)
 {
     MultipleRelationship<ContactPersonTestBO> relationship =
         organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople");
     RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;
     relationshipDef.RelationshipType = relationshipType;
     return relationship;
 }
 protected static ContactPersonTestBO CreateCreatedChild_ChildOwnsEdit(OrganisationTestBO organisationTestBO)
 {
     ContactPersonTestBO createdChild = ContactPersonTestBO.CreateUnsavedContactPerson();
     createdChild.Organisation = organisationTestBO;
     return createdChild;
 }
 protected static SingleRelationship<ContactPersonTestBO> GetAssociationRelationship(OrganisationTestBO organisationTestBO)
 {
     const RelationshipType relationshipType = RelationshipType.Association;
     return GetRelationship(organisationTestBO, relationshipType);
 }
 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 void CopyOrganisationID(OrganisationTestBO fromBO, ContactPersonTestBO toBO)
 {
     SetOrganisationID(toBO, GetOrganisationID(fromBO));
 }
        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 -------------------------          
        }
 private static ContactPersonTestBO CreateSavedContactPerson(OrganisationTestBO organisation)
 {
     MultipleRelationship<ContactPersonTestBO> relationship = GetContactPersonRelationship(organisation);
     ContactPersonTestBO cp = relationship.BusinessObjectCollection.CreateBusinessObject();
     cp.Surname = TestUtil.GetRandomString();
     cp.FirstName = TestUtil.GetRandomString();
     cp.Save();
     return cp;
 }
 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;
 }
 private static RelatedBusinessObjectCollection<ContactPersonTestBO> CreateCollectionWith_OneBO(OrganisationTestBO organisation)
 {
     CreateSavedContactPerson(organisation);
     return CreateRelatedCPCol(organisation);
 }
        public void Test_UpdateStateAsCommitted_UpdateDirtyStatus_OtherDirtyField()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO organisationTestBO = new OrganisationTestBO();

            SingleRelationship<OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle<OrganisationTestBO>("Organisation");
            singleRelationship.SetRelatedObject(organisationTestBO);
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship, organisationTestBO);

            contactPersonTestBO.Surname = TestUtil.GetRandomString();
            
            //---------------Assert PreConditions--------------- 
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            
            //---------------Execute Test ----------------------
            tsr.UpdateStateAsCommitted();
            
            //---------------Test Result -----------------------
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            //---------------Tear Down -------------------------          
        }