Example #1
0
        public void TestDatabaseReadWrite()
        {
            // Test inserting & selecting
            Shape shape = new Shape();

            shape.ShapeName = "MyShape";
            shape.Save();

            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection <Circle> circles = new BusinessObjectCollection <Circle>();

            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            Circle circle = new Circle();

            circle.Radius    = 5;
            circle.ShapeName = "Circle";
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            circles.LoadAll();
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].CircleID, shapes[0].ShapeID);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID); //still gets inherited
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius    = 10;
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[1].ShapeName);
            circles.LoadAll();
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
        }
        public void TearDown()
        {
            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll();
            Shape[] shapesClone = shapes.ToArray();
            foreach (Shape shape in shapesClone)
            {
                shape.MarkForDelete();
            }
            shapes.SaveAll();
            //Shape shape = BOLoader.Instance.GetBusinessObject<Shape>(
            //    "ShapeName = 'MyShape' OR ShapeName = 'MyShapeChanged'");
            //if (shape != null)
            //{
            //    shape.MarkForDelete();
            //    shape.Save();
            //}

            //CircleNoPrimaryKey circle = BOLoader.Instance.GetBusinessObject<CircleNoPrimaryKey>(
            //    "ShapeName = 'Circle' OR ShapeName = 'CircleChanged'");
            //if (circle != null)
            //{
            //    circle.MarkForDelete();
            //    circle.Save();
            //}

            //FilledCircleInheritsCircleNoPK filledCircle = BOLoader.Instance.GetBusinessObject<FilledCircleInheritsCircleNoPK>(
            //    "ShapeName = 'FilledCircle' OR ShapeName = 'FilledCircleChanged'");
            //if (filledCircle != null)
            //{
            //    filledCircle.MarkForDelete();
            //    filledCircle.Save();
            //}
        }
Example #3
0
        public void Test_CreateBusObject()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.LoadAll();
            RegisterForAddedEvent(cpCol);

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

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

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

            Assert.Contains(newCP, cpCol.CreatedBusinessObjects);
            Assert.Contains(newCP, cpCol);
            Assert.IsFalse(cpCol.PersistedBusinessObjects.Contains(newCP));
            Assert.IsTrue(_addedEventFired);
        }
        protected static IBusinessObjectCollection GetFakeContactPeople()
        {
            BusinessObjectCollection <FakeContactPerson> col = new BusinessObjectCollection <FakeContactPerson>();

            col.LoadAll();
            return(col);
        }
Example #5
0
        public void Test_CreatedBusinessObject_SaveBO()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();

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

            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

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

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

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

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
        public void TestDeleteShapes()
        {
            //-------------Setup Test Pack ------------------
            Shape shape = CreateSavedShape();
            CircleNoPrimaryKey             circle       = CreateSavedCircle();
            FilledCircleInheritsCircleNoPK filledCircle = CreateSavedFilledCircle();

            //-------------Execute test ---------------------
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            filledCircle.MarkForDelete();
            filledCircle.Save();
            //-------------Test Result ----------------------
            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();
            BusinessObjectCollection <CircleNoPrimaryKey>             circles       = new BusinessObjectCollection <CircleNoPrimaryKey>();
            BusinessObjectCollection <FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection <FilledCircleInheritsCircleNoPK>();

            shapes.LoadAll();
            circles.LoadAll();
            filledCircles.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            Assert.AreEqual(0, circles.Count);
            Assert.AreEqual(0, filledCircles.Count);
        }
        public void Test_CreateDisplayValueDictionary_NoSort()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();

            myBO1.Save();
            MyBO myBO2 = new MyBO();

            myBO2.Save();
            MyBO myBO3 = new MyBO();

            myBO3.Save();
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO>();

            myBOs.LoadAll();
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            Dictionary <string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);

            //--------------- Test Result -----------------------
            Assert.AreEqual(3, dictionary.Count);
            Assert.IsTrue(dictionary.ContainsValue(myBO1.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO2.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO3.ID.ToString()));
        }
Example #8
0
        protected override IList <T> LoadItems()
        {
            var availableItemsList = new BusinessObjectCollection <T>();

            availableItemsList.LoadAll();
            return(availableItemsList);
        }
Example #9
0
        public void TestAcceptanceTransactionLog_DB_DeleteContactPerson()
        {
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB          tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp);
            tc.CommitTransaction();
            cp.MarkForDelete();
            tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            var colTransactions =
                new BusinessObjectCollection <TransactionLogBusObj>();

            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            var trLog = colTransactions[colTransactions.Count - 1];

            //CRUD = Deleted
            Assert.AreEqual("Deleted", trLog.CrudAction);

            //---------------Tear Down -------------------------
        }
