コード例 #1
0
        public void Test_RefreshCollectionRefreshesNonDirtyObjects()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorDB();
            OrganisationTestBO.DeleteAllOrganisations();
            ContactPersonTestBO.DeleteAllContactPeople();
            SetupDefaultContactPersonBO();
            var col = new BusinessObjectCollection <ContactPersonTestBO>();

            var cp1 = CreateContactPersonTestBO();

            FixtureEnvironment.ClearBusinessObjectManager();

            CreateContactPersonTestBO();
            CreateContactPersonTestBO();
            col.LoadAll();
            var newSurname = Guid.NewGuid().ToString();

            cp1.Surname = newSurname;
            cp1.Save();
            var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID);

            //--------------------Assert Preconditions----------
            AssertNotContains(cp1, col);
            Assert.AreEqual(newSurname, cp1.Surname);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname);
            Assert.IsFalse(cp1.Status.IsDirty);
            //---------------Execute Test ----------------------
            col.Refresh();

            //---------------Test Result -----------------------
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname);
        }
コード例 #2
0
        public override void TestSetSelectedBO_WhenGridHasObjectIDButBOColNotHasObject_ShouldSetBO()
        {
            //This is a fairly specific situation but can occur when you are using
            // a CachedBindingList or a paginaged BindingList where the BOCol that the
            // grid has reference to does not have any BusinessObjects.
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_SavedObjects();

            IGridBase gridBase = CreateGridBaseStub();

            gridBase.GridLoader = new CustomDelegateLoaderClass(col).GridLoaderDelegateLoadFromDiffCol;
            SetupGridColumnsForMyBo(gridBase);
            gridBase.BusinessObjectCollection = new BusinessObjectCollection <MyBO>();
            //---------------Assert Preconditions---------------
            Assert.IsNull(gridBase.DataSetProvider);
            Assert.IsNotNull(gridBase.DataSource);
            col.Refresh();
            Assert.AreEqual(4, col.Count);
            Assert.AreEqual(4, gridBase.RowCount);
            //---------------Execute Test ----------------------
            var expectedSelectedBo = col[2];

            gridBase.SelectedBusinessObject = expectedSelectedBo;
            var actualSelectedBO = gridBase.SelectedBusinessObject;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedSelectedBo, actualSelectedBO);
        }
コード例 #3
0
        public void Test_Refresh_WithDuplicateObjectsInPersistedCollection_ShouldThrowHabaneroDeveloperException()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            MyBO bo = new MyBO();

            bo.Save();
            BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO>();

            collection.Load("MyBoID = '" + bo.MyBoID + "'", "");
            collection.PersistedBusinessObjects.Add(bo);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, collection.PersistedBusinessObjects.Count);
            Assert.AreSame(collection.PersistedBusinessObjects[0], collection.PersistedBusinessObjects[1]);
            //---------------Execute Test ----------------------
            try
            {
                collection.Refresh();
                //---------------Test Result -----------------------
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <HabaneroDeveloperException>(ex, "Should have thrown a HabaneroDeveloperException because of the duplicate item in the PersistedBusinessObjects collection");
                StringAssert.Contains("A duplicate Business Object was found in the persisted objects collection of the BusinessObjectCollection during a reload", ex.Message);
                StringAssert.Contains("MyBO", ex.Message);
                StringAssert.Contains(bo.MyBoID.Value.ToString("B"), ex.Message);
            }
        }
コード例 #4
0
        public void Test_Refresh_W_CreatedBOs_CreatedObjectsStillRespondToEvents()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();

            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = 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();
        }
コード例 #5
0
        public void Test_RefreshAll_W_CreatedBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.CreateBusinessObject();
            RegisterForAddedAndRemovedEvents(cpCol);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
