Esempio n. 1
0
        public void TestRemoveRelatedObject_PersistColToDataStore_usingRelationshipRefreshing()
        {
            //-----Create Test pack---------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO address;

            BORegistry.DataAccessor = new DataAccessorInMemory();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());

            //-----Assert Precondition------------------
            Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, contactPersonTestBO.Addresses.Count);

            //-----Run tests----------------------------
            //Run tests
            BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;

            addresses.Remove(address);
            addresses.SaveAll();

            ////-----Test results-------------------------
            Assert.IsFalse(address.Status.IsDirty);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count);

            Assert.AreEqual(0, contactPersonTestBO.Addresses.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count);
        }
        protected static ContactPersonTestBO CreateRemovedChild(BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            ContactPersonTestBO removedChild = CreateExistingChild(cpCol);

            cpCol.Remove(removedChild);
            return(removedChild);
        }
Esempio n. 3
0
        public void TestRemoveRelatedObject_AsBusinessObjectCollection()
        {
            //-----Create Test pack---------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            AddressTestBO       address             = contactPersonTestBO.Addresses.CreateBusinessObject();

            address.Save();
            //-------Assert Precondition ------------------------------------
            Assert.AreEqual(1, contactPersonTestBO.Addresses.Count);

            //-----Run tests----------------------------
            BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;

            addresses.Remove(address);

            ////-----Test results-------------------------
            Assert.AreEqual(1, addresses.RemovedBusinessObjects.Count);
            Assert.AreEqual(0, addresses.Count);
            Assert.IsNull(address.ContactPersonID);
            Assert.IsNull(address.ContactPersonTestBO);
//            Assert.IsTrue(address.Status.IsDeleted);
            Assert.AreEqual(1, addresses.PersistedBusinessObjects.Count);
        }
Esempio n. 4
0
        public void TestSerialiseDeserialiseBusinessObjectCollection_HavingAllCollections()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Structure.Car.LoadDefaultClassDef();
            OrganisationPerson.LoadDefaultClassDef();
            Person.LoadDefaultClassDef();
            BusinessObjectCollection <Person> originalPeople = new BusinessObjectCollection <Person>();
            Person persistedPerson = originalPeople.CreateBusinessObject();
            Person deletedPerson   = originalPeople.CreateBusinessObject();
            Person removedPerson   = originalPeople.CreateBusinessObject();

            originalPeople.SaveAll();

            originalPeople.Remove(removedPerson);
            deletedPerson.MarkForDelete();
            Person createdPerson = originalPeople.CreateBusinessObject();
            Person addedPerson   = new Person();

            addedPerson.Save();
            originalPeople.Add(addedPerson);

            IFormatter   formatter    = new BinaryFormatter();
            MemoryStream memoryStream = new MemoryStream();

            FixtureEnvironment.ClearBusinessObjectManager();
            //---------------Assert PreConditions---------------
            Assert.AreEqual(1, originalPeople.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.Count);

            //---------------Execute Test ----------------------
            formatter.Serialize(memoryStream, originalPeople);
            memoryStream.Seek(0, SeekOrigin.Begin);
            BusinessObjectCollection <Person> deserialisedPeople = (BusinessObjectCollection <Person>)formatter.Deserialize(memoryStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count);
            Assert.AreEqual(originalPeople.PersistedBusinessObjects.Count, deserialisedPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.CreatedBusinessObjects.Count, deserialisedPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.AddedBusinessObjects.Count, deserialisedPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.RemovedBusinessObjects.Count, deserialisedPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.MarkedForDeleteBusinessObjects.Count, deserialisedPeople.MarkedForDeleteBusinessObjects.Count);

            AssertPersonsAreEqual(deserialisedPeople.MarkedForDeleteBusinessObjects[0], deletedPerson);
            AssertPersonsAreEqual(deserialisedPeople.RemovedBusinessObjects[0], removedPerson);
            AssertPersonsAreEqual(deserialisedPeople.AddedBusinessObjects[0], addedPerson);
            AssertPersonsAreEqual(deserialisedPeople.PersistedBusinessObjects[0], persistedPerson);
            AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[0], createdPerson);
        }
Esempio n. 5
0
        public void Test_CreatedBO_Remove_DeregisteresFromRestoredEvent()
        {
            //If you remove a created business object that is not yet persisted then
            //-- remove from the restored and saved event.
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = BOTestUtils.RandomString;

            //---------------Assert Precondition----------------
            AssertTwoCurrentObjects_OnePsersisted_OneCreated(cpCol);
            Assert.IsTrue(cpCol.Contains(createdCp));

            //---------------Execute Test ----------------------
            cpCol.Remove(createdCp);
            createdCp.CancelEdits();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));
        }
        public override void Test_RemoveBOToCol_UpdatesItems()
        {
            //---------------Set up test pack-------------------
            IBOColSelectorControl colSelector = CreateSelector();
            MyBO myBO    = new MyBO();
            MyBO newMyBO = new MyBO();
            BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO> {
                myBO, newMyBO
            };

            colSelector.BusinessObjectCollection = collection;
            //---------------Assert Precondition----------------
            Assert.AreEqual
                (collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and one other");
            Assert.AreSame(myBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0)));
            Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(1)));
            //---------------Execute Test ----------------------
            collection.Remove(myBO);
            //---------------Test Result -----------------------
            Assert.AreEqual(ActualNumberOfRows(1), colSelector.NoOfItems, "The blank item and one other");
            Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0)));
        }
        public void Test_MarkForDelete_Added_RemoveBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB");

            cpCol.Add(myBO);
            myBO.MarkForDelete();
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);
            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);

            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
        public void TestAddMethod_RemoveAddedBusinessObject()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson();

            cpCol.Add(myBO);
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
            _businessObjectCollectionTestHelper.AssertAddedEventNotFired();
        }