Example #10
0
        public void TestAcceptanceTransactionLog_DB_NewContactPerson()
        {
            //Test that the transaction log
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB          tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp);
            string dirtyXML = cp.DirtyXML;

            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            BusinessObjectCollection <TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection <TransactionLogBusObj>();

            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            TransactionLogBusObj trLog = colTransactions[colTransactions.Count - 1];

            Assert.AreEqual("Created", trLog.CrudAction);
            Assert.AreEqual(dirtyXML, trLog.DirtyXMLLog);
            Assert.AreEqual("ContactPersonTransactionLogging", trLog.BusinessObjectTypeName);
            //Assert.AreEqual(WindowsIdentity.GetCurrent().Name, trLog.WindowsUser);
            Assert.AreEqual(Environment.MachineName, trLog.MachineUpdatedName);
            //Assert.GreaterOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddMinutes(-1));
            Assert.LessOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddSeconds(1));
            Assert.AreEqual(cp.ToString(), trLog.BusinessObjectToString);
            //---------------Tear Down -------------------------
        }
Example #11
0
        public void TestAcceptanceTransactionLog_SaveMultipleTimes()
        {
            //---------------Cleanup databse ------------------
            CleanDB();
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();

            cp.Save();
            //---------------Execute Test ----------------------
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.MarkForDelete();
            cp.Save();
            BusinessObjectCollection <TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection <TransactionLogBusObj>();

            colTransactions.LoadAll();
            //cp = CreateUnsavedContactPersonTransactionLogging();
            //cp.Save();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            Assert.AreEqual(6, colTransactions.Count);


            //---------------Tear Down -------------------------
        }
        public void TearDown()
        {
            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            Shape[] shapesClone = shapes.ToArray();
            foreach (Shape shape in shapesClone)
            {
                shape.MarkForDelete();
            }
            shapes.SaveAll();
            //Shape shape = BOLoader.Instance.GetBusinessObject<Shape>(
            //    "ShapeName = 'MyShape' OR ShapeName = 'MyShapeChanged'");
            //if (shape != null)
            //{
            //    shape.MarkForDelete();
            //    shape.Save();
            //}

            //CircleNoPrimaryKey circle = BOLoader.Instance.GetBusinessObject<CircleNoPrimaryKey>(
            //    "ShapeName = 'Circle' OR ShapeName = 'CircleChanged'");
            //if (circle != null)
            //{
            //    circle.MarkForDelete();
            //    circle.Save();
            //}

            //FilledCircleInheritsCircleNoPK filledCircle = BOLoader.Instance.GetBusinessObject<FilledCircleInheritsCircleNoPK>(
            //    "ShapeName = 'FilledCircle' OR ShapeName = 'FilledCircleChanged'");
            //if (filledCircle != null)
            //{
            //    filledCircle.MarkForDelete();
            //    filledCircle.Save();
            //}
        }
        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);
        }
        public void TestTodayDateStringCriteria_GreaterThanOrEqualTo()
        {
            //-------------Setup Test Pack ------------------
            DeleteAllContactPeople();
            BusinessObjectCollection <ContactPersonTestBO> myCol = new BusinessObjectCollection <ContactPersonTestBO>();

            myCol.LoadAll();
            DateTime today = DateTime.Today;

            ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(-1), "aaa");
            ContactPersonTestBO.CreateSavedContactPerson(today, "bbb");
            ContactPersonTestBO contactPerson3 = ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(1), "ccc");
            //ContactPersonTestBO.ClearObjectManager();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                                             "ContactPersonTestBO", "DateOfBirth > 'TODAY'", "");

            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);

            //-------------Test Pre-conditions --------------
            Assert.AreEqual(0, myCol.Count);

            //-------------Execute test ---------------------
            Dictionary <string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);

            //-------------Test Result ----------------------
            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid())));
        }
        public void TestLoadCreatedShapes_ShapeAndCircleOnly()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();
            CreateSavedCircle();

            //-------------Execute test ---------------------
            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll("ShapeName");
            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll();
            BusinessObjectCollection <FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection <FilledCircleInheritsCircleNoPK>();

            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            Assert.AreEqual(0, filledCircles.Count);
        }
        private static BusinessObjectCollection <FakeBO2> LoadBOs()
        {
            var availableItemsList = new BusinessObjectCollection <FakeBO2>();

            availableItemsList.LoadAll();
            return(availableItemsList);
        }
        public void TestLoadThenUpdateThenLoadAgain()
        {
            //-------------Setup Test Pack ------------------
            Shape shape = CreateSavedShape();
            CircleNoPrimaryKey               circle       = CreateSavedCircle();
            FilledCircleInheritsCircleNoPK   filledCircle = CreateSavedFilledCircle();
            BusinessObjectCollection <Shape> shapes       = new BusinessObjectCollection <Shape>();
            //shapes.LoadAll();
            //Assert.AreEqual(3, shapes.Count);
            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll();
            Assert.AreEqual(2, circles.Count);
            BusinessObjectCollection <FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection <FilledCircleInheritsCircleNoPK>();

            //-------------Execute test ---------------------

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius    = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius    = 12;
            filledCircle.Colour    = 4;
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);

            circles.LoadAll("ShapeName");
            filledCircles.LoadAll();
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);
        }
