Beispiel #1
0
        public void Test_CreatedBO_Remove_DeregisteresFromRestoredEvent()
        {
            //If you remove a created business object that is not yet persisted then
            //-- remove from the restored and saved event.
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = BOTestUtils.RandomString;

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));
        }
Beispiel #2
0
        public void Test_RemoveCreatedBo_DeregistersForSaveEvent()
        {
            //If you remove a created business object that is not yet persisted then
            //-- remove from the restored and saved event.
            //-- when the object is saved it should be independent of the collection.
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = BOTestUtils.RandomString;
            cpCol.Remove(createdCp);
            RegisterForAddedAndRemovedEvents(cpCol);
            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));
            AssertAddedAndRemovedEventsNotFired();
        }
        public void TestCreateBusinessObjectFromCollection()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            new Address();
            new Engine();
            new Car(); new ContactPerson();
            BusinessObjectCollection<ContactPerson> col = new BusinessObjectCollection<ContactPerson>();

            IBusinessObjectCreator boCreator = new DefaultBOCreator(col);

            //---------------Execute Test ----------------------
            ContactPerson cp = (ContactPerson) boCreator.CreateBusinessObject();
            cp.Surname = Guid.NewGuid().ToString("N");
            cp.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(col.Contains(cp));
            //---------------Tear Down -------------------------
        }
Beispiel #4
0
        public void TestCreateBusinessObjectFromCollection()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            new Address();
            new Engine();
            new Car(); new ContactPerson();
            BusinessObjectCollection <ContactPerson> col = new BusinessObjectCollection <ContactPerson>();

            IBusinessObjectCreator boCreator = new DefaultBOCreator(col);

            //---------------Execute Test ----------------------
            ContactPerson cp = (ContactPerson)boCreator.CreateBusinessObject();

            cp.Surname = Guid.NewGuid().ToString("N");
            cp.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(col.Contains(cp));
            //---------------Tear Down -------------------------
        }
        public void TestRefreshCollectionRefreshesNonDirtyObjects()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorDB();
            ContactPersonTestBO.DeleteAllContactPeople();

            SetupDefaultContactPersonBO();
            var col = new BusinessObjectCollection <ContactPersonTestBO>();

            var cp1 = ContactPersonTestBO.CreateSavedContactPerson();

            FixtureEnvironment.ClearBusinessObjectManager();
            ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO.CreateSavedContactPerson();
            col.LoadAll();
            var newSurname = Guid.NewGuid().ToString();

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

            //--------------------Assert Preconditions----------
            Assert.IsFalse(col.Contains(cp1));
            Assert.AreEqual(3, col.Count);
            Assert.AreEqual(newSurname, cp1.Surname);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname);
            Assert.IsFalse(cp1.Status.IsDirty);
            //---------------Execute Test ----------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);

            //---------------Test Result -----------------------
            Assert.AreEqual(3, col.Count);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname);
        }
		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));
		}
        public void Test_Contains_False_UnsavedBusinessObject_NotInCollection_CompositeKey()
        {
            //--------------- Set up test pack ------------------
            ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
            ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();

            Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);
            cpCol.Add(ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp());
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.IsFalse(keyObjectHashTable.ContainsKey(person.ID.ObjectID));
            //--------------- Execute Test ----------------------
            bool contains = cpCol.Contains(person);
            //--------------- Test Result -----------------------
            Assert.IsFalse(contains);
        }
        public void TestRefreshCollectionRefreshesNonDirtyObjects()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorDB();
            ContactPersonTestBO.DeleteAllContactPeople();

            SetupDefaultContactPersonBO();
            var col = new BusinessObjectCollection<ContactPersonTestBO>();

            var cp1 = ContactPersonTestBO.CreateSavedContactPerson();
            FixtureEnvironment.ClearBusinessObjectManager();
            ContactPersonTestBO.CreateSavedContactPerson();
            ContactPersonTestBO.CreateSavedContactPerson();
            col.LoadAll();
            var newSurname = Guid.NewGuid().ToString();
            cp1.Surname = newSurname;
            cp1.Save();
            var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID);

            //--------------------Assert Preconditions----------
            Assert.IsFalse(col.Contains(cp1));
            Assert.AreEqual(3, col.Count);
            Assert.AreEqual(newSurname, cp1.Surname);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname);
            Assert.IsFalse(cp1.Status.IsDirty);
            //---------------Execute Test ----------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);

            //---------------Test Result -----------------------
            Assert.AreEqual(3, col.Count);
            Assert.AreNotSame(secondInstanceOfCP1, cp1);
            Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname);
        }
		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));
		}
 public void Test_Remove_UnsavedBusinessObjectFromCollection_CompositeKey()
 {
     //--------------- Set up test pack ------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
     ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp();
     BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
     Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);
     cpCol.Add(person);
     //--------------- Test Preconditions ----------------
     Assert.AreEqual(1, cpCol.Count);
     Assert.AreEqual(1, keyObjectHashTable.Count);
     Assert.IsTrue(cpCol.Contains(person));
     //--------------- Execute Test ----------------------
     cpCol.Remove(person);
     //--------------- Test Result -----------------------
     Assert.AreEqual(0, cpCol.Count);
     Assert.AreEqual(0, keyObjectHashTable.Count);
 }
		public void Test_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_RefreshLoadedCollection_IsNotNull_CriteriaString()
		{
			//---------------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(null, "sn", "fn");

			const string criteria = "DateOfBirth IS NOT 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(null, "sn2", "fn2");

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

			//---------------Execute Test ----------------------
			//col.Refresh();
			BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);
			//---------------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));
		}
        public void Test_Contains_True_UnsavedBusinessObject_InCollection()
        {
            //--------------- Set up test pack ------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();

            Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);
            cpCol.Add(person);
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.IsTrue(keyObjectHashTable.ContainsKey(person.ID.ObjectID));
            //--------------- Execute Test ----------------------
            bool contains = cpCol.Contains(person);
            //--------------- Test Result -----------------------
            Assert.IsTrue(contains);
        }
		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));
		}
		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));
		}
        public void Test_CollectionLoad_LoadWithLimit_CriteriaObject_IncludesCriteriaMatchesWithinLimit()
        {
            //---------------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), "bbb");

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, now.AddHours(-1));
            //---------------Assert Precondition ---------------


            //---------------Execute Test ----------------------
            //            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);
            col.LoadWithLimit(criteria, "Surname", 2);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.AreSame(cp1, col[0]);
            Assert.AreSame(cp2, col[1]);
            Assert.IsFalse(col.Contains(cpLast));
        }
        public void Test_Add_UnsavedBusinessObjectToCollection_ChangePrimaryKeyPropertyValue_CompositeKey()
        {
            //--------------- Set up test pack ------------------
            ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
            ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();

            Hashtable keyObjectHashTable = GetKeyObjectHashTable(cpCol);
            cpCol.Add(person);
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.AreEqual(1, keyObjectHashTable.Count);
            Assert.IsTrue(cpCol.Contains(person));
            //--------------- Execute Test ----------------------
            person.ContactPersonID = Guid.NewGuid();
            //--------------- Test Result -----------------------
            Assert.AreEqual(1, cpCol.Count);
            Assert.AreEqual(1, keyObjectHashTable.Count);
            Assert.IsTrue(cpCol.Contains(person));
            Assert.IsTrue(keyObjectHashTable.ContainsKey(person.ID.ObjectID));
        }