Inheritance: BusinessObject
Example #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]);
        }
Example #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);
            }
        }
        /// <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;
		}
        [Test]  // Ensures that the defaults have not been tampered
        public void Test_CreateDriverWithDefaults()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------

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

            //---------------Execute Test ----------------------
            Driver driver = new Driver();

            //---------------Test Result -----------------------
                        Assert.IsNotNull(driver.DriverID);
                        Assert.IsInstanceOf(driver.Props["DriverID"].PropertyType, driver.DriverID);
                        Assert.IsNull(driver.DriverName);
                        Assert.IsNull(driver.Age);
                        Assert.IsNull(driver.DOB);
                        Assert.IsNull(driver.LicenseRaing);
                        Assert.IsNull(driver.CarID);
        }
	    /// <summary>
        /// Creates a new unsaved Driver where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
		public static Driver CreateUnsavedDefaultDriver()
		{
			Driver driver = new Driver();
			return driver;
		}
        [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);
        }
        [Test]  // Ensures that gets and sets in the code refer to the same property
        public void Test_PropertyGetters()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Driver driver = new Driver();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForDriverName = TestUtilsShared.GetRandomString();
            driver.DriverName = (System.String) valueForDriverName;
            object valueForAge = TestUtilsShared.GetRandomInt();
            driver.Age = (System.Int32) valueForAge;
            object valueForDOB = TestUtilsShared.GetRandomDate();
            driver.DOB = (System.DateTime) valueForDOB;
            object valueForLicenseRaing = (double)TestUtilsShared.GetRandomInt();
            driver.LicenseRaing = (System.Double) valueForLicenseRaing;
            object valueForCarID = Guid.NewGuid();
            driver.CarID = (System.Guid) 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);
        }