Пример #1
0
        public void Test_CreatedBusinessObject_CancelEdits()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();
            RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

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

            //---------------Test Result -----------------------
            AssertAllCollectionsHaveNoItems(cpCol);
            AssertRemovedEventFired();
        }
        public void Test_MarkForDelete_Added_CancelEdits()
        {
            //---------------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.CancelEdits();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedEventFired();
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
        }
        public void Test_Add_PersistedBO_CancelEdits()
        {
            //---------------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.
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO myBO  = ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO myBO2 = ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO myBO3 = ContactPersonTestBO.CreateSavedContactPerson();

            cpCol.Add(myBO, myBO2, myBO3);
            _businessObjectCollectionTestHelper.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");
            _businessObjectCollectionTestHelper.AssertRemovedEventNotFired();
            ///---------------Execute Test ----------------------
            cpCol.CancelEdits();

            //---------------Test Result ----------------------- - Result
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
        }
        public void Test_MarkForDelete_Added_CancelEdits()
        {
            //---------------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.CancelEdits();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedEventFired();
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
        }
        public void Test_Add_PersistedBO_CancelEdits()
        {
            //---------------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.
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO myBO2 = ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO myBO3 = ContactPersonTestBO.CreateSavedContactPerson();
            cpCol.Add(myBO, myBO2, myBO3);
            _businessObjectCollectionTestHelper.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");
            _businessObjectCollectionTestHelper.AssertRemovedEventNotFired();
            ///---------------Execute Test ----------------------
            cpCol.CancelEdits();

            //---------------Test Result ----------------------- - Result
            BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol);
            _businessObjectCollectionTestHelper.AssertRemovedEventFired();
        }
        public void Test_CreatedBusinessObject_CancelEdits()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = TestUtil.GetRandomString();
            RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

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

            //---------------Test Result -----------------------
            AssertAllCollectionsHaveNoItems(cpCol);
            AssertRemovedEventFired();
        }
        public void Test_RestoreAll()
        {
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO contact1 = new ContactPersonTestBO {Surname = "Soap"};
            ContactPersonTestBO contact2 = new ContactPersonTestBO {Surname = "Hope"};
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO> {contact1, contact2};
            col.SaveAll();

            Assert.AreEqual("Soap", col[0].Surname);
            Assert.AreEqual("Hope", col[1].Surname);

            contact1.Surname = "Cope";
            contact2.Surname = "Pope";
            Assert.AreEqual("Cope", col[0].Surname);
            Assert.AreEqual("Pope", col[1].Surname);

            col.CancelEdits();
            Assert.AreEqual("Soap", col[0].Surname);
            Assert.AreEqual("Hope", col[1].Surname);

            contact1.MarkForDelete();
            contact2.MarkForDelete();
            col.SaveAll();
            Assert.AreEqual(0, col.Count);
        }