コード例 #6
0
        public void TestAddMethod_RefreshAllBusinessObject()
        {
            //---------------Set up test pack-------------------
            var 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.Refresh();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentPersistedCollectionOnly(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
コード例 #7
0
        public void Test_MarkForDelete_Added_RefreshAll()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.Load(new Criteria("Surname", Criteria.ComparisonOp.Equals, TestUtil.GetRandomString()), "");
            cpCol.Add(myBO);
            myBO.MarkForDelete();
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
            //---------------Execute Test ----------------------
            cpCol.Refresh();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
コード例 #8
0
        public void Test_MarkForDelete_Added_LoadWCriteria_RefreshAll()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.Load("Surname=cc", "");
            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.Refresh();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
コード例 #9
0
        public void Test_MarkForDelete_Added_LoadWCriteria_RefreshAll()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.Load("Surname=cc", "");
            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.Refresh();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
		public void Test_RefreshLoadedCollection_Typed_LTEQCriteriaString_IntegerProperty()
		{
			//---------------Set up test pack-------------------
		    LoadContactPersonClassDefWithIntProp();
		    DateTime now = DateTime.Now;
			ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now);
			cp1.SetPropertyValue("IntegerProperty", 0);
			cp1.Save();
			ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now);
			cp2.SetPropertyValue("IntegerProperty", 1);
			cp2.Save();
			ContactPersonTestBO cpExcluded = ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(+3));
			cpExcluded.SetPropertyValue("IntegerProperty", 3);
			cpExcluded.Save();
			ContactPersonTestBO cpEqual = ContactPersonTestBO.CreateSavedContactPerson(now.AddHours(+1));
			cpEqual.SetPropertyValue("IntegerProperty", 2);
			cpEqual.Save();

			string criteria = "IntegerProperty <= " + cpEqual.GetPropertyValue("IntegerProperty");
			var col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "");
			var cp3 = ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(-1));
			cp3.SetPropertyValue("IntegerProperty", 1);
			cp3.Save();
			var cpExcludeNew = ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(+1));
			cpExcludeNew.SetPropertyValue("IntegerProperty", 5);
			cpExcludeNew.Save();
			var cpEqualNew = ContactPersonTestBO.CreateSavedContactPerson(cpEqual.DateOfBirth);
			cpEqualNew.SetPropertyValue("IntegerProperty", 2);
			cpEqualNew.Save();

			//---------------Assert Precondition ---------------
			Assert.AreEqual(3, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cpEqual, col);
			Assert.IsFalse(col.Contains(cpExcluded));

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

			//---------------Test Result -----------------------
			Assert.AreEqual(5, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cp3, col);
			Assert.Contains(cpEqual, col);
			Assert.Contains(cpEqualNew, col);
			Assert.IsFalse(col.Contains(cpExcludeNew));
			Assert.IsFalse(col.Contains(cpExcluded));
		}
コード例 #11
0
        public void TestAddMethod_Refresh_LoadWithCriteria_BusinessObject()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.Load("Surname='bbb'", "");
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("aaa");

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

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

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
コード例 #12
0
        public void Test_MarkForDelete_Added_RefreshAll()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.Load(new Criteria("Surname", Criteria.ComparisonOp.Equals, TestUtil.GetRandomString()), "" );
            cpCol.Add(myBO);
            myBO.MarkForDelete();
            _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
            //---------------Execute Test ----------------------
            cpCol.Refresh();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol);
            Assert.IsTrue(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired();
        }
コード例 #13
0
        public void Test_RefreshAll_W_CreatedBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.CreateBusinessObject();
            RegisterForAddedAndRemovedEvents(cpCol);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
        public void Test_RefreshCollectionRefreshesNonDirtyObjects()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorDB();
            OrganisationTestBO.DeleteAllOrganisations();
            ContactPersonTestBO.DeleteAllContactPeople();
            SetupDefaultContactPersonBO();
            var col = new BusinessObjectCollection<ContactPersonTestBO>();

            var cp1 = CreateContactPersonTestBO();
            FixtureEnvironment.ClearBusinessObjectManager();

            CreateContactPersonTestBO();
            CreateContactPersonTestBO();
            col.LoadAll();
            var newSurname = Guid.NewGuid().ToString();
            cp1.Surname = newSurname;
            cp1.Save();
            var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID);

            //--------------------Assert Preconditions----------
            AssertNotContains(cp1, col);
            Assert.AreEqual(newSurname, cp1.Surname);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname);
            Assert.IsFalse(cp1.Status.IsDirty);
            //---------------Execute Test ----------------------
            col.Refresh();

            //---------------Test Result -----------------------
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname);
        }
