Esempio n. 1
0
        [Test] // Checks that a related collection loads correctly (no tampering with class defs)
        public void Test_LoadThroughMultipleRelationship_Drivers()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Car car = TestUtilsCar.CreateSavedCar();

            TestProject.BO.Driver boForRelationshipDrivers = TestUtilsDriver.CreateUnsavedValidDriver();
            boForRelationshipDrivers.CarID = car.VehicleID;
            boForRelationshipDrivers.Save();

            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, car.Drivers.Count);
            //---------------Execute Test ----------------------
            TestProject.BO.Driver loadedRelatedBO =
                Broker.GetBusinessObject <TestProject.BO.Driver>(boForRelationshipDrivers.ID);
            Car loadedCar = Broker.GetBusinessObject <Car>(car.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedCar.Drivers.Count);
            Assert.AreEqual(boForRelationshipDrivers, loadedCar.Drivers[0]);
            Assert.AreEqual(loadedRelatedBO, loadedCar.Drivers[0]);
            Assert.AreEqual(loadedRelatedBO, car.Drivers[0]);
        }
Esempio n. 2
0
        [Test] // Checks that deletion is prevented when a child exists
        public void Test_MultipleRelationshipDeletion_PreventDelete_Drivers()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateSavedCar();

            TestProject.BO.Driver boForRelationshipDrivers = TestUtilsDriver.CreateUnsavedValidDriver();
            boForRelationshipDrivers.CarID = car.VehicleID;
            boForRelationshipDrivers.Save();

            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, car.Drivers.Count);
            IRelationshipDef relationshipDef = ClassDef.Get <Car>().RelationshipDefCol["Drivers"];

            Assert.AreEqual(DeleteParentAction.Prevent, relationshipDef.DeleteParentAction);
            //---------------Execute Test ----------------------
            try
            {
                car.MarkForDelete();
                car.Save();
                Assert.Fail("Should have thrown exception due to deletion prevention");
            }
            //---------------Test Result -----------------------
            catch (BusObjDeleteException ex)
            {
                StringAssert.Contains("You cannot delete Car identified by ", ex.Message);
                StringAssert.Contains("via the Drivers relationship", ex.Message);
            }
        }
Esempio n. 3
0
        [Test] // Ensures that updates to property values are stored and can be retrieved
        public void Test_UpdateCar()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateSavedCar();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForMake = TestUtilsShared.GetRandomString();

            car.Make = (System.String)valueForMake;
            object valueForModel = TestUtilsShared.GetRandomString();

            car.Model = (System.String)valueForModel;
            object valueForVehicleType = TestUtilsShared.GetRandomString();

            car.VehicleType = (System.String)valueForVehicleType;
            object valueForMaxSpeed = (double)TestUtilsShared.GetRandomInt();

            car.MaxSpeed = (System.Double)valueForMaxSpeed;
            car.Save();

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            Car retrievedCar = Broker.GetBusinessObject <Car>(car.ID);

            Assert.AreEqual(valueForMake, retrievedCar.Make);
            Assert.AreEqual(valueForModel, retrievedCar.Model);
            Assert.AreEqual(valueForVehicleType, retrievedCar.VehicleType);
            Assert.AreEqual(valueForMaxSpeed, retrievedCar.MaxSpeed);
        }
        /// <summary>
        /// Creates a new unsaved SteeringWheel with a random value assigned to every property
        /// </summary>
        public static SteeringWheel CreateUnsavedValidSteeringWheel()
        {
            SteeringWheel steeringWheel = new SteeringWheel();

            steeringWheel.Car = TestUtilsCar.CreateSavedCar();
            return(steeringWheel);
        }
Esempio n. 5
0
        [Test] // Ensures that a class can be deleted
        public void Test_DeleteCar()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateSavedCar();

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

            //---------------Execute Test ----------------------
            car.MarkForDelete();
            car.Save();
            //---------------Test Result -----------------------
            try
            {
                Broker.GetBusinessObject <Car>(car.ID);
                Assert.Fail("expected Err");
            }
            catch (BusObjDeleteConcurrencyControlException ex)
            {
                StringAssert.Contains(
                    "A Error has occured since the object you are trying to refresh has been deleted by another user",
                    ex.Message);
                StringAssert.Contains("There are no records in the database for the Class: Car", ex.Message);
            }
        }
