コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Test_MarkForDeleteBO_At_IndexNotExist()
        {
            //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());

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count);

            //---------------Execute Test ----------------------
            try
            {
                cpCol.MarkForDeleteAt(1);
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (ArgumentOutOfRangeException ex)
            {
                StringAssert.Contains("Index was out of range", ex.Message);
            }
            catch (Exception)
            {
                Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
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-------------------
            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();
        }
コード例 #6
0
        public void TestGetRelatedBusinessObjectCollection_SortOrder_ChangeOrder()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_SortOrder_AddressLine1();
            ContactPersonTestBO cp       = ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            AddressTestBO       address1 = new AddressTestBO();

            address1.ContactPersonID = cp.ContactPersonID;
            address1.AddressLine1    = "ffff";
            address1.Save();
            AddressTestBO address2 = new AddressTestBO();

            address2.ContactPersonID = cp.ContactPersonID;
            address2.AddressLine1    = "bbbb";
            address2.Save();

            //---------------Assert PreConditions---------------
            RelatedBusinessObjectCollection <AddressTestBO> addresses = cp.Addresses;

            Assert.AreEqual(2, addresses.Count);
            Assert.AreSame(address1, addresses[1]);
            Assert.AreSame(address2, addresses[0]);

            //---------------Execute Test ----------------------
            address2.AddressLine1 = "zzzzz";
            address2.Save();
            RelatedBusinessObjectCollection <AddressTestBO> addressesAfterChangeOrder = cp.Addresses;

            //---------------Test Result -----------------------

            Assert.AreSame(address1, addressesAfterChangeOrder[0]);
            Assert.AreSame(address2, addressesAfterChangeOrder[1]);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        public void Test_Refresh_W_CreatedBOs_CreatedObjectsStillRespondToEvents()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();

            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname   = BOTestUtils.RandomString;
            createdCp.FirstName = BOTestUtils.RandomString;
            RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, cpCol.Count);
            Assert.AreEqual(1, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, cpCol.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            cpCol.Refresh();
            createdCp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(2, cpCol.Count);
            Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(2, cpCol.PersistedBusinessObjects.Count);
            AssertAddedAndRemovedEventsNotFired();
        }
コード例 #10
0
        public void Test_CreatedBusinessObject_SaveBO()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname   = TestUtil.GetRandomString();
            newCP.FirstName = TestUtil.GetRandomString();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            //---------------Execute Test ----------------------
            newCP.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
コード例 #11
0
        public void Test_CreateBusinessObject()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            cpCol.LoadAll();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.IsFalse(_addedEventFired);
            Assert.AreEqual(0, cpCol.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            Assert.Contains(newCP, cpCol.CreatedBusinessObjects);
            Assert.Contains(newCP, cpCol);
            Assert.IsFalse(cpCol.PersistedBusinessObjects.Contains(newCP));
            Assert.IsTrue(_addedEventFired);
        }
コード例 #12
0
        public void Test_CreateBusinessObject_ForeignKeySetUp_BeforeAddedEventFired()
        {
            //---------------Set up test pack-------------------
            //The Foreign Key (address.ContactPersonId) should be set up to be
            // equal to the contactPerson.ContactPersonID before he Added event fires.
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;
            AddressTestBO addressFromEvent = null;
            Guid?         addressContactPersonIDFromEvent = null;

            addresses.BusinessObjectAdded += delegate(object sender, BOEventArgs <AddressTestBO> e)
            {
                addressFromEvent = e.BusinessObject;
                addressContactPersonIDFromEvent = addressFromEvent.ContactPersonID;
            };
            //---------------Assert Precondition----------------
            Assert.IsNull(addressFromEvent);
            Assert.IsNull(addressContactPersonIDFromEvent);
            //---------------Execute Test ----------------------
            AddressTestBO address = addresses.CreateBusinessObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(addressFromEvent);
            Assert.IsNotNull(addressContactPersonIDFromEvent, "Adress.ContactPersonID should have been set before the Added event was called");
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, addressContactPersonIDFromEvent);
            Assert.AreSame(address, addressFromEvent);
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, address.ContactPersonID);
            Assert.IsTrue(address.Status.IsNew);
            Assert.AreEqual(1, addresses.CreatedBusinessObjects.Count);
        }
コード例 #13
0
        public void Test_MarkForDeleteBOList()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(OrganisationTestBO.CreateSavedOrganisation());

            //---------------Test Result -----------------------
            Assert.IsNotNull(cpCol.MarkedForDeleteBusinessObjects);
        }