Example #18
0
        [Test] // Ensures that a class can be successfully saved
        public void Test_SaveCar()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateUnsavedValidCar();

            //---------------Assert Precondition----------------
            Assert.IsTrue(car.Status.IsNew);
            BusinessObjectCollection<Car> col = new BusinessObjectCollection<Car>();
            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(car.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
        public void TestNowDateStringCriteria()
        {
            DeleteAllContactPeople();
            BusinessObjectCollection <ContactPersonTestBO> myCol = new BusinessObjectCollection <ContactPersonTestBO>();

            myCol.LoadAll();
            Assert.AreEqual(0, myCol.Count);
            ContactPersonTestBO contactPerson1 = new ContactPersonTestBO();

            contactPerson1.Surname     = "aaa";
            contactPerson1.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson1.Save();
            ContactPersonTestBO contactPerson2 = new ContactPersonTestBO();

            contactPerson2.Surname     = "bbb";
            contactPerson2.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson2.Save();
            ContactPersonTestBO contactPerson3 = new ContactPersonTestBO();

            contactPerson3.Surname     = "ccc";
            contactPerson3.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson3.Save();

            //ContactPersonTestBO.ClearObjectManager();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                                             "ContactPersonTestBO", "DateOfBirth < 'Now'", "");

            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);
            Dictionary <string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);

            Assert.AreEqual(3, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson1.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson2.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid())));
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                    "ContactPersonTestBO", "DateOfBirth > 'now'", "")
            {
                PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null)
            };
            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(0, col.Count);
            ContactPersonTestBO contactPerson4 = new ContactPersonTestBO();

            contactPerson4.Surname     = "ddd";
            contactPerson4.DateOfBirth = DateTime.Now.AddMinutes(5);
            contactPerson4.Save();
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                    "ContactPersonTestBO", "DateOfBirth > NOW", "");
            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);

            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson4.ID.GetAsGuid())));
        }
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateUnsavedValidVehicle();

            //---------------Assert Precondition----------------
            Assert.IsTrue(vehicle.Status.IsNew);
            BusinessObjectCollection<Vehicle> col = new BusinessObjectCollection<Vehicle>();
            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(vehicle.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
	    
        }