Esempio n. 6
0
        [Test]  // Checks that deleting this instance has no effect in the related class
        public void Test_SingleRelationshipDeletion_DoNothing_Car()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Driver driver = TestUtilsDriver.CreateSavedDriver();

            TestProject.BO.Car boForRelationshipCar = TestUtilsCar.CreateSavedCar();
            driver.Car = boForRelationshipCar;
            driver.Save();

            //---------------Assert Preconditions---------------
            IRelationshipDef relationshipDef = ClassDef.Get <Driver>().RelationshipDefCol["Car"];

            Assert.AreEqual(DeleteParentAction.DoNothing, relationshipDef.DeleteParentAction);
            //---------------Execute Test ----------------------
            driver.MarkForDelete();
            driver.Save();
            //---------------Execute Test ----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();

            try
            {
                Broker.GetBusinessObject <Driver>(driver.ID);
                Assert.Fail("BO should no longer exist and exception should be thrown");
            }
            catch (BusObjDeleteConcurrencyControlException ex)
            {
                StringAssert.Contains("There are no records in the database for the Class: Driver", ex.Message);
            }

            TestProject.BO.Car relatedBO = Broker.GetBusinessObject <TestProject.BO.Car>(boForRelationshipCar.ID);
            Assert.AreEqual(relatedBO.ID.ToString(), boForRelationshipCar.ID.ToString());
        }
Esempio n. 7
0
        [Test]  // Ensures that property setters in the code point to the correct property
        public void Test_PropertySettersUseCorrectPropertyNames()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Driver driver = new Driver();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForDriverName = TestUtilsShared.GetRandomString();

            driver.SetPropertyValue("DriverName", valueForDriverName);
            object valueForAge = TestUtilsShared.GetRandomInt();

            driver.SetPropertyValue("Age", valueForAge);
            object valueForDOB = TestUtilsShared.GetRandomDate();

            driver.SetPropertyValue("DOB", valueForDOB);
            object valueForLicenseRaing = (double)TestUtilsShared.GetRandomInt();

            driver.SetPropertyValue("LicenseRaing", valueForLicenseRaing);
            object valueForCarID = TestUtilsCar.CreateSavedCar().VehicleID;

            driver.SetPropertyValue("CarID", valueForCarID);

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForDriverName, driver.DriverName);
            Assert.AreEqual(valueForAge, driver.Age);
            Assert.AreEqual(valueForDOB, driver.DOB);
            Assert.AreEqual(valueForLicenseRaing, driver.LicenseRaing);
            Assert.AreEqual(valueForCarID, driver.CarID);
        }
        /// <summary>
        /// Creates a new unsaved Driver with a random value assigned to every property
        /// </summary>
        public static Driver CreateUnsavedValidDriver()
        {
            Driver driver = new Driver();

            driver.DriverName   = TestUtilsShared.GetRandomString();
            driver.Age          = TestUtilsShared.GetRandomInt();
            driver.DOB          = TestUtilsShared.GetRandomDate();
            driver.LicenseRaing = (double)TestUtilsShared.GetRandomInt();
            driver.Car          = TestUtilsCar.CreateSavedCar();
            return(driver);
        }
Esempio n. 9
0
        public void Test_Inheritance_CodeClass_InheritsCorrectly()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Car car = TestUtilsCar.CreateUnsavedValidCar();

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <Vehicle>(car);
        }
Esempio n. 10
0
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Car car = TestUtilsCar.CreateUnsavedValidCar();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string toStringValue = car.ToString();

            //---------------Test Result -----------------------
            Assert.Fail("Implement ToString() for Car and refine this test");
            //Assert.AreEqual(car.SomeProperty, toStringValue);
        }
Esempio n. 11
0
        [Test]  // Ensures that property setters in the code point to the correct property
        public void Test_PropertySettersUseCorrectPropertyNames()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            SteeringWheel steeringWheel = new SteeringWheel();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForCarID = TestUtilsCar.CreateSavedCar().VehicleID;

            steeringWheel.SetPropertyValue("CarID", valueForCarID);

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForCarID, steeringWheel.CarID);
        }
Esempio n. 12
0
        [Test] // Ensures that a saved class can be loaded
        public void Test_LoadCar()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateSavedCar();

            //---------------Execute Test ----------------------
            Car loadedCar = Broker.GetBusinessObject <Car>(car.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(car.Make, loadedCar.Make);
            Assert.AreEqual(car.Model, loadedCar.Model);
            Assert.AreEqual(car.VehicleID, loadedCar.VehicleID);
            Assert.AreEqual(car.VehicleType, loadedCar.VehicleType);
            Assert.AreEqual(car.MaxSpeed, loadedCar.MaxSpeed);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        [Test] // Makes sure there are no non-null rules in the database that don't have corresponding compulsory rules
        public void Test_SetPropertyValue_Null()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = TestUtilsCar.CreateSavedCar();

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

            //---------------Execute Test ----------------------
            car.Make  = null;
            car.Model = null;
            car.Save();

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            Car retrievedCar =
                Broker.GetBusinessObject <Car>(car.ID);

            Assert.IsNull(retrievedCar.Make);
            Assert.IsNull(retrievedCar.Model);
        }