public void Test_MarkForDelete_Added_RestoreBO_LoadWCriteria()
        {
            //---------------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 ----------------------
            myBO.CancelEdits();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedEventFired();
            _businessObjectCollectionTestHelper.AssertRemovedEventNotFired();
        }
        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);
            }
        }
Beispiel #3
0
        protected internal static BusinessObjectCollection <BusinessObject> LoadBusinessObjCol(string searchCriteria,
                                                                                               string orderByClause)
        {
            BusinessObjectCollection <BusinessObject> bOCol = new BusinessObjectCollection <BusinessObject>(GetClassDef());

            bOCol.Load(searchCriteria, orderByClause);
            return(bOCol);
        }
Beispiel #4
0
        public static BusinessObjectCollection <ContactPerson> LoadBusinessObjCol(string searchCriteria,
                                                                                  string orderByClause)
        {
            BusinessObjectCollection <ContactPerson> bOCol = new BusinessObjectCollection <ContactPerson>(GetClassDef());

            bOCol.Load(searchCriteria, orderByClause);
            return(bOCol);
        }
        public void TestAcceptance_SearchGridSearchesTheGrid()
        {
            //---------------Set up test pack-------------------
            //Clear all contact people from the DB
            ContactPerson.DeleteAllContactPeople();
            IClassDef classDef = ContactPersonTestBO.LoadDefaultClassDefWithUIDef();

            //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();
            //Create grid setup for search
            IEditableGridControl gridControl = CreateEditableGridControl();
            ITextBox             txtbox      = gridControl.FilterControl.AddStringFilterTextBox("Surname", "Surname");

            gridControl.Initialise(classDef);
            gridControl.FilterMode = FilterModes.Search;

            //--------------Assert PreConditions----------------
            //No items in the grid
            Assert.AreEqual(1, gridControl.Grid.Rows.Count);

            //---------------Execute Test ----------------------
            //set data in grid to a value that should return 2 people
            const string filterByValue = "SSSSS";

            txtbox.Text = filterByValue;
            //grid.filtercontrols.searchbutton.click
            gridControl.OrderBy = "Surname";
            gridControl.FilterControl.ApplyFilter();

            //---------------Test Result -----------------------
            StringAssert.Contains(filterByValue,
                                  gridControl.FilterControl.GetFilterClause().GetFilterClauseString());
            //verify that there are 2 people in the grid.
            Assert.AreEqual(3, gridControl.Grid.Rows.Count);

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

            col.Load("Surname like %" + filterByValue + "%", "Surname");
            Assert.AreEqual(col.Count + 1, gridControl.Grid.Rows.Count);
            int rowNum = 0;

            foreach (ContactPersonTestBO person in col)
            {
                object rowID = gridControl.Grid.Rows[rowNum++].Cells["HABANERO_OBJECTID"].Value;
                Assert.AreEqual(person.ID.ToString(), rowID.ToString());
            }
            //---------------Tear Down -------------------------
            ContactPerson.DeleteAllContactPeople();
        }
        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();
        }
        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();
        }
		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_CollectionLoad_Load_CriteriaString()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            //            DateTime now = DateTime.Now;
            const string surname = "abab";
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(surname);
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(surname);
            ContactPersonTestBO.CreateSavedContactPerson();
            //            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);
            const string criteria = "Surname = " + surname;

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load(criteria, "Surname");

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.Contains(cp1, col);
            Assert.Contains(cp2, col);
        }
        public void Test_MarkForDelete_Added_RestoreBO_LoadWCriteria()
        {
            //---------------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 ----------------------
            myBO.CancelEdits();

            //---------------Test Result -----------------------
            BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol);
            Assert.IsFalse(myBO.Status.IsDirty);
            _businessObjectCollectionTestHelper.AssertAddedEventFired();
            _businessObjectCollectionTestHelper.AssertRemovedEventNotFired();
        }
        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();
        }
        public void TestAcceptance_SearchGridSearchesTheGrid()
        {
            //---------------Set up test pack-------------------
            //Clear all contact people from the DB
            BORegistry.DataAccessor = new DataAccessorInMemory();
            IClassDef classDef = ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
            //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();
            //Create grid setup for search
            IReadOnlyGridControl readOnlyGridControl = CreateReadOnlyGridControl(true);
            ITextBox txtbox = readOnlyGridControl.FilterControl.AddStringFilterTextBox("Surname", "Surname");
            readOnlyGridControl.Initialise(classDef);
            readOnlyGridControl.FilterMode = FilterModes.Search;

            //--------------Assert PreConditions----------------            
            //No items in the grid
            Assert.AreEqual(0, readOnlyGridControl.Grid.Rows.Count);

            //---------------Execute Test ----------------------
            //set data in grid to a value that should return 2 people
            const string filterByValue = "SSSSS";
            txtbox.Text = filterByValue;
            //grid.filtercontrols.searchbutton.click
            readOnlyGridControl.OrderBy = "Surname";
            readOnlyGridControl.FilterControl.ApplyFilter();

            //---------------Test Result -----------------------
            StringAssert.Contains
                (filterByValue, readOnlyGridControl.FilterControl.GetFilterClause().GetFilterClauseString());
            //verify that there are 2 people in the grid.
            Assert.AreEqual(2, readOnlyGridControl.Grid.Rows.Count);

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load("Surname like %" + filterByValue + "%", "Surname");
            Assert.AreEqual(col.Count, readOnlyGridControl.Grid.Rows.Count);
            int rowNum = 0;
            foreach (ContactPersonTestBO person in col)
            {
                object rowID = readOnlyGridControl.Grid.Rows[rowNum++].Cells[_gridIdColumnName].Value;
                Assert.AreEqual(person.ID.ToString(), rowID.ToString());
            }
        }
        public void Test_LoadUsingNotLike()
        {
            //---------------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();
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();

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

            //---------------Execute Test ----------------------
            col.Load("Surname Not like %SSS%", "Surname");
            //---------------Test Result -----------------------
            Assert.AreEqual(3, col.Count);
        }
        public void Test_CollectionLoad_Load_GuidCriteria()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            DateTime now = DateTime.Now;
            ContactPersonTestBO.CreateSavedContactPerson(now);
            ContactPersonTestBO.CreateSavedContactPerson(now);
            ContactPersonTestBO person = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load("ContactPersonID = '" + person.ContactPersonID + "'", "");

            //---------------Test Result -----------------------
            Assert.AreEqual(1, col.Count);
        }
        public void Test_CollectionLoad_LoadWithOrderBy_ManualOrderbyFieldName()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("eeeee");
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("ggggg");
            ContactPersonTestBO cp3 = ContactPersonTestBO.CreateSavedContactPerson("bbbbb");

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load("", "Surname");

            //---------------Test Result -----------------------
            Assert.AreSame(cp3, col[0]);
            Assert.AreSame(cp1, col[1]);
            Assert.AreSame(cp2, col[2]);
        }
		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_Load_CriteriaString_WithOrder_Untyped_DateOfBirth()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            DateTime now = DateTime.Now;
            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now, "zzzz");
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now, "aaaa");
            string criteria = "DateOfBirth = '" + now + "'";

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load(criteria, "Surname");

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.AreSame(cp2, col[0]);
            Assert.AreSame(cp1, col[1]);
        }
		public virtual void Test_CollectionLoad_Load_CriteriaObject_ThroughRelationship_TwoLevels()
		//Modified from Test_CollectionLoad_Load_CriteriaString_ThroughRelationship_TwoLevels
        {
            //---------------Set up test pack-------------------
            Engine.LoadClassDef_IncludingCarAndOwner();
            //            DateTime now = DateTime.Now;
            string surname;
            string regno;
            string engineNo;
            Engine engine = Engine.CreateEngineWithCarWithContact(out surname, out regno, out engineNo);
            Engine.CreateEngineWithCarWithContact();
			Criteria criteria = new Criteria("Car.Owner.Surname", Criteria.ComparisonOp.Equals, surname);
            BusinessObjectCollection<Engine> col = new BusinessObjectCollection<Engine>();

            //---------------Execute Test ----------------------
            col.Load(criteria, "");

            //---------------Test Result -----------------------
            Assert.AreEqual(1, col.Count);
            Assert.Contains(engine, col);
        }
		public void Test_CollectionLoad_Load_CriteriaString_Untyped()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            //            DateTime now = DateTime.Now;
            const string firstName = "abab";
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName);
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName);
            //            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);
            const string criteria = "FirstName = '" + firstName + "'";

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load(criteria, "Surname");

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            col.Sort("Surname", true, true);
            Assert.AreSame(cp2, col[0]);
            Assert.AreSame(cp1, col[1]);
        }