Example #21
0
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateUnsavedValidVehicle();

            //---------------Assert Precondition----------------
            Assert.IsTrue(vehicle.Status.IsNew);
            BusinessObjectCollection <Vehicle> col = new BusinessObjectCollection <Vehicle>();

            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(vehicle.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveSteeringWheel()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel();

            //---------------Assert Precondition----------------
            Assert.IsTrue(steeringWheel.Status.IsNew);
            BusinessObjectCollection<SteeringWheel> col = new BusinessObjectCollection<SteeringWheel>();
            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(steeringWheel.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
	    
        }
Example #23
0
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveSteeringWheel()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel();

            //---------------Assert Precondition----------------
            Assert.IsTrue(steeringWheel.Status.IsNew);
            BusinessObjectCollection <SteeringWheel> col = new BusinessObjectCollection <SteeringWheel>();

            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(steeringWheel.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
Example #24
0
        [Test] // Ensures that a class can be successfully saved
        public void Test_SaveCar()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateUnsavedValidCar();

            //---------------Assert Precondition----------------
            Assert.IsTrue(car.Status.IsNew);
            BusinessObjectCollection <Car> col = new BusinessObjectCollection <Car>();

            col.LoadAll();
            Assert.AreEqual(0, col.Count);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(car.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
Example #25
0
        public static void ClearAllFromDB()
        {
            BusinessObjectCollection <OrganisationTestBO> col = new BusinessObjectCollection <OrganisationTestBO>();

            col.LoadAll();

            while (col.Count > 0)
            {
                OrganisationTestBO obj = col[0];
                obj.MarkForDelete();
            }
            col.SaveAll();
        }
Example #26
0
        public static void ClearTable()
        {
            BusinessObjectCollection <OrderItem> col = new BusinessObjectCollection <OrderItem>();

            col.LoadAll();
            OrderItem item;

            while (col.Count > 0)
            {
                item = col[0];
                item.MarkForDelete();
            }
            col.SaveAll();
        }
        public void TestLoadCreatedShapes_ShapeAndCircleAndFilledCircle()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();
            CreateSavedCircle();
            CreateSavedFilledCircle();

            //-------------Execute test ---------------------
            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll("ShapeName");
            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll("ShapeName");
            BusinessObjectCollection <FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection <FilledCircleInheritsCircleNoPK>();

            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(3, shapes.Count);

            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);

            Shape filledCircleShape = shapes[1];

            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);
            CircleNoPrimaryKey filledCircleCircle = circles[1];

            Assert.AreEqual(filledCircleShape.ShapeID, filledCircleCircle.ShapeID);
            Assert.AreEqual(7, filledCircleCircle.Radius);

            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, filledCircleShape.ShapeID);
            FilledCircleInheritsCircleNoPK filledCircle = filledCircles[0];

            Assert.AreEqual(7, filledCircle.Radius);
            Assert.AreEqual("FilledCircle", filledCircle.ShapeName);
            Assert.AreEqual(3, filledCircle.Colour);
        }
        public void TestSetupComboBoxFromClassDef_SetsItemsInComboBox()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

            OrganisationTestBO.LoadDefaultClassDef();
            ContactPerson.DeleteAllContactPeople();
            OrganisationTestBO.ClearAllFromDB();
            OrganisationTestBO.CreateSavedOrganisation();
            OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            TestUtil.WaitForGC();
            BusinessObjectCollection <ContactPersonTestBO> col = new BusinessObjectCollection <ContactPersonTestBO>();

            col.LoadAll();

            IEditableGridControl gridControl     = GetControlFactory().CreateEditableGridControl();
            GridInitialiser      gridInitialiser = new GridInitialiser(gridControl, GetControlFactory());

            //--------------Assert PreConditions----------------
            Assert.AreEqual(0, gridControl.Grid.Columns.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            const string uiDefName = "default";
            IUIGrid      uiGridDef = classDef.UIDefCol[uiDefName].UIGrid;

            Assert.IsNotNull(uiGridDef);
            Assert.AreEqual(1, uiGridDef.Count);
            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(2,
                            BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <OrganisationTestBO>
                                ("").Count);

            //---------------Execute Test ----------------------
            gridInitialiser.InitialiseGrid(classDef, uiDefName);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, gridControl.Grid.Columns.Count, "Should have ID column and should have comboBoxColumn");
            IDataGridViewColumn dataGridViewColumn = gridControl.Grid.Columns[1];

            AssertIsComboBoxColumnType(dataGridViewColumn);
            AssertComboBoxItemCount(dataGridViewColumn, 3);
        }
        public void TestLoadCreatedShapes_ShapeOnly()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();

            //-------------Execute test ---------------------
            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll();
            BusinessObjectCollection <FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection <FilledCircleInheritsCircleNoPK>();

            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(1, shapes.Count);
            Assert.AreEqual(0, circles.Count);
            Assert.AreEqual(0, filledCircles.Count);
        }
        public void Test_CreateBusObject()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.LoadAll();
            RegisterForAddedEvent(cpCol);

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

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

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

            Assert.Contains(newCP, cpCol.CreatedBusinessObjects);
            Assert.Contains(newCP, cpCol);
            Assert.IsFalse(cpCol.PersistedBusinessObjects.Contains(newCP));
            Assert.IsTrue(_addedEventFired);
        }
        public void TestDatabaseReadWrite()
        {
            // Test inserting & selecting
            Shape shape = new Shape {ShapeName = "MyShape"};
            shape.Save();

            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            BusinessObjectCollection<FilledCircleNoPrimaryKey> filledCircles =
                new BusinessObjectCollection<FilledCircleNoPrimaryKey>();
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);

            CircleNoPrimaryKey circle = new CircleNoPrimaryKey {Radius = 5, ShapeName = "Circle"};
            circle.Save();

            FixtureEnvironment.ClearBusinessObjectManager();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            FixtureEnvironment.ClearBusinessObjectManager();
            circles.LoadAll();
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey
                                                        {
                                                            Colour = 3,
                                                            Radius = 7,
                                                            ShapeName = "FilledCircle"
                                                        };
            filledCircle.Save();

            FixtureEnvironment.ClearBusinessObjectManager();
            shapes.LoadAll("ShapeName");
            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);
            Assert.That(shapes[0], Is.InstanceOf(typeof(CircleNoPrimaryKey)));
            Assert.That(shapes[1], Is.InstanceOf(typeof(FilledCircleNoPrimaryKey)));
            Assert.That(shapes[2], Is.InstanceOf(typeof(Shape)));

            circles.LoadAll("ShapeName");
            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual(circles[1].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, circles[1].Radius);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);

            filledCircles.LoadAll();
            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName);
            Assert.AreEqual(3, filledCircles[0].Colour);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius = 12;
            filledCircle.Colour = 4;
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);
            circles.LoadAll("ShapeName");
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);
            filledCircles.LoadAll();
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            filledCircle.MarkForDelete();
            filledCircle.Save();

            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            Assert.AreEqual(0, shapes.PersistedBusinessObjects.Count);
            Assert.AreEqual(0, shapes.CreatedBusinessObjects.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);
        }
        public void TestTodayDateStringCriteria_GreaterThanOrEqualTo()
        {
            //-------------Setup Test Pack ------------------
            DeleteAllContactPeople();
            BusinessObjectCollection<ContactPersonTestBO> myCol = new BusinessObjectCollection<ContactPersonTestBO>();
            myCol.LoadAll();
            DateTime today = DateTime.Today;
            ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(-1), "aaa");
            ContactPersonTestBO.CreateSavedContactPerson(today, "bbb");
            ContactPersonTestBO contactPerson3 = ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(1), "ccc");
            //ContactPersonTestBO.ClearObjectManager();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                    "ContactPersonTestBO", "DateOfBirth > 'TODAY'", "");
            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);

            //-------------Test Pre-conditions --------------
            Assert.AreEqual(0, myCol.Count);

            //-------------Execute test ---------------------
            Dictionary<string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);

            //-------------Test Result ----------------------
            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid())));
        }
        public void TestLoadCreatedShapes_ShapeOnly()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();

            //-------------Execute test ---------------------
            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll();
            BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
            circles.LoadAll();
            BusinessObjectCollection<FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection<FilledCircleInheritsCircleNoPK>();
            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(1, shapes.Count);
            Assert.AreEqual(0, circles.Count);
            Assert.AreEqual(0, filledCircles.Count);
        }
        public void TestLoadCreatedShapes_ShapeAndCircleAndFilledCircle()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();
            CreateSavedCircle();
            CreateSavedFilledCircle();

            //-------------Execute test ---------------------
            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll("ShapeName");
            BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
            circles.LoadAll("ShapeName");
            BusinessObjectCollection<FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection<FilledCircleInheritsCircleNoPK>();
            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(3, shapes.Count);

            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);

            Shape filledCircleShape = shapes[1];

            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);
            CircleNoPrimaryKey filledCircleCircle = circles[1];
            Assert.AreEqual(filledCircleShape.ShapeID, filledCircleCircle.ShapeID);
            Assert.AreEqual(7, filledCircleCircle.Radius);

            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, filledCircleShape.ShapeID);
            FilledCircleInheritsCircleNoPK filledCircle = filledCircles[0];
            Assert.AreEqual(7, filledCircle.Radius);
            Assert.AreEqual("FilledCircle", filledCircle.ShapeName);
            Assert.AreEqual(3, filledCircle.Colour);
        }
        public void TestNowDateStringCriteria()
        {
            DeleteAllContactPeople();
            BusinessObjectCollection<ContactPersonTestBO> myCol = new BusinessObjectCollection<ContactPersonTestBO>();
            myCol.LoadAll();
            Assert.AreEqual(0, myCol.Count);
            ContactPersonTestBO contactPerson1 = new ContactPersonTestBO();
            contactPerson1.Surname = "aaa";
            contactPerson1.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson1.Save();
            ContactPersonTestBO contactPerson2 = new ContactPersonTestBO();
            contactPerson2.Surname = "bbb";
            contactPerson2.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson2.Save();
            ContactPersonTestBO contactPerson3 = new ContactPersonTestBO();
            contactPerson3.Surname = "ccc";
            contactPerson3.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson3.Save();

            //ContactPersonTestBO.ClearObjectManager();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                                             "ContactPersonTestBO", "DateOfBirth < 'Now'", "");
            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);
            Dictionary<string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(3, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson1.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson2.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid())));
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                "ContactPersonTestBO", "DateOfBirth > 'now'", "")
                   {
                       PropDef = new PropDef ("name", typeof (string), PropReadWriteRule.ReadWrite, null)
                   };
            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(0, col.Count);
            ContactPersonTestBO contactPerson4 = new ContactPersonTestBO();
            contactPerson4.Surname = "ddd";
            contactPerson4.DateOfBirth = DateTime.Now.AddMinutes(5);
            contactPerson4.Save();
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                "ContactPersonTestBO", "DateOfBirth > NOW", "");
            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);

            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson4.ID.GetAsGuid())));
        }
        public void Test_CreateDisplayValueDictionary_NoSort()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();
            myBO1.Save();
            MyBO myBO2 = new MyBO();
            myBO2.Save();
            MyBO myBO3 = new MyBO();
            myBO3.Save();
            BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO>();
            myBOs.LoadAll();            
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            Dictionary<string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);
            //--------------- Test Result -----------------------
            Assert.AreEqual(3, dictionary.Count);
            Assert.IsTrue(dictionary.ContainsValue(myBO1.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO2.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO3.ID.ToString()));
        }        