コード例 #15
0
        public void Test_RefreshCollectionDoesNotRefreshDirtyOject()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorDB();
            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            
            ContactPersonTestBO cp1 = CreateContactPersonTestBO();
            col.Add(cp1);
            string newSurname = Guid.NewGuid().ToString();
            //--------------------Assert Preconditions----------
            Assert.Contains(cp1 , col, "cp1 should be saved to the database");
            //---------------Execute Test ----------------------
            cp1.Surname = newSurname;
            col.Refresh();

            //---------------Test Result -----------------------
            Assert.AreEqual(newSurname, cp1.Surname);
            Assert.IsTrue(cp1.Status.IsDirty);
        }
		public void Test_RefreshLoadedCollection_Typed_NotEQ_CriteriaString_Null()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			DateTime now = DateTime.Now;
			ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(+3));
			ContactPersonTestBO cpEqual = ContactPersonTestBO.CreateSavedContactPerson(now.AddHours(+1));

			const string criteria = "DateOfBirth <> " + null;
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "");
			ContactPersonTestBO cp3 = ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(-1));
			ContactPersonTestBO cpNotEqual = ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(+1));
			ContactPersonTestBO cpEqualNew = ContactPersonTestBO.CreateSavedContactPerson(cpEqual.DateOfBirth);

			//---------------Assert Precondition ---------------
			Assert.AreEqual(4, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.IsTrue(col.Contains(cpEqual));

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

			//---------------Test Result -----------------------
			Assert.AreEqual(7, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cp3, col);
			Assert.Contains(cpNotEqual, col);
			Assert.IsTrue(col.Contains(cpEqualNew));
			Assert.IsTrue(col.Contains(cpEqual));
		}
