Inheritance: BusinessObject
Ejemplo n.º 1
0
        public void Test_BusinessObject_WhenSet_HavingExistingNonSingleRelationshipOnRelatedBO_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO.LoadDefaultClassDef();
            IClassDef            contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO  contactPersonTestBO   = new ContactPersonTestBO();
            const string         innerRelationshipName = "ContactPersonTestBO";
            const string         outerRelationshipName = "Addresses";
            const string         relationshipName      = outerRelationshipName + "." + innerRelationshipName;
            BORelationshipMapper boRelationshipMapper  = new BORelationshipMapper(relationshipName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            //---------------Execute Test ----------------------
            try
            {
                boRelationshipMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '"
                                      + contactPersonClassDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.", ex.Message);
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on the BusinessObject '"
                                      + contactPersonClassDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.", ex.DeveloperMessage);
                Assert.IsNull(boRelationshipMapper.BusinessObject);
                Assert.IsNull(boRelationshipMapper.Relationship);
            }
        }
Ejemplo n.º 2
0
        public static AddressTestBO CreateSavedAddress(Guid contactPersonID, string firstLine)
        {
            AddressTestBO address = CreateUnsavedAddress(contactPersonID, firstLine);

            address.Save();
            return(address);
        }
Ejemplo n.º 3
0
        public static AddressTestBO CreateSavedAddress(Guid contactPersonID)
        {
            AddressTestBO address = CreateUnsavedAddress(contactPersonID);

            address.Save();
            return(address);
        }
Ejemplo n.º 4
0
        public static string CreateAddressTable(string tableNameExtension)
        {
            var contactPersonAddressTableName = "contact_person_address_" + tableNameExtension;

            AddressTestBO.CreateContactPersonAddressTable(contactPersonAddressTableName, "contact_person_" + tableNameExtension);
            return(contactPersonAddressTableName);
        }
Ejemplo n.º 5
0
        public static AddressTestBO CreateUnsavedAddress(ContactPersonTestBO contactPerson, string firstLine)
        {
            AddressTestBO address = new AddressTestBO();

            address.ContactPersonTestBO = contactPerson;
            address.AddressLine1        = firstLine;
            return(address);
        }
Ejemplo n.º 6
0
        private static ContactPersonTestBO CreateSavedCP_WithOneAddresss(out AddressTestBO address)
        {
            ContactPersonTestBO cp = CreateSavedCP();

            address = new AddressTestBO();
            address.ContactPersonID = cp.ContactPersonID;
            address.Save();
            return(cp);
        }
Ejemplo n.º 7
0
 public void SetupTest()
 {
     ClassDef.ClassDefs.Clear();
     GlobalRegistry.UIExceptionNotifier = new RethrowingExceptionNotifier();
     BORegistry.DataAccessor            = new DataAccessorInMemory();
     AddressTestBO.LoadDefaultClassDef();
     ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
     OrganisationTestBO.LoadDefaultClassDef();
 }
 public void TestFixtureSetup()
 {
     ClassDef.ClassDefs.Clear();
     GlobalRegistry.UIExceptionNotifier = new RethrowingExceptionNotifier();
     FixtureEnvironment.SetupInMemoryDataAccessor();
     FixtureEnvironment.ResetBORegistryBusinessObjectManager();
     AddressTestBO.LoadDefaultClassDef();
     ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
     OrganisationTestBO.LoadDefaultClassDef();
 }
Ejemplo n.º 9
0
        public void Test_LoadObjectWhenAlreadyObjectInObjectManager()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            AddressTestBO       address;
            ContactPersonTestBO cp = CreateSavedCP_WithOneAddresss(out address);

            IPrimaryKey contactPersonID = cp.ID;
            IPrimaryKey addresssID      = address.ID;

            cp      = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            AddressTestBO addressOut;

            CreateSavedCP_WithOneAddresss(out addressOut);
            CreateSavedCP_WithOneAddresss(out addressOut);
            CreateSavedCP_WithOneAddresss(out addressOut);

            //---------------Assert Precondition----------------
            Assert.AreEqual(6, boMan.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(contactPersonID);
            RelatedBusinessObjectCollection <AddressTestBO> addresses = loadedCP.AddressTestBOs;

            //---------------Test Result -----------------------
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(8, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            AddressTestBO loadedAddress = addresses[0];

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.GetObjectId()));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]);
        }