Example #37
0
		public static void ClearTable()
		{
			BusinessObjectCollection<OrderItem> col = new BusinessObjectCollection<OrderItem>();
			col.LoadAll();
			OrderItem item;
			while (col.Count > 0)
			{
				item = col[0];
				item.MarkForDelete();
			}
			col.SaveAll();
		}
        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 TestDatabaseReadWrite()
        {
            
            // Test inserting & selecting
            Shape shape = new Shape();
            shape.ShapeName = "MyShape";
            shape.Save();

            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection<Circle> circles = new BusinessObjectCollection<Circle>();
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            BusinessObjectCollection<FilledCircle> filledCircles = new BusinessObjectCollection<FilledCircle>();
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);

            Circle circle = new Circle();
            circle.Radius = 5;
            circle.ShapeName = "Circle";
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            circles.LoadAll("ShapeName");
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            FilledCircle filledCircle = new FilledCircle();
            filledCircle.Colour = 3;
            filledCircle.Radius = 7;
            filledCircle.ShapeName = "FilledCircle";
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);

            circles.LoadAll("ShapeName");
            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(7, circles[1].Radius);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);

            filledCircles.LoadAll();
            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName);
            Assert.AreEqual(3, filledCircles[0].Colour);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius = 12;
            filledCircle.Colour = 4;
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);
            circles.LoadAll("ShapeName");
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);
            filledCircles.LoadAll();
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            filledCircle.MarkForDelete();
            filledCircle.Save();

            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);
        }
