public void Test_ReturnSameObjectFromBusinessObjectLoader() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO originalContactPerson = CreateSavedCP(); IPrimaryKey id = originalContactPerson.ID; originalContactPerson = null; boMan.ClearLoadedObjects(); TestUtil.WaitForGC(); //load second object from DB to ensure that it is now in the object manager ContactPersonTestBO myContact2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(id); //---------------Assert Precondition---------------- Assert.AreNotSame(originalContactPerson, myContact2); //---------------Execute Test ---------------------- ContactPersonTestBO myContact3 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(id); //---------------Test Result ----------------------- Assert.AreNotSame(originalContactPerson, myContact3); Assert.AreSame(myContact2, myContact3); }
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()]); }
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()]); }