Ejemplo n.º 10
0
        public void Test_EditDataTable_WhenMultipleLevelProp_ShouldEditRelatedBO()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <AddressTestBO> addresses = new BusinessObjectCollection <AddressTestBO>();

            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });
            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });
            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid       uiGrid       = new UIGrid();
            const string propertyName = "ContactPersonTestBO.OrganisationID";

            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses);
            DataTable        table           = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(3, table.Rows.Count);
            Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]);
            //---------------Execute Test ----------------------
            table.Rows[0][propertyName] = organisation.OrganisationID;
            //---------------Test Result -----------------------
            Assert.AreEqual(organisation.OrganisationID, table.Rows[0][propertyName]);
            Assert.AreEqual(organisation.OrganisationID, addresses[0].ContactPersonTestBO.OrganisationID);
            recordingExceptionNotifier.RethrowRecordedException();
        }
Ejemplo n.º 11
0
        public void Test_EditDataTable_WhenVirtualProp_ShouldEditRelatedVirtualProp()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();

            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection <ContactPersonTestBO>();

            contactPersonTestBOS.Add(new ContactPersonTestBO(), new ContactPersonTestBO(), new ContactPersonTestBO());

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid uiGrid = new UIGrid();

            new UIDef("fdafdas", new UIForm(), uiGrid)
            {
                ClassDef = contactPersonClassDef
            };
            const string propertyName = "-Organisation-";

            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS);
            DataTable        table           = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(3, table.Rows.Count);
            Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]);
            Assert.AreEqual(null, contactPersonTestBOS[0].Organisation);
            //---------------Execute Test ----------------------
            table.Rows[0][propertyName] = organisation;
            //---------------Test Result -----------------------
            Assert.AreSame(organisation, table.Rows[0][propertyName]);
            Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation);
            recordingExceptionNotifier.RethrowRecordedException();
        }
Ejemplo n.º 12
0
        public void Test_LoadObject_SingleRelationship_UpdatedObjectMan_Generic()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            ContactPersonTestBO cp      = CreateSavedCP();
            AddressTestBO       address = new AddressTestBO();

            address.ContactPersonID = cp.ContactPersonID;
            address.Save();

            IPrimaryKey contactPersonID = cp.ID;
            IPrimaryKey addresssID      = address.ID;

            cp      = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);

            //---------------Execute Test ----------------------
            AddressTestBO       loadedAddress = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <AddressTestBO>(addresssID);
            ContactPersonTestBO loadedCP      = loadedAddress.ContactPersonTestBO;

            //---------------Test Result -----------------------
            Assert.AreEqual(2, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.IsTrue(boMan.Contains(contactPersonID));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.GetObjectId()));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]);
        }
        public void Test_AutoLoadingMapper_WhenCreateFromControlMapper_ShouldSetupCollection()
        {
            //---------------Set up test pack-------------------
            var cmbox = _controlFactory.CreateComboBox();
            var controlMapper = ControlMapper.Create
                ("AutoLoadingRelationshipComboBoxMapper", "Habanero.Faces.Base", cmbox, "ContactPersonTestBO", false,
                 GetControlFactory());

            var person1 = ContactPersonTestBO.CreateSavedContactPerson();
            var person2 = ContactPersonTestBO.CreateSavedContactPerson();

            var addressTestBo = new AddressTestBO();

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

            //---------------Execute Test ----------------------
            controlMapper.BusinessObject = addressTestBo;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsTrue(cmbox.Items.Contains(person1));
            Assert.IsTrue(cmbox.Items.Contains(person2));
        }
