public void Test_AddPersistedObject_AddsTo_AddedCollection() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); AddressTestBO address; ContactPersonTestBO.CreateContactPersonWithOneAddressTestBO(out address); ContactPersonTestBO newContactPerson = new ContactPersonTestBO(); RelatedBusinessObjectCollection <AddressTestBO> addressTestBOS = newContactPerson.AddressTestBOs; //---------------Assert Precondition---------------- Assert.AreEqual(0, addressTestBOS.AddedBusinessObjects.Count); Assert.AreEqual(0, addressTestBOS.Count); Assert.AreEqual(0, addressTestBOS.PersistedBusinessObjects.Count); //---------------Execute Test ---------------------- addressTestBOS = newContactPerson.AddressTestBOs; addressTestBOS.Add(address); //---------------Test Result ----------------------- Assert.AreEqual(1, addressTestBOS.AddedBusinessObjects.Count); Assert.AreEqual(0, addressTestBOS.CreatedBusinessObjects.Count); Assert.AreEqual(1, addressTestBOS.Count); Assert.AreEqual(0, addressTestBOS.PersistedBusinessObjects.Count); }
public void Test_AddPersistedObject_AddsObjectToCollection_SurvivesRefresh() { //---------------Set up test pack------------------- //The Foreign Key (address.ContactPersonId) should be set up to be // equal to the contactPerson.ContactPersonID //Test that using relationship from contact person so that overcome issues // with reloading all the time. ClassDef.ClassDefs.Clear(); AddressTestBO address; ContactPersonTestBO.CreateContactPersonWithOneAddressTestBO(out address); ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); RelatedBusinessObjectCollection <AddressTestBO> addressTestBOS = contactPersonTestBO.AddressTestBOs; addressTestBOS.Add(address); //---------------Assert Precondition---------------- Assert.AreEqual(1, addressTestBOS.AddedBusinessObjects.Count); Assert.AreEqual(1, addressTestBOS.Count); Assert.AreEqual(0, addressTestBOS.PersistedBusinessObjects.Count); //---------------Execute Test ---------------------- addressTestBOS.Refresh(); //---------------Test Result ----------------------- Assert.AreEqual(1, addressTestBOS.AddedBusinessObjects.Count); Assert.AreEqual(1, addressTestBOS.Count); Assert.AreEqual(0, addressTestBOS.PersistedBusinessObjects.Count); }
public void Test_AddPersistedObject_AddsObjectToCollection_SetsUpForeignKey() { //---------------Set up test pack------------------- //The Foreign Key (address.ContactPersonId) should be set up to be // equal to the contactPerson.ContactPersonID //SetupTests // ContactPersonTestBO.LoadClassDefWithAddresBOsRelationship_AddressReverseRelationshipConfigured(); //Run tests ClassDef.ClassDefs.Clear(); AddressTestBO address; ContactPersonTestBO.CreateContactPersonWithOneAddressTestBO(out address); ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); //---------------Assert Precondition---------------- Assert.AreEqual(0, contactPersonTestBO.AddressTestBOs.CreatedBusinessObjects.Count); Assert.AreEqual(0, contactPersonTestBO.AddressTestBOs.Count); Assert.AreEqual(0, contactPersonTestBO.AddressTestBOs.PersistedBusinessObjects.Count); Assert.IsNotNull(address.ContactPersonTestBO); Assert.IsNotNull(address.ContactPersonID); //---------------Execute Test ---------------------- RelatedBusinessObjectCollection <AddressTestBO> addressTestBOS = contactPersonTestBO.AddressTestBOs; addressTestBOS.Add(address); //---------------Test Result ----------------------- Assert.AreEqual(0, addressTestBOS.CreatedBusinessObjects.Count); Assert.AreEqual(1, addressTestBOS.AddedBusinessObjects.Count); Assert.AreEqual(1, addressTestBOS.Count); Assert.AreEqual(0, addressTestBOS.PersistedBusinessObjects.Count); Assert.AreEqual(contactPersonTestBO.ContactPersonID, address.ContactPersonID); Assert.AreSame(contactPersonTestBO, address.ContactPersonTestBO); }
public void Test_LoadedBo_Add() { //-----Create Test pack--------------------- ContactPersonTestBO cp; RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation()); //--------------Assert Preconditions-------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); //-----Run tests---------------------------- cpCol.Add(cp); ////-----Test results------------------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); }
public void Test_CreatedBusinessObject_Add() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol(); ContactPersonTestBO newCP = cpCol.CreateBusinessObject(); newCP.Surname = TestUtil.GetRandomString(); RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- AssertOneObjectInCurrentAndCreatedCollection(cpCol); //---------------Execute Test ---------------------- cpCol.Add(newCP); //---------------Test Result ----------------------- AssertOneObjectInCurrentAndCreatedCollection(cpCol); AssertAddedAndRemovedEventsNotFired(); }
public void Test_NewBusObject_Added() { //Test add new business object adds to created collection and sets the foreign key fields //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo = new MyBO(); IMultipleRelationship rel = bo.Relationships.GetMultiple("MyMultipleRelationship"); RelatedBusinessObjectCollection <MyRelatedBo> col = new RelatedBusinessObjectCollection <MyRelatedBo>(rel); MyRelatedBo relatedBo = new MyRelatedBo(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- col.Add(relatedBo); //---------------Test Result ----------------------- Assert.AreEqual(bo.MyBoID, relatedBo.MyBoID, "The foreign key should eb set"); Assert.IsTrue(relatedBo.Status.IsNew); Assert.AreEqual(1, col.CreatedBusinessObjects.Count, "The created BOs should be added"); Assert.AreEqual(1, col.Count); Assert.AreEqual(0, col.AddedBusinessObjects.Count); }
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"); }
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(); }
public void TestAddMethod_Refresh_LoadWithCriteria_BusinessObject() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); cpCol.Load("Surname='bbb'", ""); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("aaa"); cpCol.Add(myBO); util.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- cpCol.Refresh(); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); }
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 Test_AddMethod() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = new ContactPersonTestBO(); util.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- util.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsFalse(util.AddedEventFired); //---------------Execute Test ---------------------- cpCol.Add(myBO); //---------------Test Result ----------------------- Assert.AreEqual(1, cpCol.Count, "One object should be in the cpCollection"); Assert.IsTrue(util.AddedEventFired); Assert.AreEqual(myBO, cpCol[0], "Added object should be in the cpCollection"); }
public void Test_MarkForDelete_Added_RestoreAll() { //---------------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.CancelEdits(); //---------------Test Result ----------------------- util.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsFalse(myBO.Status.IsDirty); util.AssertAddedEventFired(); util.AssertRemovedEventFired(); }
//TODO Mark 09 Mar 2009: Ignored Test - This needs to be reviewed with the cancellation and persistance philosophy public void Test_MarkForDelete_Added_RestoreBO() { //---------------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); util.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- myBO.CancelEdits(); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); util.AssertAddedEventFired(); Assert.IsFalse (myBO.Status.IsDirty, "Should be dirty since is readded to collection when cancel edits called"); //TODO: test that mybo.orgid set correctly. util.AssertRemovedEventNotFired(); }
public void Test_Add_PersistedBOs() { //---------------Set up test pack------------------- //The persisted business objects should not be added since this is a normal cpCollection which does not // modify the added objects alternate key etc unlike the RelatedBusinessObjectCollection OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO> (organisationTestBO.Relationships["ContactPeople"]); ContactPersonTestBO myBO = CreateSavedContactPerson(); ContactPersonTestBO myBO2 = CreateSavedContactPerson(); ContactPersonTestBO myBO3 = CreateSavedContactPerson(); util.RegisterForAddedEvent(cpCol); //-------Assert Preconditions Assert.AreEqual(0, cpCol.Count, "Three objects should be in the cpCollection"); //---------------Execute Test ---------------------- cpCol.Add(myBO, myBO2, myBO3); //---------------Test Result ----------------------- - Result Assert.AreEqual(3, cpCol.Count, "Three objects should be in the copied cpCollection"); Assert.AreEqual (3, cpCol.AddedBusinessObjects.Count, "The persisted business objects should not be in the AddedList since this is a normal cpCollection which does not modify the added objects alternate key etc unlike the RelatedBusinessObjectCollection"); Assert.IsTrue(util.AddedEventFired); }
public void Test_AddMethod_WithParamArray() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = new ContactPersonTestBO(); ContactPersonTestBO myBO2 = new ContactPersonTestBO(); ContactPersonTestBO myBO3 = new ContactPersonTestBO(); //---------------Execute Test ---------------------- cpCol.Add(myBO, myBO2, myBO3); //---------------Test Result ----------------------- Assert.AreEqual(3, cpCol.Count, "Three objects should be in the cpCollection"); Assert.AreEqual(myBO, cpCol[0], "Added object should be in the cpCollection"); Assert.AreEqual(myBO2, cpCol[1], "Added object should be in the cpCollection"); Assert.AreEqual(myBO3, cpCol[2], "Added object should be in the cpCollection"); }
public void Test_AddMethod_WithCollection() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = new ContactPersonTestBO(); ContactPersonTestBO myBO2 = new ContactPersonTestBO(); ContactPersonTestBO myBO3 = new ContactPersonTestBO(); cpCol.Add(myBO, myBO2, myBO3); //-------Assert Preconditions Assert.AreEqual(3, cpCol.Count, "Three objects should be in the cpCollection"); //---------------Execute Test ---------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpColCopied = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); cpColCopied.Add(cpCol); //---------------Test Result ----------------------- - Result Assert.AreEqual(3, cpColCopied.Count, "Three objects should be in the copied cpCollection"); Assert.AreEqual(3, cpColCopied.CreatedBusinessObjects.Count); Assert.AreEqual(0, cpColCopied.AddedBusinessObjects.Count); Assert.AreEqual(myBO, cpColCopied[0], "Added object should be in the copied cpCollection"); Assert.AreEqual(myBO2, cpColCopied[1], "Added object should be in the copied cpCollection"); Assert.AreEqual(myBO3, cpColCopied[2], "Added object should be in the copied cpCollection"); }
public void Test_AddMethod_WithEnumerable_List() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = new ContactPersonTestBO(); ContactPersonTestBO myBO2 = new ContactPersonTestBO(); ContactPersonTestBO myBO3 = new ContactPersonTestBO(); List<ContactPersonTestBO> list = new List<ContactPersonTestBO>(); list.Add(myBO); list.Add(myBO2); list.Add(myBO3); //---------------Execute Test ---------------------- cpCol.Add(list); //---------------Test Result ----------------------- Assert.AreEqual(3, cpCol.Count, "Three objects should be in the cpCollection"); Assert.AreEqual(myBO, cpCol[0], "Added object should be in the cpCollection"); Assert.AreEqual(myBO2, cpCol[1], "Added object should be in the cpCollection"); Assert.AreEqual(myBO3, cpCol[2], "Added object should be in the cpCollection"); Assert.IsNotNull(myBO3.OrganisationID); Assert.IsNotNull(myBO2.OrganisationID); Assert.IsNotNull(myBO.OrganisationID); }
public void Test_Add_PersistedBO_AddsToAddedCollection() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO newCP = ContactPersonTestBO.CreateUnsavedContactPerson (BOTestUtils.RandomString, BOTestUtils.RandomString); newCP.Save(); util.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- util.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsNull(newCP.OrganisationID); //---------------Execute Test ---------------------- cpCol.Add(newCP); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.Contains(newCP, cpCol); Assert.IsTrue(util.AddedEventFired); Assert.IsNotNull(newCP.OrganisationID); }
public void Test_Add_NullBO() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); const ContactPersonTestBO newCP = null; util.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- util.AssertAllCollectionsHaveNoItems(cpCol); //---------------Execute Test ---------------------- try { cpCol.Add(newCP); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (ArgumentNullException ex) { StringAssert.Contains("Value cannot be null", ex.Message); } //---------------Test Result ----------------------- }
public void TestAddMethod_MarkForDeleteAddedBusinessObject() { //---------------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.MarkForDelete(myBO); //---------------Test Result ----------------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertRemovedEventFired(); }
public void TestAddMethod_PersistedObject_IgnoresAddWhenItemAlreadyExists() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); util.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(util.AddedEventFired); //---------------Execute Test ---------------------- cpCol.Add(myBO); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(util.AddedEventFired); }
public void Test_MarkForDelete_Added_LoadWCriteria_RefreshAll() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); cpCol.Load("Surname=cc", ""); 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.Refresh(); //---------------Test Result ----------------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); }
public void TestAddMethod_SaveAllBusinessObject() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); util.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); Assert.IsFalse(util.AddedEventFired); //---------------Execute Test ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentPersistedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); Assert.IsFalse(util.AddedEventFired); }
public void Test_MarkForDelete_Added_BO_MarkForDelete() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB"); cpCol.Add(myBO); myBO.MarkForDelete(); //---------------Assert Precondition---------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- myBO.MarkForDelete(); //---------------Test Result ----------------------- util.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); }
public void TestAddMethod_RestoreBusinessObject() { //---------------Set up test pack------------------- RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); util.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); Assert.IsNotNull(myBO.OrganisationID); //---------------Execute Test ---------------------- myBO.CancelEdits(); //---------------Test Result ----------------------- util.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); util.AssertAddedAndRemovedEventsNotFired(); Assert.IsNull(myBO.OrganisationID); }
public void Test_Add_PersistedBO_RestoreAll() { //---------------Set up test pack------------------- //The persisted objects are added to the added cpCollection // when restore is called the added objects should be removed from the cpCollection. RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol = new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship()); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); ContactPersonTestBO myBO2 = ContactPersonTestBO.CreateSavedContactPerson(); ContactPersonTestBO myBO3 = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO, myBO2, myBO3); util.RegisterForRemovedEvent(cpCol); //-------Assert Preconditions Assert.AreEqual(3, cpCol.Count, "Three objects should be in the copied cpCollection"); Assert.AreEqual(3, cpCol.AddedBusinessObjects.Count, "Three objects should be in the cpCollection"); Assert.IsFalse(util.RemovedEventFired); Assert.IsNotNull(myBO.OrganisationID); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- cpCol.CancelEdits(); //---------------Test Result ----------------------- - Result util.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsNull(myBO.OrganisationID); Assert.IsTrue(util.RemovedEventFired); }
public void Test_NewBusObject_Added() { //Test add new business object adds to created collection and sets the foreign key fields //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo = new MyBO(); IMultipleRelationship rel = bo.Relationships.GetMultiple("MyMultipleRelationship"); RelatedBusinessObjectCollection<MyRelatedBo> col = new RelatedBusinessObjectCollection<MyRelatedBo>(rel); MyRelatedBo relatedBo = new MyRelatedBo(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- col.Add(relatedBo); //---------------Test Result ----------------------- Assert.AreEqual(bo.MyBoID, relatedBo.MyBoID, "The foreign key should eb set"); Assert.IsTrue(relatedBo.Status.IsNew); Assert.AreEqual(1, col.CreatedBusinessObjects.Count, "The created BOs should be added"); Assert.AreEqual(1, col.Count); Assert.AreEqual(0, col.AddedBusinessObjects.Count); }