コード例 #17
0
        public void Test_AddedEvent_NotFiringWhenRefreshing()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            _addedEventFired = false;
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.LoadAll();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = Guid.NewGuid().ToString();
            newCP.Save();

            cpCol.BusinessObjectAdded += delegate { _addedEventFired = true; };
            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);

            //---------------Execute Test ----------------------
            cpCol.Refresh();
            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
        }
		public void Test_Refresh_WithSavedBOAlreadyInCollection()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			ContactPersonTestBO cp = ContactPersonTestBO.CreateUnsavedContactPerson();
			BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
			cpCol.Add(cp);
			cp.Save();
			//---------------Assert preconditions---------------
			Assert.AreEqual(1, cpCol.PersistedBusinessObjects.Count);
			//---------------Execute Test ----------------------
			cpCol.Refresh();
			//---------------Test Result -----------------------
			Assert.AreEqual(1, cpCol.PersistedBusinessObjects.Count);
		}
		public void Test_RefreshLoadedCollection_Untyped()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			DateTime now = DateTime.Now;
			ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(-1));

			Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "Surname");
			ContactPersonTestBO cp3 = ContactPersonTestBO.CreateSavedContactPerson(now);
			//---------------Assert Precondition ---------------
			Assert.AreEqual(2, col.Count);

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

			//---------------Test Result -----------------------
			Assert.AreEqual(3, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cp3, col);
		}
		public void Test_RefreshLoadedCollection_UsingNotLike()
		{
			//---------------Set up test pack-------------------
			ContactPerson.DeleteAllContactPeople();
			SetupDefaultContactPersonBO();
			//Create data in the database with the 5 contact people two with Search in surname
			CreateContactPersonInDB();
			CreateContactPersonInDB();
			CreateContactPersonInDB();
			CreateContactPersonInDB_With_SSSSS_InSurname();
			CreateContactPersonInDB_With_SSSSS_InSurname();
			var col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load("Surname not like %SSS%", "Surname");

			//---------------Assert Precondition----------------
			Assert.AreEqual(3, col.Count);
			//---------------Execute Test ----------------------
			CreateContactPersonInDB();
			CreateContactPersonInDB();
			ContactPersonTestBO cpNewLikeMatch = CreateContactPersonInDB_With_SSSSS_InSurname();
			col.Refresh();

			//---------------Test Result -----------------------
			Assert.AreEqual(5, col.Count);
			Assert.IsFalse(col.Contains(cpNewLikeMatch));
		}
			Test_RefreshLoadedCollection_Untyped_GTCriteriaObject_OrderClause_DoesNotLoadNewObject()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			DateTime now = DateTime.Now;
			ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now, "aaa");
			ContactPersonTestBO cpLast = ContactPersonTestBO.CreateSavedContactPerson(now, "zzz");
			ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now, "hhh");
			ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(-3));

			Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, now.AddHours(-1));
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "Surname");
			ContactPersonTestBO cpnew = ContactPersonTestBO.CreateSavedContactPerson(now, "bbb");

			//---------------Assert Precondition ---------------
			Assert.AreEqual(3, col.Count);

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

			//---------------Test Result -----------------------
			Assert.AreEqual(4, col.Count);
			Assert.AreSame(cp1, col[0]);
			Assert.AreSame(cpnew, col[1]);
			Assert.AreSame(cp2, col[2]);
			Assert.AreSame(cpLast, col[3]);
		}
		public void Test_RefreshLoadedCollection_Untyped_GTCriteriaObject_LoadsNewObject()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			DateTime now = DateTime.Now;
			ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(-3));

			Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, now.AddHours(-2));
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "");
			ContactPersonTestBO cp3 = ContactPersonTestBO.CreateSavedContactPerson(now.AddHours(-1));

			//---------------Assert Precondition ---------------
			Assert.AreEqual(2, col.Count);

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

			//---------------Test Result -----------------------
			Assert.AreEqual(3, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cp3, col);
		}
		public void Test_RefreshLoadedCollection_ISNull_CriteriaString()
		{
			//---------------Set up test pack-------------------
			SetupDefaultContactPersonBO();
			DateTime now = DateTime.Now;
			ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO.CreateSavedContactPerson(now);
			ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(+3));
			ContactPersonTestBO cpEqual = ContactPersonTestBO.CreateSavedContactPerson(null, "sn", "fn");

			const string criteria = "DateOfBirth IS NULL";
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "");
			ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(-1));
			ContactPersonTestBO.CreateSavedContactPerson(now.AddDays(+1));
			ContactPersonTestBO cpEqualNew = ContactPersonTestBO.CreateSavedContactPerson(null, "sn2", "fn2");

			//---------------Assert Precondition ---------------
			Assert.AreEqual(1, col.Count);
			Assert.IsTrue(col.Contains(cpEqual));

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

			//---------------Test Result -----------------------
			Assert.AreEqual(2, col.Count);
			Assert.IsTrue(col.Contains(cpEqualNew));
			Assert.IsTrue(col.Contains(cpEqual));
		}
 public void Test_CollectionLoad_LoadWithLimit_FirstAtEnd_LimitBeyondEnd_RefreshWithAdditionalBO()
 {
     const int totalRecords = 5;
     const int firstRecord = totalRecords - 1;
     const int limit = 3;
     SetupDefaultContactPersonBO();
     var contactPersonTestBOs = CreateSavedContactPeople(totalRecords);
     var contactPersonTestBOsPlusOne = new ContactPersonTestBO[totalRecords + 1];
     contactPersonTestBOs.CopyTo(contactPersonTestBOsPlusOne, 0);
     var col = new BusinessObjectCollection<ContactPersonTestBO>();
     int totalNoOfRecords;
     col.LoadWithLimit("", "Surname", firstRecord, limit, out totalNoOfRecords);
     contactPersonTestBOsPlusOne[totalRecords] = ContactPersonTestBO.CreateSavedContactPerson
         ("ZZZZZZZZZZZZZZZZZ");
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, col.Count);
     Assert.AreEqual(totalRecords, contactPersonTestBOs.Length);
     Assert.AreEqual(totalRecords + 1, contactPersonTestBOsPlusOne.Length);
     //---------------Execute Test ----------------------
     col.Refresh();
     //---------------Test Result -----------------------
     totalNoOfRecords++;
     AssertLimitedResultsCorrect
         (firstRecord, limit, totalRecords + 1, 2, contactPersonTestBOsPlusOne, col, totalNoOfRecords);
 }