Ejemplo n.º 14
0
        public static void DropNewContactPersonAndAddressTables()
        {
            if (ClassDef.ClassDefs.Count > 0 && (ClassDef.ClassDefs.Contains("Habanero.Test.BO", "AddressTestBO")))
            {
                var    classDef = ClassDef.Get <AddressTestBO>();
                string defaultCpAddressTableName = "contact_person_address";
                if (classDef.TableName.ToLower() != defaultCpAddressTableName)
                {
                    AddressTestBO.DropCpAddressTable(classDef.TableName);
                }
            }

            if (ClassDef.ClassDefs.Count > 0 && (ClassDef.ClassDefs.Contains("Habanero.Test.BO", "ContactPersonTestBO")))
            {
                var    classDef = ClassDef.Get <ContactPersonTestBO>();
                string defaultContactPersonTableName = "contact_person";
                if (classDef.TableName.ToLower() != defaultContactPersonTableName)
                {
                    ContactPersonTestBO.DropContactPersonTable(classDef.TableName);
                }
            }
        }
        public void Test_AutoLoadingMapper_WhenConstructNormally_ShouldSetupCollection()
        {
            //---------------Set up test pack-------------------
            var cmbox = _controlFactory.CreateComboBox();
            var controlMapper = GetMapper(cmbox, "ContactPersonTestBO");

            var person1 = ContactPersonTestBO.CreateSavedContactPerson();
            var person2 = ContactPersonTestBO.CreateSavedContactPerson();

            var addressTestBo = new AddressTestBO();

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

            //---------------Execute Test ----------------------
            controlMapper.BusinessObject = addressTestBo;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsTrue(cmbox.Items.Contains(person1));
            Assert.IsTrue(cmbox.Items.Contains(person2));
        }
        public override void Test_ApplyChangesToBusinessObject_WhenNewItemIsSelected_WhenSet_WhenRelationshipIsLevelsDeep_ShouldUpdateRelatedBusinessObjectWithSelectedValue()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            AddressTestBO.LoadDefaultClassDef();

            const string relationshipName = "ContactPersonTestBO.Organisation";
            var mapper = GetMapperBoColHasOneItem(relationshipName);
            var cmbox = mapper.Control;
            var boCol = (BusinessObjectCollection<OrganisationTestBO>)mapper.BusinessObjectCollection;
            var person = new ContactPersonTestBO { Organisation = boCol[0] };
            var addressTestBO = new AddressTestBO { ContactPersonTestBO = person };
            
            var newOrganisation = new OrganisationTestBO();
            newOrganisation.Save();
            mapper.BusinessObject = addressTestBO;
            //---------------Assert Precondition----------------
            Assert.AreSame(addressTestBO, mapper.BusinessObject);
            Assert.AreSame(person.Organisation, cmbox.SelectedItem);
            Assert.AreNotSame(person.Organisation, newOrganisation);
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = newOrganisation;
            Assert.AreSame(newOrganisation, cmbox.SelectedItem, "Selected Item should be set.");
            mapper.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreSame(newOrganisation, cmbox.SelectedItem);
            Assert.AreSame(newOrganisation, person.Organisation);
        }
 private static ContactPersonTestBO CreateSavedCP_WithOneAddresss(out AddressTestBO address)
 {
     var cp = CreateSavedCP();
     address = new AddressTestBO {ContactPersonID = cp.ContactPersonID};
     address.Save();
     return cp;
 }
        public void Test_LoadObject_SingleRelationship_UpdatedObjectMan_Generic()
        {
            //---------------Set up test pack-------------------
            LoadContactPersonAndAddressClassDef();

            var boMan = BusinessObjectManager.Instance;

            var cp = CreateSavedCP();
            var address = new AddressTestBO {ContactPersonID = cp.ContactPersonID};
            address.Save();

            var contactPersonID = cp.ID;
            var addresssID = address.ID;
            cp = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);

            //---------------Execute Test ----------------------
            var loadedAddress = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<AddressTestBO>
                (addresssID);
            var loadedCP = loadedAddress.ContactPersonTestBO;

            //---------------Test Result -----------------------
            Assert.IsNotNull(loadedCP);
            Assert.AreEqual(2, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.IsTrue(boMan.Contains(contactPersonID));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.ObjectID));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.ObjectID]);
        }
 public void Test_GetRelatedBusinessObject_WhenRelationshipIsLevelsDeep_ShouldReturnCorrectBO()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
     OrganisationTestBO.LoadDefaultClassDef();
     AddressTestBO.LoadDefaultClassDef();
     const string relationshipName = "ContactPersonTestBO.Organisation";
     RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(relationshipName);
     BusinessObjectCollection<OrganisationTestBO> boCol = (BusinessObjectCollection<OrganisationTestBO>)mapper.BusinessObjectCollection;
     ContactPersonTestBO person = new ContactPersonTestBO();
     person.Organisation = boCol[0];
     AddressTestBO addressTestBO = new AddressTestBO { ContactPersonTestBO = person };
     mapper.BusinessObject = addressTestBO;
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, boCol.Count);
     //---------------Execute Test ----------------------
     IBusinessObject relatedBO = mapper.GetRelatedBusinessObject();
     //---------------Test Result -----------------------
     Assert.AreSame(person.Organisation, relatedBO);
 }
 private static ContactPersonTestBO CreateContactPersonWithOneAddress(out AddressTestBO address)
 {
     var tableNameExtension = TestUtil.GetRandomString();
     BOTestUtils.CreateContactPersonTable(tableNameExtension);
     BOTestUtils.CreateAddressTable(tableNameExtension);
     return ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, tableNameExtension);
 }
 public void Test_BusinessObject_WhenSet_WhenRelationshipIsLevelsDeep_ShouldSelectRelatedItemInComboBox()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
     OrganisationTestBO.LoadDefaultClassDef();
     AddressTestBO.LoadDefaultClassDef();
     const string relationshipName = "ContactPersonTestBO.Organisation";
     RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(relationshipName);
     IComboBox cmbox = mapper.Control;
     BusinessObjectCollection<OrganisationTestBO> boCol = (BusinessObjectCollection<OrganisationTestBO>)mapper.BusinessObjectCollection;
     ContactPersonTestBO person = new ContactPersonTestBO { Organisation = boCol[0] };
     AddressTestBO addressTestBO = new AddressTestBO { ContactPersonTestBO = person };
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, boCol.Count);
     Assert.IsNull(cmbox.SelectedItem);
     Assert.IsFalse(mapper.Control.Enabled);
     //---------------Execute Test ----------------------
     mapper.BusinessObject = addressTestBO;
     //---------------Test Result -----------------------
     Assert.AreSame(addressTestBO, mapper.BusinessObject);
     Assert.IsTrue(mapper.Control.Enabled);
     Assert.IsNotNull(cmbox.SelectedItem);
     Assert.AreSame(person.Organisation, cmbox.SelectedItem);
 }
