Exemplo n.º 1
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();

            TestProjectNoDBSpecificProps.BO.Driver boForRelationshipDrivers = TestUtilsDriver.CreateUnsavedValidDriver();
            boForRelationshipDrivers.Car = car;
            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);
            }
        }
Exemplo n.º 2
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 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(valueForMaxSpeed, retrievedCar.MaxSpeed);
        }
Exemplo n.º 3
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();

            TestProjectNoDBSpecificProps.BO.Driver boForRelationshipDrivers = TestUtilsDriver.CreateUnsavedValidDriver();
            boForRelationshipDrivers.Car = car;
            boForRelationshipDrivers.Save();

            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, car.Drivers.Count);
            //---------------Execute Test ----------------------
            TestProjectNoDBSpecificProps.BO.Driver loadedRelatedBO = Broker.GetBusinessObject <TestProjectNoDBSpecificProps.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]);
        }
        /// <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);
        }
        [Test]  // Checks that deleting this instance has no effect in the related class
        public void Test_SingleRelationshipDeletion_DoNothing_Car()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel();

            TestProjectNoDBSpecificProps.BO.Car boForRelationshipCar = TestUtilsCar.CreateSavedCar();
            steeringWheel.Car = boForRelationshipCar;
            steeringWheel.Save();

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

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

            try
            {
                Broker.GetBusinessObject <SteeringWheel>(steeringWheel.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: SteeringWheel", ex.Message);
            }

            TestProjectNoDBSpecificProps.BO.Car relatedBO = Broker.GetBusinessObject <TestProjectNoDBSpecificProps.BO.Car>(boForRelationshipCar.ID);
            Assert.AreEqual(relatedBO.ID.ToString(), boForRelationshipCar.ID.ToString());
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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.MaxSpeed, loadedCar.MaxSpeed);
        }
        [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 ----------------------
            Car valueForCar = TestUtilsCar.CreateSavedCar();

            steeringWheel.SetPropertyValue("CarID", (object)valueForCar.ID.GetAsGuid());

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForCar, steeringWheel.Car);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
            }
        }