Inheritance: Vehicle
Example #1
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());
        }
        /// <summary>
        /// Creates a new unsaved Car with a random value assigned to every property
        /// </summary>
		public static Car CreateUnsavedValidCar()
		{
			Car car = new Car();
			car.Make = TestUtilsShared.GetRandomString();
			car.Model = TestUtilsShared.GetRandomString();
			car.MaxSpeed = (double)TestUtilsShared.GetRandomInt();
			return car;
		}
        [Test] // Ensures that the defaults have not been tampered
        public void Test_CreateCarWithDefaults()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------

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

            //---------------Execute Test ----------------------
            var car = new Car();

            //---------------Test Result -----------------------
            Assert.IsNull(car.Make);
            Assert.IsNull(car.Model);
            Assert.IsNotNull(car.VehicleID);
            Assert.IsInstanceOf(car.Props["VehicleID"].PropertyType, car.VehicleID);
            Assert.IsNull(car.MaxSpeed);
        }
Example #4
0
        [Test]  // Checks that BOs in a single relationship load correctly (no tampering with class defs)
        public void Test_LoadThroughSingleRelationship_Car()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Driver driver = TestUtilsDriver.CreateSavedDriver();

            TestProject.BO.Car boForRelationshipCar = driver.Car;

            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            //---------------Execute Test ----------------------
            TestProject.BO.Car loadedRelatedBO = Broker.GetBusinessObject <TestProject.BO.Car>(boForRelationshipCar.ID);
            Driver             loadedDriver    = Broker.GetBusinessObject <Driver>(driver.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(boForRelationshipCar, loadedDriver.Car);
            Assert.AreEqual(loadedRelatedBO, loadedDriver.Car);
            Assert.AreEqual(loadedRelatedBO, driver.Car);
        }
        [Test] // Ensures that property setters in the code point to the correct property
        public void Test_PropertySettersUseCorrectPropertyNames()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = new Car();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForMake = TestUtilsShared.GetRandomString();
            car.SetPropertyValue("Make", valueForMake);
            object valueForModel = TestUtilsShared.GetRandomString();
            car.SetPropertyValue("Model", valueForModel);

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForMake, car.Make);
            Assert.AreEqual(valueForModel, car.Model);
        }
        [Test] // Ensures that gets and sets in the code refer to the same property
        public void Test_PropertyGetters()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Car car = new Car();
            //---------------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;

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForMake, car.Make);
            Assert.AreEqual(valueForModel, car.Model);
            Assert.AreEqual(valueForVehicleType, car.VehicleType);
            Assert.AreEqual(valueForMaxSpeed, car.MaxSpeed);
        }
	    /// <summary>
        /// Creates a new unsaved Car 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 Car CreateUnsavedDefaultCar()
		{
			Car car = new Car();
			return car;
		}