Ejemplo n.º 22
0
        public void Test_LoadObject_SingleRelationship_UpdatedObjectMan_Generic()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            ContactPersonTestBO cp = CreateSavedCP();
            AddressTestBO address = new AddressTestBO();
            address.ContactPersonID = cp.ContactPersonID;
            address.Save();

            IPrimaryKey contactPersonID = cp.ID;
            IPrimaryKey addresssID = address.ID;
            cp = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);

            //---------------Execute Test ----------------------
            AddressTestBO loadedAddress = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<AddressTestBO>(addresssID);
            ContactPersonTestBO loadedCP = loadedAddress.ContactPersonTestBO;

            //---------------Test Result -----------------------
            Assert.AreEqual(2, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.IsTrue(boMan.Contains(contactPersonID));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.GetObjectId()));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]);
        }
Ejemplo n.º 23
0
 public static AddressTestBO CreateUnsavedAddress(ContactPersonTestBO contactPerson, string firstLine)
 {
     AddressTestBO address = new AddressTestBO();
     address.ContactPersonTestBO = contactPerson;
     address.AddressLine1 = firstLine;
     return address;
 }
 public void Test_RelatedObjectChanged_WhenRelatedObjectPathChanged_WhenRelationshipMultipleLevelsDeep_ShouldUpdate()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
     OrganisationTestBO.LoadDefaultClassDef();
     AddressTestBO.LoadDefaultClassDef();
     const string relationshipName = "ContactPersonTestBO.Organisation";
     RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(relationshipName);
     IComboBox cmbox = mapper.Control;
     BusinessObjectCollection<OrganisationTestBO> boCol = (BusinessObjectCollection<OrganisationTestBO>)mapper.BusinessObjectCollection;
     ContactPersonTestBO person = new ContactPersonTestBO();
     person.Organisation = boCol[0];
     OrganisationTestBO newOrganisation = boCol.CreateBusinessObject();
     ContactPersonTestBO newPerson = new ContactPersonTestBO { Organisation = newOrganisation };
     AddressTestBO addressTestBO = new AddressTestBO { ContactPersonTestBO = person };
     mapper.BusinessObject = addressTestBO;
     //---------------Assert Precondition----------------
     Assert.AreEqual(2, boCol.Count);
     Assert.AreNotSame(newOrganisation, cmbox.SelectedItem);
     //---------------Execute Test ----------------------
     addressTestBO.ContactPersonTestBO = newPerson;
     //---------------Test Result -----------------------
     Assert.AreSame(newOrganisation, cmbox.SelectedItem);
 }
        public void Test_LoadObject_MulitpleRelationship_UpdatedObjectMan_Generic()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            var tableNameExt = CreateContactPersonAndAddressTables();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteDoNothing(tableNameExt);
            var boMan = BusinessObjectManager.Instance;

            var cp = CreateSavedCP();
            var address = new AddressTestBO();
            cp.Addresses.Add(address);
            address.Save();

            var contactPersonID = cp.ID;
            var addresssID = address.ID;
            cp = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);

            //---------------Execute Test ----------------------
            var loadedCP =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPersonTestBO>(contactPersonID);
            var addresses = loadedCP.Addresses;

            //---------------Test Result -----------------------
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(2, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            var loadedAddress = addresses[0];

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.ObjectID));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.ObjectID]);
        }