コード例 #14
0
        public void Test_LoadBoCol_Generic()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            CreateSavedContactPerson(organisation);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol(organisation);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        public void Test_LoaderRefresh_ShouldSetDateTimeLastLoaded()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO       address;
            ContactPersonTestBO contactPersonTestBO             = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());
            RelatedBusinessObjectCollection <AddressTestBO> col = new RelatedBusinessObjectCollection <AddressTestBO>(contactPersonTestBO.Relationships["Addresses"]);

            //---------------Assert Precondition----------------
            Assert.IsNull(col.TimeLastLoaded);
            //---------------Execute Test ----------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);
            //---------------Test Result -----------------------
            Assert.IsNotNull(col.TimeLastLoaded);
        }
コード例 #18
0
        private static RelatedBusinessObjectCollection <ContactPersonTestBO> CreateCollectionWith_OneBO()
        {
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            ContactPersonTestBO cp = cpCol.CreateBusinessObject();

            cp.FirstName = TestUtil.GetRandomString();
            cp.Surname   = TestUtil.GetRandomString();
            cp.Save();
            return(BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObjectCollection <ContactPersonTestBO>
                       (cpRelationship));
        }
コード例 #19
0
        public void Test_LoadObjectWhenAlreadyObjectInObjectManager()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            AddressTestBO       address;
            ContactPersonTestBO cp = CreateSavedCP_WithOneAddresss(out address);

            IPrimaryKey contactPersonID = cp.ID;
            IPrimaryKey addresssID      = address.ID;

            cp      = null;
            address = null;

            TestUtil.WaitForGC();
            boMan.ClearLoadedObjects();

            AddressTestBO addressOut;

            CreateSavedCP_WithOneAddresss(out addressOut);
            CreateSavedCP_WithOneAddresss(out addressOut);
            CreateSavedCP_WithOneAddresss(out addressOut);

            //---------------Assert Precondition----------------
            Assert.AreEqual(6, boMan.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(contactPersonID);
            RelatedBusinessObjectCollection <AddressTestBO> addresses = loadedCP.AddressTestBOs;

            //---------------Test Result -----------------------
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(8, boMan.Count);

            Assert.IsTrue(boMan.Contains(loadedCP));
            Assert.AreSame(loadedCP, boMan[contactPersonID]);

            AddressTestBO loadedAddress = addresses[0];

            Assert.IsTrue(boMan.Contains(loadedAddress));
            Assert.IsTrue(boMan.Contains(addresssID));
            Assert.IsTrue(boMan.Contains(addresssID.GetObjectId()));
            Assert.AreSame(loadedAddress, boMan[addresssID]);
            Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]);
        }
コード例 #20
0
        public void Test_loadedBo_RefreshAll()
        {
            //-----Create Test pack---------------------
            ContactPersonTestBO cp;
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation());

            cp.FirstName = TestUtil.GetRandomString();

            //--------------Assert Preconditions--------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);

            //-----Run tests----------------------------
            cpCol.Refresh();

            ////-----Test results-------------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        public void Test_SetTimeLastLoaded_ShouldSetTimeLastLoaded()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO       address;
            ContactPersonTestBO contactPersonTestBO             = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());
            RelatedBusinessObjectCollection <AddressTestBO> col = new RelatedBusinessObjectCollection <AddressTestBO>(contactPersonTestBO.Relationships["Addresses"]);

            //---------------Assert Precondition----------------
            Assert.IsNull(col.TimeLastLoaded);
            //---------------Execute Test ----------------------
            DateTime expectedLastLoaded = DateTime.Now;

            col.TimeLastLoaded = expectedLastLoaded;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedLastLoaded, col.TimeLastLoaded);
        }
コード例 #23
0
        public void Test_Remove_RefreshAll()
        {
            //-----Create Test pack---------------------
            ContactPersonTestBO cp;
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCol_OneCP(out cp, OrganisationTestBO.CreateSavedOrganisation());

            cpCol.Remove(cp);

            //--------------Assert Preconditions--------
            AssertOneObjectInRemovedAndPersistedCollection(cpCol);

            //-----Run tests----------------------------
            cpCol.Refresh();

            ////-----Test results-------------------------
            AssertOneObjectInRemovedAndPersistedCollection(cpCol);
        }
コード例 #24
0
        public void Test_CreatedBusinessObject_MarkForDelete_ShouldRemoveFromCurrentAndCreatedCol()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            //---------------Execute Test ----------------------
            newCP.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count);
            Assert.IsTrue(newCP.Status.IsDeleted);
        }
コード例 #25
0
        public void Test_CreatedBusinessObject_Refresh()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();

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

            //---------------Execute Test ----------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(newCP);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
        }
コード例 #26
0
        public void Test_RefreshAll_W_CreatedBO()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol();

            cpCol.CreateBusinessObject();
            RegisterForAddedAndRemovedEvents(cpCol);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