コード例 #25
0
        public void Test_Refresh_WithDuplicateObjectsInPersistedCollection_ShouldThrowHabaneroDeveloperException()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            MyBO bo = new MyBO();
            bo.Save();
            BusinessObjectCollection<MyBO> collection = new BusinessObjectCollection<MyBO>();
            collection.Load("MyBoID = '" + bo.MyBoID + "'", "");
            collection.PersistedBusinessObjects.Add(bo);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, collection.PersistedBusinessObjects.Count);
            Assert.AreSame(collection.PersistedBusinessObjects[0], collection.PersistedBusinessObjects[1]);
            //---------------Execute Test ----------------------
            try
            {
                collection.Refresh();
                //---------------Test Result -----------------------
            } catch (Exception ex) 
            {
                Assert.IsInstanceOf<HabaneroDeveloperException>(ex, "Should have thrown a HabaneroDeveloperException because of the duplicate item in the PersistedBusinessObjects collection");
                StringAssert.Contains("A duplicate Business Object was found in the persisted objects collection of the BusinessObjectCollection during a reload", ex.Message);
                StringAssert.Contains("MyBO", ex.Message);
                StringAssert.Contains(bo.MyBoID.Value.ToString("B").ToUpper(), ex.Message);
            }

        }
コード例 #26
0
 public void Test_RefreshCollection_ShouldSetDateTimeLastLoaded()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadDefaultClassDef();
     IBusinessObjectCollection col = new BusinessObjectCollection<ContactPersonTestBO>();
     //---------------Assert Precondition----------------
     Assert.IsNull(col.TimeLastLoaded);
     //---------------Execute Test ----------------------
     col.Refresh();
     //---------------Test Result -----------------------
     Assert.IsNotNull(col.TimeLastLoaded);
 }
		public void Test_RefreshLoadedCollection_Typed_NotEQ_CriteriaString()
		{
			//---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            LoadContactPersonClassDefWithIntProp();
			ContactPersonTestBO cp1 = CreateSavedContactPerson(TestUtil.GetRandomString(), 2);
			ContactPersonTestBO cp2 = CreateSavedContactPerson(TestUtil.GetRandomString(), 4);
			CreateSavedContactPerson(TestUtil.GetRandomString(), 2);
			ContactPersonTestBO cpEqual = CreateSavedContactPerson(TestUtil.GetRandomString(), 3);

			string criteria = "IntegerProperty <> " + 3;
			BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
			col.Load(criteria, "");

			//---------------Assert Precondition ---------------
			Assert.AreEqual(3, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.IsFalse(col.Contains(cpEqual));

			//---------------Execute Test ----------------------
			ContactPersonTestBO cp3 = CreateSavedContactPerson(TestUtil.GetRandomString(), 2);
			ContactPersonTestBO cpNotEqual = CreateSavedContactPerson(TestUtil.GetRandomString(), 4);
			ContactPersonTestBO cpEqualNew = CreateSavedContactPerson(TestUtil.GetRandomString(), 3);
			col.Refresh();

			//---------------Test Result -----------------------
			Assert.AreEqual(5, col.Count);
			Assert.Contains(cp1, col);
			Assert.Contains(cp2, col);
			Assert.Contains(cp3, col);
			Assert.Contains(cpNotEqual, col);
			Assert.IsFalse(col.Contains(cpEqualNew));
			Assert.IsFalse(col.Contains(cpEqual));
		}