public void Test_LoadObject_UpdateObjectMan_NonGenericLoad() { //---------------Set up test pack------------------- ClassDef classDef = ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = CreateSavedCP(); IPrimaryKey id = cp.ID; cp = null; TestUtil.WaitForGC(); boMan.ClearLoadedObjects(); //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Test ---------------------- ContactPersonTestBO contactPersonTestBO = (ContactPersonTestBO)BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject(classDef, id); //---------------Test Result ----------------------- Assert.IsNotNull(contactPersonTestBO); Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(contactPersonTestBO)); Assert.IsTrue(boMan.Contains(id)); Assert.IsTrue(boMan.Contains(id.GetObjectId())); Assert.AreSame(contactPersonTestBO, boMan[id.GetObjectId()]); Assert.AreSame(contactPersonTestBO, boMan[id]); }
public T GetBusinessObject <T>(IPrimaryKey key) where T : class, IBusinessObject { if (BusinessObject.AllLoadedBusinessObjects().ContainsKey(key.GetObjectId())) { return((T)BusinessObject.AllLoadedBusinessObjects()[key.GetObjectId()].Target); } else { return((T)BOLoader.Instance.GetBusinessObjectByID(typeof(T), key)); } }
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()]); }
public void Test_LoadObject_ViaCollection_UpdatedObjectMan_Generic() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = CreateSavedCP(); Guid contactPersonId = cp.ContactPersonID; IPrimaryKey id = cp.ID; cp = null; TestUtil.WaitForGC(); boMan.ClearLoadedObjects(); //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Test ---------------------- Criteria criteria = new Criteria("ContactPersonID", Criteria.ComparisonOp.Equals, contactPersonId); IBusinessObjectCollection colContactPeople = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <ContactPersonTestBO>(criteria); //---------------Test Result ----------------------- Assert.AreEqual(1, colContactPeople.Count); IBusinessObject loadedCP = colContactPeople[0]; Assert.IsNotNull(loadedCP); Assert.AreNotSame(cp, loadedCP); Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(loadedCP)); Assert.IsTrue(boMan.Contains(id)); Assert.IsTrue(boMan.Contains(id.GetObjectId())); Assert.AreSame(loadedCP, boMan[id]); Assert.AreSame(loadedCP, boMan[id.GetObjectId()]); }