public void TestRemoveAddress_AlreadyInRemoveCollection() { //-----Create Test pack--------------------- ClassDef.ClassDefs.Clear(); AddressTestBO address; ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString()); RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses; //-----Run tests---------------------------- addresses.Remove(address); addresses.Remove(address); //-----Test results------------------------- Assert.AreEqual(1, addresses.RemovedBusinessObjects.Count); }
public void Test_RemoveCreatedBo_DeregistersForSaveEvent() { //If you remove a created business object that is not yet persisted then //-- remove from the restored and saved event. //-- when the object is saved it should be independent of the collection. //---------------Set up test pack------------------- RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(); ContactPersonTestBO createdCp = cpCol.CreateBusinessObject(); createdCp.Surname = BOTestUtils.RandomString; createdCp.FirstName = BOTestUtils.RandomString; cpCol.Remove(createdCp); RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsFalse(cpCol.Contains(createdCp)); //---------------Execute Test ---------------------- createdCp.Save(); //---------------Test Result ----------------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsFalse(cpCol.Contains(createdCp)); AssertAddedAndRemovedEventsNotFired(); }
public void TestRemoveRelatedObject_usingRelationship() { //-----Create Test pack--------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses(); AddressTestBO address = contactPersonTestBO.Addresses.CreateBusinessObject(); address.Save(); Assert.AreEqual(1, contactPersonTestBO.Addresses.Count); //------Assert Preconditions Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count); //-----Run tests---------------------------- RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses; addresses.Remove(address); ////-----Test results------------------------- Assert.AreEqual(1, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count); Assert.AreEqual(0, contactPersonTestBO.Addresses.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count); Assert.IsNull(address.ContactPersonTestBO); Assert.IsNull(address.ContactPersonID); }
public void Test_CreatedBo_Remove() { //If you remove a created business object that is not yet persisted then //-- remove from the restored and saved event. //---------------Set up test pack------------------- RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(); Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count); ContactPersonTestBO createdCp = cpCol.CreateBusinessObject(); createdCp.Surname = BOTestUtils.RandomString; createdCp.FirstName = BOTestUtils.RandomString; RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- Assert.IsTrue(cpCol.Contains(createdCp)); AssertTwoCurrentObjects_OnePsersisted_OneCreated(cpCol); //---------------Execute Test ---------------------- cpCol.Remove(createdCp); //---------------Test Result ----------------------- Assert.IsFalse(cpCol.Contains(createdCp)); AssertOneObjectInCurrentAndPersistedCollection(cpCol); AssertRemovedEventFired(); AssertAddedEventNotFired(); }
public void Test_Remove_AlreadyInRemoveCollection() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); _removedEventFired = false; cpCol.BusinessObjectRemoved += delegate { _removedEventFired = true; }; //--------------Assert Preconditions-------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); Assert.IsFalse(_removedEventFired); //-----Run tests---------------------------- cpCol.Remove(cp); //-----Test results------------------------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); Assert.IsFalse(_removedEventFired); }
public void Test_Remove_AddsToRemovedCollection() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); //--------------Assert Preconditions-------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsFalse(cp.Status.IsDirty); Assert.IsNotNull(cp.OrganisationID); //-----Run tests---------------------------- cpCol.Remove(cp); //-----Test results------------------------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); Assert.IsTrue(cp.Status.IsDirty, "Should be edited since the remove modifies the alternate key"); Assert.IsNull(cp.OrganisationID); }
public void Test_Remove_Add() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); //--------------Assert Preconditions-------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); //-----Run tests---------------------------- cpCol.Add(cp); ////-----Test results------------------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); }
public void Test_RemovedBOs_Refresh() { //---------------Set up test pack------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); //---------------Assert Precondition---------------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); Assert.AreEqual(0, cpCol.Count); //---------------Execute Test ---------------------- cpCol.Refresh(); //---------------Test Result ----------------------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); }
public void TestRemoveRelatedObject_SetsRemovedBO() { //-----Create Test pack--------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses(); RelatedBusinessObjectCollection <AddressTestBO> addresses1 = contactPersonTestBO.Addresses; AddressTestBO address = addresses1.CreateBusinessObject(); address.Save(); //-----Run tests---------------------------- RelatedBusinessObjectCollection <AddressTestBO> addresses = addresses1; addresses.Remove(address); ////-----Test results------------------------- Assert.AreSame(contactPersonTestBO, address.Relationships.GetSingle <ContactPersonTestBO>("ContactPersonTestBO").RemovedBO); }
public void Test_Remove_Save() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); //--------------Assert Preconditions-------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); //-----Run tests---------------------------- cp.Save(); ////-----Test results------------------------- AssertAllCollectionsHaveNoItems(cpCol); Assert.IsFalse(cp.Status.IsDirty); Assert.IsNull(cp.OrganisationID); }
public void Test_Remove_Restore() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); _addedEventFired = false; cpCol.BusinessObjectAdded += delegate { _addedEventFired = true; }; //--------------Assert Preconditions-------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); Assert.IsFalse(_addedEventFired); Assert.IsNull(cp.OrganisationID); //-----Run tests---------------------------- cp.CancelEdits(); //-----Test results------------------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsTrue(_addedEventFired); Assert.IsNotNull(cp.OrganisationID); }
public void Test_Remove_Refresh() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); cpCol.Remove(cp); //--------------Assert Preconditions-------- AssertOneObjectInRemovedAndPersistedCollection(cpCol); //-----Run tests---------------------------- try { BORegistry.DataAccessor.BusinessObjectLoader.Refresh(cp); Assert.Fail("Expected to throw an HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("the object being refreshed is being edited", ex.Message); } }
public void Test_MarkForDeleteBO_Remove_RemovedNotFired() { //A Business object that exists in the collection can be marked for deletion either as a bo or // as an index in the collection //---------------Set up test pack------------------- RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(OrganisationTestBO.CreateSavedOrganisation()); ContactPersonTestBO markForDeleteCP = cpCol[0]; cpCol.MarkForDelete(markForDeleteCP); _removedEventFired = false; cpCol.BusinessObjectRemoved += delegate { _removedEventFired = true; }; //---------------Assert Precondition---------------- AssertOnePersisted_OneMarkForDelete(cpCol); Assert.IsFalse(_removedEventFired); //---------------Execute Test ---------------------- cpCol.Remove(markForDeleteCP); //---------------Test Result ----------------------- AssertOnePersisted_OneMarkForDelete(cpCol); Assert.IsTrue(markForDeleteCP.Status.IsDeleted); Assert.IsFalse(_removedEventFired); }
public void Test_MarkForDelete_Added_RemoveBO() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB"); cpCol.Add(myBO); myBO.MarkForDelete(); util.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- cpCol.Remove(myBO); //---------------Test Result ----------------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); }
public void TestAddMethod_Remove_Added_NonPersisted_BusinessObject() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateUnsavedContactPerson (TestUtil.GetRandomString(), TestUtil.GetRandomString()); cpCol.Add(myBO); util.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndCreatedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); Assert.IsNotNull(myBO.OrganisationID); //---------------Execute Test ---------------------- cpCol.Remove(myBO); //---------------Test Result ----------------------- util.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsTrue(myBO.Status.IsDirty); Assert.IsNull(myBO.OrganisationID); util.AssertRemovedEventFired(); util.AssertAddedEventNotFired(); }
Test_FixBug_AddMethod_RestoreNewRelationship_WhenObjectWasOnPreviousRelationshipShouldRestoreToPrevious() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); myBO.Save(); Guid? origionalOrganisationID = myBO.OrganisationID; OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); MultipleRelationship<ContactPersonTestBO> contactPeopleRel = organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople"); //RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol2 = new RelatedBusinessObjectCollection<ContactPersonTestBO>(contactPeopleRel); IBusinessObjectCollection cpCol2 = contactPeopleRel.CurrentBusinessObjectCollection; cpCol.Remove(myBO); cpCol2.Add(myBO); //---------------Assert Precondition---------------- util.AssertOneObjectInRemovedAndPersisted(cpCol); util.AssertOneObjectInCurrentAndAddedCollection(cpCol2); Assert.IsTrue(myBO.Status.IsDirty); // util.AssertAddedAndRemovedEventsNotFired(); Assert.AreEqual(organisationTestBO.OrganisationID, myBO.OrganisationID); Assert.AreNotEqual(origionalOrganisationID, myBO.OrganisationID); //---------------Execute Test ---------------------- contactPeopleRel.CancelEdits(); //---------------Test Result ----------------------- Assert.IsFalse(myBO.Status.IsDirty); // util.AssertAddedAndRemovedEventsNotFired(); Assert.AreNotEqual(organisationTestBO.OrganisationID, myBO.OrganisationID); Assert.AreEqual(origionalOrganisationID, myBO.OrganisationID); util.AssertOneObjectInCurrentPersistedCollection(cpCol); util.AssertAllCollectionsHaveNoItems(cpCol2); }
public void TestAddMethod_RemoveAddedBusinessObject() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); util.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- cpCol.Remove(myBO); //---------------Test Result ----------------------- util.AssertAllCollectionsHaveNoItems(cpCol); util.AssertRemovedEventFired(); util.AssertAddedEventNotFired(); Assert.IsFalse(myBO.Status.IsDirty, "The BO is no longer dirty since its FK Prop has been reverted by the remove"); }