CreateUnsavedValidDriver() public static method

Creates a new unsaved Driver with a random value assigned to every property
public static CreateUnsavedValidDriver ( ) : Driver
return TestProject.BO.Driver
Esempio 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();

            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. 2
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. 3
0
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Driver driver = TestUtilsDriver.CreateUnsavedValidDriver();
            //---------------Assert Precondition----------------

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

            //---------------Test Result -----------------------
            Assert.Fail("Implement ToString() for Driver and refine this test");
            //Assert.AreEqual(driver.SomeProperty, toStringValue);
        }
Esempio n. 4
0
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveDriver()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Driver driver = TestUtilsDriver.CreateUnsavedValidDriver();

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

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

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

            //---------------Test Result -----------------------
            Assert.IsFalse(driver.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
Esempio n. 5
0
        public void Test_NotSettingCompulsoryPropertiesThrowsException()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Driver driver = TestUtilsDriver.CreateUnsavedValidDriver();

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

            //---------------Execute Test ----------------------
            driver.DriverID = null;

            try
            {
                driver.Save();
                Assert.Fail("Should throw an exception when compulsory properties are null");
            }
            //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("Driver ID' is a compulsory field and has no value", ex.Message);
            }
        }