Esempio n. 9
0
        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-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = 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 TestSerialiseDeserialiseBusinessObjectCollection_HavingAllCollections()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Structure.Car.LoadDefaultClassDef();
            OrganisationPerson.LoadDefaultClassDef();
            Person.LoadDefaultClassDef();
            BusinessObjectCollection<Person> originalPeople = new BusinessObjectCollection<Person>();
            Person persistedPerson = originalPeople.CreateBusinessObject();
            Person deletedPerson = originalPeople.CreateBusinessObject();
            Person removedPerson = originalPeople.CreateBusinessObject();
            originalPeople.SaveAll();

            originalPeople.Remove(removedPerson);
            deletedPerson.MarkForDelete();
            Person createdPerson = originalPeople.CreateBusinessObject();
            Person addedPerson = new Person();
            addedPerson.Save();
            originalPeople.Add(addedPerson);

            IFormatter formatter = new BinaryFormatter();
            MemoryStream memoryStream = new MemoryStream();
            FixtureEnvironment.ClearBusinessObjectManager();
            //---------------Assert PreConditions---------------       
            Assert.AreEqual(1, originalPeople.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.Count);

            //---------------Execute Test ----------------------
            formatter.Serialize(memoryStream, originalPeople);
            memoryStream.Seek(0, SeekOrigin.Begin);
            BusinessObjectCollection<Person> deserialisedPeople = (BusinessObjectCollection<Person>)formatter.Deserialize(memoryStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count);
            Assert.AreEqual(originalPeople.PersistedBusinessObjects.Count, deserialisedPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.CreatedBusinessObjects.Count, deserialisedPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.AddedBusinessObjects.Count, deserialisedPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.RemovedBusinessObjects.Count, deserialisedPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.MarkedForDeleteBusinessObjects.Count, deserialisedPeople.MarkedForDeleteBusinessObjects.Count);

            AssertPersonsAreEqual(deserialisedPeople.MarkedForDeleteBusinessObjects[0], deletedPerson);
            AssertPersonsAreEqual(deserialisedPeople.RemovedBusinessObjects[0], removedPerson);
            AssertPersonsAreEqual(deserialisedPeople.AddedBusinessObjects[0], addedPerson);
            AssertPersonsAreEqual(deserialisedPeople.PersistedBusinessObjects[0], persistedPerson);
            AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[0], createdPerson);

        }
 public void Test_Remove_UnsavedBusinessObjectFromCollection_CompositeKey()
 {
     //--------------- Set up test pack ------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
     ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp();
     BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
     Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);
     cpCol.Add(person);
     //--------------- Test Preconditions ----------------
     Assert.AreEqual(1, cpCol.Count);
     Assert.AreEqual(1, keyObjectHashTable.Count);
     Assert.IsTrue(cpCol.Contains(person));
     //--------------- Execute Test ----------------------
     cpCol.Remove(person);
     //--------------- Test Result -----------------------
     Assert.AreEqual(0, cpCol.Count);
     Assert.AreEqual(0, keyObjectHashTable.Count);
 }
        public void Test_MarkForDelete_Added_RemoveBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();

            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB");
            cpCol.Add(myBO);
            myBO.MarkForDelete();
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);
            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);

            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
        public void TestAddMethod_RemoveAddedBusinessObject()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson();
            cpCol.Add(myBO);
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
            _businessObjectCollectionTestHelper.AssertAddedEventNotFired();
        }
 public override void Test_RemoveBOToCol_UpdatesItems()
 {
     //---------------Set up test pack-------------------
     IBOColSelectorControl colSelector = CreateSelector();
     MyBO myBO = new MyBO();
     MyBO newMyBO = new MyBO();
     BusinessObjectCollection<MyBO> collection = new BusinessObjectCollection<MyBO> {myBO, newMyBO};
     colSelector.BusinessObjectCollection = collection;
     //---------------Assert Precondition----------------
     Assert.AreEqual
         (collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and one other");
     Assert.AreSame(myBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0)));
     Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(1)));
     //---------------Execute Test ----------------------
     collection.Remove(myBO);
     //---------------Test Result -----------------------
     Assert.AreEqual(ActualNumberOfRows(1), colSelector.NoOfItems, "The blank item and one other");
     Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0)));
 }
 protected static ContactPersonTestBO CreateRemovedChild(BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     ContactPersonTestBO removedChild = CreateExistingChild(cpCol);
     cpCol.Remove(removedChild);
     return removedChild;
 }
Esempio n. 16
0
 protected override void CauseEventToFire(BusinessObjectCollection <ContactPersonTestBO> col, ContactPersonTestBO bo)
 {
     col.Add(bo);
     col.Remove(bo);
 }
        public void Test_Clear_Clears_RemovedCollection()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO.DeleteAllContactPeople();
            CreateTwoSavedContactPeople();
            ContactPersonTestBO cp = ContactPersonTestBO.CreateUnsavedContactPerson(BOTestUtils.RandomString, BOTestUtils.RandomString);
            cpCol.LoadAll();
            cpCol.Remove(cp);

            Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, cpCol.RemovedBusinessObjects.Count);
            Assert.AreEqual(2, cpCol.Count);
            Assert.AreEqual(2, keyObjectHashTable.Count);

            //---------------Execute Test ----------------------
            cpCol.Clear();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.RemovedBusinessObjects.Count);
            Assert.AreEqual(0, cpCol.Count);
            Assert.AreEqual(0, keyObjectHashTable.Count);
        }