Example #40
0
        public void TestDatabaseReadWrite()
        {
            FixtureEnvironment.ClearBusinessObjectManager();
            // Test inserting & selecting
            Shape shape = new Shape();

            shape.ShapeName = "MyShape";
            shape.Save();

            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            CircleNoPrimaryKey circle = new CircleNoPrimaryKey();

            circle.Radius    = 5;
            circle.ShapeName = "Circle";
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            circles.LoadAll();
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.IsFalse(circles[0].Props.Contains("CircleID"));
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius    = 10;
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[1].ShapeName);
            circles.LoadAll();
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
        }
        public void TestDatabaseReadWrite()
        {
            // Test inserting & selecting
            Shape shape = new Shape {
                ShapeName = "MyShape"
            };

            shape.Save();

            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>();

            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            BusinessObjectCollection <FilledCircleNoPrimaryKey> filledCircles =
                new BusinessObjectCollection <FilledCircleNoPrimaryKey>();

            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);

            CircleNoPrimaryKey circle = new CircleNoPrimaryKey {
                Radius = 5, ShapeName = "Circle"
            };

            circle.Save();

            FixtureEnvironment.ClearBusinessObjectManager();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            FixtureEnvironment.ClearBusinessObjectManager();
            circles.LoadAll();
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey
            {
                Colour    = 3,
                Radius    = 7,
                ShapeName = "FilledCircle"
            };

            filledCircle.Save();

            FixtureEnvironment.ClearBusinessObjectManager();
            shapes.LoadAll("ShapeName");
            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);
            Assert.That(shapes[0], Is.InstanceOf(typeof(CircleNoPrimaryKey)));
            Assert.That(shapes[1], Is.InstanceOf(typeof(FilledCircleNoPrimaryKey)));
            Assert.That(shapes[2], Is.InstanceOf(typeof(Shape)));

            circles.LoadAll("ShapeName");
            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual(circles[1].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, circles[1].Radius);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);

            filledCircles.LoadAll();
            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName);
            Assert.AreEqual(3, filledCircles[0].Colour);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius    = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius    = 12;
            filledCircle.Colour    = 4;
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);
            circles.LoadAll("ShapeName");
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);
            filledCircles.LoadAll();
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            filledCircle.MarkForDelete();
            filledCircle.Save();

            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            Assert.AreEqual(0, shapes.PersistedBusinessObjects.Count);
            Assert.AreEqual(0, shapes.CreatedBusinessObjects.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);
        }
        public static void ClearAllFromDB()
        {
            BusinessObjectCollection<OrganisationTestBO> col = new BusinessObjectCollection<OrganisationTestBO>();
            col.LoadAll();

            while (col.Count > 0)
            {
                OrganisationTestBO obj = col[0];
                obj.MarkForDelete();   
            }
            col.SaveAll();
        }
        public void TestDatabaseReadWrite()
        {
            // Test inserting & selecting
            Shape shape = new Shape();
            shape.ShapeName = "MyShape";
            shape.Save();

            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection<Circle> circles = new BusinessObjectCollection<Circle>();
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            Circle circle = new Circle();
            circle.Radius = 5;
            circle.ShapeName = "Circle";
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            circles.LoadAll();
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].CircleID, shapes[0].ShapeID);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID); //still gets inherited
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius = 10;
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[1].ShapeName);
            circles.LoadAll();
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
        }
        public void Test_CreatedBusinessObject_SaveBO()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in 
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();

            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.LoadAll();

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

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

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

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
Example #45
0
        public void TestDatabaseReadWrite()
        {
            // Test inserting & selecting
            Shape shape = new Shape();

            shape.ShapeName = "MyShape";
            shape.Save();

            BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>();

            shapes.LoadAll();
            Assert.AreEqual(1, shapes.Count);

            BusinessObjectCollection <Circle> circles = new BusinessObjectCollection <Circle>();

            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);

            BusinessObjectCollection <FilledCircle> filledCircles = new BusinessObjectCollection <FilledCircle>();

            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);

            Circle circle = new Circle();

            circle.Radius    = 5;
            circle.ShapeName = "Circle";
            circle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            circles.LoadAll("ShapeName");
            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            FilledCircle filledCircle = new FilledCircle();

            filledCircle.Colour    = 3;
            filledCircle.Radius    = 7;
            filledCircle.ShapeName = "FilledCircle";
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircle", shapes[1].ShapeName);
            Assert.AreEqual("MyShape", shapes[2].ShapeName);

            circles.LoadAll("ShapeName");
            Assert.AreEqual(2, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(7, circles[1].Radius);
            Assert.AreEqual("FilledCircle", circles[1].ShapeName);

            filledCircles.LoadAll();
            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID);
            Assert.AreEqual(7, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName);
            Assert.AreEqual(3, filledCircles[0].Colour);

            // Test updating
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius    = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius    = 12;
            filledCircle.Colour    = 4;
            filledCircle.Save();

            shapes.LoadAll("ShapeName");
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);
            circles.LoadAll("ShapeName");
            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);
            filledCircles.LoadAll();
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);

            // Test deleting
            shape.MarkForDelete();
            shape.Save();
            circle.MarkForDelete();
            circle.Save();
            filledCircle.MarkForDelete();
            filledCircle.Save();

            shapes.LoadAll();
            Assert.AreEqual(0, shapes.Count);
            circles.LoadAll();
            Assert.AreEqual(0, circles.Count);
            filledCircles.LoadAll();
            Assert.AreEqual(0, filledCircles.Count);
        }
 public void TestFilterControlStillVisibleAfterSetCollection()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
     IReadOnlyGridControl grid = GetControlFactory().CreateReadOnlyGridControl();
     grid.FilterControl.AddStringFilterTextBox("Surname", "Surname");
     grid.FilterControl.Visible = true;
     grid.FilterMode = FilterModes.Search;
     BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
     col.LoadAll();
     //---------------Assert PreConditions---------------     
     Assert.IsTrue(grid.FilterControl.Visible);
     //---------------Execute Test ----------------------
     grid.SetBusinessObjectCollection(col);
     //---------------Tear Down ------------------------- 
     Assert.IsTrue(grid.FilterControl.Visible);
 }
 protected static BusinessObjectCollection<MyBO> CreateSavedMyBoCollection()
 {
     CreateSavedMyBo();
     CreateSavedMyBo();
     BusinessObjectCollection<MyBO> myBos = new BusinessObjectCollection<MyBO>();
     myBos.LoadAll("");
     return myBos;
 }
        public void PopulateCollectionAsync_WithCallback_RespectsSynchronousGlobalHint()
        {
            //---------------Set up test pack-------------------
            GlobalUIRegistry.AsyncSettings.SynchroniseBackgroundOperations = true;
            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 = "Surname <> '" + boExclude.Surname + "'";
            grid.Initialise(classDef);

            grid.FilterControl.Visible = true;
            grid.FilterMode = FilterModes.Filter;

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.LoadAll();
            var afterPopCalled = false;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            grid.PopulateCollectionAsync(() => { Thread.Sleep(100); return col; }, () => { afterPopCalled = true; });
            
            //---------------Test Result -----------------------
            Assert.IsNotNull(grid.BusinessObjectCollection);
            Assert.IsTrue(afterPopCalled);
        }
 public void TestDeleteShapes()
 {
     //-------------Setup Test Pack ------------------
     Shape shape = CreateSavedShape();
     CircleNoPrimaryKey circle = CreateSavedCircle();
     FilledCircleInheritsCircleNoPK filledCircle = CreateSavedFilledCircle();
     //-------------Execute test ---------------------
     shape.MarkForDelete();
     shape.Save();
     circle.MarkForDelete();
     circle.Save();
     filledCircle.MarkForDelete();
     filledCircle.Save();
     //-------------Test Result ----------------------
     BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
     BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
     BusinessObjectCollection<FilledCircleInheritsCircleNoPK> filledCircles =
         new BusinessObjectCollection<FilledCircleInheritsCircleNoPK>();
     shapes.LoadAll();
     circles.LoadAll();
     filledCircles.LoadAll();
     Assert.AreEqual(0, shapes.Count);
     Assert.AreEqual(0, circles.Count);
     Assert.AreEqual(0, filledCircles.Count);
 }
        public void Test_FilterGrid_AppliesAdditionalSearchCriteria_NoFilterCriteria()
        {
            //---------------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 = "Surname <> '" + boExclude.Surname + "'";
            grid.Initialise(classDef);

            grid.FilterControl.Visible = true;
            grid.FilterMode = FilterModes.Filter;

            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.LoadAll();
            grid.BusinessObjectCollection = col;
            //---------------Execute Test ----------------------
            grid.FilterControl.ApplyFilter();

            //---------------Test Result -----------------------
            Assert.AreEqual(col.Count - 1, grid.Grid.Rows.Count, "The additional filter should exclude " + boExclude.ID);
        }
        public void TestLoadCreatedShapes_ShapeAndCircleOnly()
        {
            //-------------Setup Test Pack ------------------
            CreateSavedShape();
            CreateSavedCircle();

            //-------------Execute test ---------------------
            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            shapes.LoadAll("ShapeName");
            BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
            circles.LoadAll();
            BusinessObjectCollection<FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection<FilledCircleInheritsCircleNoPK>();
            filledCircles.LoadAll();

            //-------------Test Result ----------------------
            Assert.AreEqual(2, shapes.Count);
            Assert.AreEqual("Circle", shapes[0].ShapeName);
            Assert.AreEqual("MyShape", shapes[1].ShapeName);

            Assert.AreEqual(1, circles.Count);
            Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID);
            Assert.AreEqual(5, circles[0].Radius);
            Assert.AreEqual("Circle", circles[0].ShapeName);

            Assert.AreEqual(0, filledCircles.Count);
        }
        public void TestSetupComboBoxFromClassDef_SetsItemsInComboBox()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPerson.DeleteAllContactPeople();
            OrganisationTestBO.ClearAllFromDB();
            OrganisationTestBO.CreateSavedOrganisation();
            OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            TestUtil.WaitForGC();
            BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.LoadAll();

            IEditableGridControl gridControl = GetControlFactory().CreateEditableGridControl();
            GridInitialiser gridInitialiser = new GridInitialiser(gridControl, GetControlFactory());

            //--------------Assert PreConditions----------------            
            Assert.AreEqual(0, gridControl.Grid.Columns.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            const string uiDefName = "default";
            IUIGrid uiGridDef = classDef.UIDefCol[uiDefName].UIGrid;
            Assert.IsNotNull(uiGridDef);
            Assert.AreEqual(1, uiGridDef.Count);
            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(2,
                            BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<OrganisationTestBO>
                                ("").Count);

            //---------------Execute Test ----------------------
            gridInitialiser.InitialiseGrid(classDef, uiDefName);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, gridControl.Grid.Columns.Count, "Should have ID column and should have comboBoxColumn");
            IDataGridViewColumn dataGridViewColumn = gridControl.Grid.Columns[1];
            AssertIsComboBoxColumnType(dataGridViewColumn);
            AssertComboBoxItemCount(dataGridViewColumn, 3);
        }
        public void TestLoadUpdatedShapes()
        {
            //-------------Setup Test Pack ------------------
            Shape shape = CreateSavedShape();
            CircleNoPrimaryKey circle = CreateSavedCircle();
            FilledCircleInheritsCircleNoPK filledCircle = CreateSavedFilledCircle();
            shape.ShapeName = "MyShapeChanged";
            shape.Save();
            circle.ShapeName = "CircleChanged";
            circle.Radius = 10;
            circle.Save();
            filledCircle.ShapeName = "FilledCircleChanged";
            filledCircle.Radius = 12;
            filledCircle.Colour = 4;
            filledCircle.Save();

            //-------------Execute test ---------------------
            BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>();
            BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>();
            BusinessObjectCollection<FilledCircleInheritsCircleNoPK> filledCircles =
                new BusinessObjectCollection<FilledCircleInheritsCircleNoPK>();
            shapes.LoadAll("ShapeName");
            circles.LoadAll("ShapeName");
            filledCircles.LoadAll("ShapeName");

            //-------------Test Result ----------------------
            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual("CircleChanged", shapes[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName);
            Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName);

            Assert.AreEqual(2, circles.Count);

            Assert.AreEqual(10, circles[0].Radius);
            Assert.AreEqual(12, circles[1].Radius);
            Assert.AreEqual("CircleChanged", circles[0].ShapeName);
            Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName);

            Assert.AreEqual(1, filledCircles.Count);
            Assert.AreEqual(4, filledCircles[0].Colour);
            Assert.AreEqual(12, filledCircles[0].Radius);
            Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName);
        }
        public void TestAcceptanceTransactionLog_SaveMultipleTimes()
        {
            //---------------Cleanup databse ------------------
            CleanDB();
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            cp.Save();
            //---------------Execute Test ----------------------
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.MarkForDelete();
            cp.Save();
            BusinessObjectCollection<TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection<TransactionLogBusObj>();
            colTransactions.LoadAll();
            //cp = CreateUnsavedContactPersonTransactionLogging();
            //cp.Save();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            Assert.AreEqual(6, colTransactions.Count);


            //---------------Tear Down -------------------------          
        }
        public void Test_SearchGrid_AppliesAdditionalSearchCriteria_NoFilterCriteria()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = ContactPersonTestBO.LoadDefaultClassDefWithUIDef();

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

            ContactPersonTestBO boInclude = new ContactPersonTestBO();
            boInclude.Surname = "Include this one.";
            boInclude.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>();
            col.LoadAll();

            //---------------Execute Test ----------------------
            grid.FilterControl.FilterButton.PerformClick();

            //---------------Test Result -----------------------
            Assert.AreEqual(col.Count - 1, grid.Grid.Rows.Count, "The additional filter should exclude " + boExclude.ID);
        }
        public void TestAcceptanceTransactionLog_DB_DeleteContactPerson()
        {
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            tc.CommitTransaction();
            cp.MarkForDelete();
            tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            var colTransactions =
                new BusinessObjectCollection<TransactionLogBusObj>();
            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            var trLog = colTransactions[colTransactions.Count - 1];

            //CRUD = Deleted
            Assert.AreEqual("Deleted", trLog.CrudAction);

            //---------------Tear Down -------------------------          
        }
 protected static IBusinessObjectCollection GetFakeContactPeople()
 {
     BusinessObjectCollection<FakeContactPerson> col = new BusinessObjectCollection<FakeContactPerson>();
     col.LoadAll();
     return col;
 }
        public void TestAcceptanceTransactionLog_DB_NewContactPerson()
        {
            //Test that the transaction log 
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            string dirtyXML = cp.DirtyXML;
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            BusinessObjectCollection<TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection<TransactionLogBusObj>();
            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            TransactionLogBusObj trLog = colTransactions[colTransactions.Count - 1];
            Assert.AreEqual("Created", trLog.CrudAction);
            Assert.AreEqual(dirtyXML, trLog.DirtyXMLLog);
            Assert.AreEqual("ContactPersonTransactionLogging", trLog.BusinessObjectTypeName);
            //Assert.AreEqual(WindowsIdentity.GetCurrent().Name, trLog.WindowsUser);
            Assert.AreEqual(Environment.MachineName, trLog.MachineUpdatedName);
            //Assert.GreaterOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddMinutes(-1));
            Assert.LessOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddSeconds(1));
            Assert.AreEqual(cp.ToString(),trLog.BusinessObjectToString);
            //---------------Tear Down -------------------------          
        }