public void Test_Add_CopyOfSameObjectTwiceShould_ThrowError() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); BusinessObjectManager boMan = BusinessObjectManager.Instance; boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); //---------------Execute Test ---------------------- ContactPersonTestBO cp2 = new ContactPersonTestBO(); cp2.ContactPersonID = cp.ContactPersonID; try { boMan.Add(cp2); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("There was a serious developer exception. Two copies of the business object", ex.Message); StringAssert.Contains(" were added to the object manager", ex.Message); } }
public void Test_AddSameObjectTwiceShouldNotCauseError() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); BusinessObjectManager boMan = BusinessObjectManager.Instance; cp.Surname = TestUtil.CreateRandomString(); boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); //---------------Execute Test ---------------------- boMan.Add(cp); //---------------Test Result ----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.IsTrue(boMan.Contains(cp.ID)); Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId())); Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]); Assert.AreSame(cp, boMan[cp.ID]); }
public void Test_RemoveFromObjectManager() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = new ContactPersonTestBO(); cp.Surname = TestUtil.CreateRandomString(); boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); //---------------Execute Test ---------------------- boMan.Remove(cp); //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); Assert.IsFalse(boMan.Contains(cp)); }
public void Test_ObjectDestructor_RemovesFromObjectManager() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = new ContactPersonTestBO(); boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.IsTrue(boMan.Contains(cp.ID)); //---------------Execute Test ---------------------- cp = null; TestUtil.WaitForGC(); //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); }
public void Test_ObjectManagerIndexers() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = new ContactPersonTestBO(); boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); //---------------Execute Test ---------------------- IBusinessObject boFromObjMan_StringID = boMan[cp.ID.GetObjectId()]; IBusinessObject boFromMan_ObjectID = boMan[cp.ID]; //---------------Test Result ----------------------- Assert.AreSame(cp, boFromObjMan_StringID); Assert.AreSame(cp, boFromMan_ObjectID); }