コード例 #27
0
        public void Test_MarkForDeleteBO_RestoreAll()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(OrganisationTestBO.CreateSavedOrganisation());
            ContactPersonTestBO cp = cpCol[0];

            cpCol.MarkForDelete(cp);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsTrue(cpCol.Contains(cp));
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        public void Test_MarkForDeleteBO_At()
        {
            //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];

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count);

            //---------------Execute Test ----------------------
            cpCol.MarkForDeleteAt(0);

            //---------------Test Result -----------------------
            AssertOnePersisted_OneMarkForDelete(cpCol);
            Assert.IsTrue(markForDeleteCP.Status.IsDeleted);
        }
コード例 #30
0
        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);
        }
コード例 #31
0
        public void Test_CreateBusinessObject_AddedToTheCollection()
        {
            //---------------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);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            MyRelatedBo relatedBo = col.CreateBusinessObject();
            //---------------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(0, col.AddedBusinessObjects.Count);
            Assert.AreEqual(1, col.Count);
        }
コード例 #32
0
        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);
        }
コード例 #33
0
        //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();
        }
コード例 #34
0
        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 -----------------------
        }
コード例 #35
0
        public void Test_CreateBusinessObject()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship =
                (IMultipleRelationship) organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(cpRelationship);
            cpCol.LoadAll();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.IsFalse(_addedEventFired);
            Assert.AreEqual(0, cpCol.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            Assert.Contains(newCP, cpCol.CreatedBusinessObjects);
            Assert.Contains(newCP, cpCol);
            Assert.IsFalse(cpCol.PersistedBusinessObjects.Contains(newCP));
            Assert.IsTrue(_addedEventFired);
        }
コード例 #36
0
        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");
        }
コード例 #37
0
 public void Test_LoaderRefresh_ShouldSetDateTimeLastLoaded()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     AddressTestBO address;
     ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());
     RelatedBusinessObjectCollection<AddressTestBO> col = new RelatedBusinessObjectCollection<AddressTestBO>(contactPersonTestBO.Relationships["Addresses"]);
     //---------------Assert Precondition----------------
     Assert.IsNull(col.TimeLastLoaded);
     //---------------Execute Test ----------------------
     BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);
     //---------------Test Result -----------------------
     Assert.IsNotNull(col.TimeLastLoaded);
 }
コード例 #38
0
            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);
        }
コード例 #39
0
        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);
        }
コード例 #40
0
        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);
        }
コード例 #41
0
        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);
        }
コード例 #42
0
        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);
        }
コード例 #43
0
        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);
        }
コード例 #44
0
        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();
        }
コード例 #45
0
        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");
        }
コード例 #46
0
        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();
        }
コード例 #47
0
 public void Test_SetTimeLastLoaded_ShouldSetTimeLastLoaded()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     AddressTestBO address;
     ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());
     RelatedBusinessObjectCollection<AddressTestBO> col = new RelatedBusinessObjectCollection<AddressTestBO>(contactPersonTestBO.Relationships["Addresses"]);
     //---------------Assert Precondition----------------
     Assert.IsNull(col.TimeLastLoaded);
     //---------------Execute Test ----------------------
     DateTime expectedLastLoaded = DateTime.Now;
     col.TimeLastLoaded = expectedLastLoaded;
     //---------------Test Result -----------------------
     Assert.AreEqual(expectedLastLoaded, col.TimeLastLoaded);
 }
コード例 #48
0
        public void Test_CreatedBusinessObject_SaveAll()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in 
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------

            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship =
                (IMultipleRelationship) organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(cpRelationship);
            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = TestUtil.GetRandomString();
            newCP.FirstName = TestUtil.GetRandomString();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);
            Assert.AreEqual(InsertParentAction.InsertRelationship, cpRelationship.RelationshipDef.InsertParentAction);
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(newCP.Status.IsNew);
            Assert.IsFalse(newCP.Status.IsDirty);
        }
コード例 #49
0
        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();
        }
コード例 #50
0
        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");
        }
コード例 #51
0
        private static RelatedBusinessObjectCollection<ContactPersonTestBO> CreateCollectionWith_OneBO()
        {
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship =
                (IMultipleRelationship) organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(cpRelationship);

            ContactPersonTestBO cp = cpCol.CreateBusinessObject();
            cp.FirstName = TestUtil.GetRandomString();
            cp.Surname = TestUtil.GetRandomString();
            cp.Save();
            return BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObjectCollection<ContactPersonTestBO>
                (cpRelationship);
        }
コード例 #52
0
        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");
        }
コード例 #53
0
        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();
        }
コード例 #54
0
        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();
        }
コード例 #55
0
 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);
 }
コード例 #56
0
        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);
        }