Beispiel #20
0
 public static BusinessObjectCollection<ContactPerson> LoadBusinessObjCol(string searchCriteria,
                                                                                       string orderByClause)
 {
     BusinessObjectCollection<ContactPerson> bOCol = new BusinessObjectCollection<ContactPerson>(GetClassDef());
     bOCol.Load(searchCriteria, orderByClause);
     return bOCol;
 }
        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);
            }

        }
		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_CollectionLoad_Load_NullCriteriaString()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            DateTime now = DateTime.Now;
            ContactPersonTestBO.CreateSavedContactPerson(now);
            ContactPersonTestBO.CreateSavedContactPerson(now);
            ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load("", "Surname");

            //---------------Test Result -----------------------
            Assert.AreEqual(3, col.Count);
        }
 private static BusinessObjectCollection<ContactPersonTestBO> CreateCollectionWithTestPack(string firstName, out ContactPersonTestBO cp1, out ContactPersonTestBO cp2, out ContactPersonTestBO cp3)
 {
     ContactPersonTestBO.LoadDefaultClassDef();
     cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzaaaa", firstName);
     cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName);
     cp3 = ContactPersonTestBO.CreateSavedContactPerson("ZZZZZ", "FirstName");
     BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
     col.Load("", "Surname");
     col.Sort("Surname", true, true);
     return col;
 }
		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 TestAcceptance_SearchGridSearchesTheGrid()
        {
            //---------------Set up test pack-------------------
            //Clear all contact people from the DB
            ContactPerson.DeleteAllContactPeople();
            IClassDef classDef = ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
            //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();
            //Create grid setup for search
            IEditableGridControl gridControl = CreateEditableGridControl();
            ITextBox txtbox = gridControl.FilterControl.AddStringFilterTextBox("Surname", "Surname");
            gridControl.Initialise(classDef);
            gridControl.FilterMode = FilterModes.Search;

            //--------------Assert PreConditions----------------            
            //No items in the grid
            Assert.AreEqual(1, gridControl.Grid.Rows.Count);

            //---------------Execute Test ----------------------
            //set data in grid to a value that should return 2 people
            const string filterByValue = "SSSSS";
            txtbox.Text = filterByValue;
            //grid.filtercontrols.searchbutton.click
            gridControl.OrderBy = "Surname";
            gridControl.FilterControl.ApplyFilter();

            //---------------Test Result -----------------------
            StringAssert.Contains(filterByValue,
                                  gridControl.FilterControl.GetFilterClause().GetFilterClauseString());
            //verify that there are 2 people in the grid.
            Assert.AreEqual(3, gridControl.Grid.Rows.Count);

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load("Surname like %" + filterByValue + "%", "Surname");
            Assert.AreEqual(col.Count + 1, gridControl.Grid.Rows.Count);
            int rowNum = 0;
            foreach (ContactPersonTestBO person in col)
            {
                object rowID = gridControl.Grid.Rows[rowNum++].Cells["HABANERO_OBJECTID"].Value;
                Assert.AreEqual(person.ID.ToString(), rowID.ToString());
            }
            //---------------Tear Down -------------------------   
            ContactPerson.DeleteAllContactPeople();
        }
		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));
		}
Beispiel #29
0
 protected internal static BusinessObjectCollection<BusinessObject> LoadBusinessObjCol(string searchCriteria,
                                                                                       string orderByClause)
 {
     BusinessObjectCollection<BusinessObject> bOCol = new BusinessObjectCollection<BusinessObject>(GetClassDef());
     bOCol.Load(searchCriteria, orderByClause);
     return bOCol;
 }
        public void Test_SearchGrid_AppliesAdditionalSearchCriteria()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = ContactPersonTestBO.LoadDefaultClassDefWithUIDef();

            ContactPersonTestBO boExclude = new ContactPersonTestBO {Surname = "Excude this one."};
            boExclude.Save();

            new ContactPersonTestBO { Surname = "Include this one." }.Save();

            IReadOnlyGridControl grid = CreateReadOnlyGridControl(true);
            grid.AdditionalSearchCriteria = "ContactPersonID <> " + boExclude.ContactPersonID.ToString("B");
            grid.Initialise(classDef);
            grid.FilterControl.Visible = true;
            grid.FilterMode = FilterModes.Search;

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            const string surnameFilterText = "this one";//To prevent tests interacting with other DB Tests.
            col.Load("Surname like %" + surnameFilterText + "%", "");

            //---------------Execute Test ----------------------
            ITextBox surnameFilterTextbox = grid.FilterControl.AddStringFilterTextBox("label", "Surname");

            surnameFilterTextbox.Text = surnameFilterText;
            grid.FilterControl.FilterButton.PerformClick();

            //---------------Test Result -----------------------
            Assert.AreEqual(col.Count - 1, grid.Grid.Rows.Count, "The additional filter should exclude " + boExclude.ID);
        }
 public void Test_Find_ShouldReturnObject()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadDefaultClassDef();
     //            DateTime now = DateTime.Now;
     const string firstName = "abab";
     ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName);
     ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName);
     //            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);
     const string criteria = "FirstName = '" + firstName + "'";
     BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
     col.Load(criteria, "Surname");
     col.Sort("Surname", true, true);
     //---------------Assert Precondition----------------
     Assert.AreEqual(2, col.Count);
     Assert.AreSame(cp2, col[0], "Collection should be in Surname Asc Order");
     Assert.AreSame(cp1, col[1], "Collection should be in Surname Asc Order");
     //---------------Execute Test ----------------------
     ContactPersonTestBO foundCp = col.Find(bo => bo.Surname == "zzzz");
     //---------------Test Result -----------------------
     Assert.IsNotNull(foundCp);
     Assert.AreSame(cp1, foundCp);
 }
        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();
        }
		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_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_CollectionLoad_Load_CriteriaString_ShouldSetUponLoadingCollection()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, "searchSurname");
            const string stringCriteria = "Surname = searchSurname";

            //---------------Execute Test ----------------------
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.Load(stringCriteria, "Surname");

            //---------------Test Result -----------------------
            Assert.AreEqual(criteria, col.SelectQuery.Criteria);
            Assert.AreEqual("ContactPersonTestBO.Surname ASC", col.SelectQuery.OrderCriteria.ToString());
            Assert.AreEqual(-1, col.SelectQuery.Limit);
        }
			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_Sort_WhenOrderCriteriaSetup_AndCollectionSorted_ShouldNotChangeOrder()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadDefaultClassDef();
     //            DateTime now = DateTime.Now;
     const string firstName = "abab";
     ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName);
     ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName);
     //            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);
     const string criteria = "FirstName = '" + firstName + "'";
     BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
     col.Load(criteria, "Surname");
     col.Sort("Surname", true, true);
     //---------------Assert Precondition----------------
     Assert.AreEqual(2, col.Count);
     Assert.AreSame(cp2, col[0], "Collection should be in Surname Asc Order");
     Assert.AreSame(cp1, col[1], "Collection should be in Surname Asc Order");
     //---------------Execute Test ----------------------
     col.Sort();
     //---------------Test Result -----------------------
     Assert.AreEqual(2, col.Count);
     Assert.AreSame(cp2, col[0], "Collection should b sorted by the Surname Property as per the origional collection.Load");
     Assert.AreSame(cp1, col[1]);
 }