示例#1
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);
        }
        /// <summary>
        /// Creates a new unsaved Vehicle with a random value assigned to every property
        /// </summary>
        public static Vehicle CreateUnsavedValidVehicle()
        {
            Vehicle vehicle = new Vehicle();

            vehicle.MaxSpeed = (double)TestUtilsShared.GetRandomInt();
            return(vehicle);
        }
        [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());
        }
示例#4
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]);
        }
示例#5
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-------------------
            Driver driver = TestUtilsDriver.CreateSavedDriver();

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

            //---------------Execute Test ----------------------
            driver.DriverName   = null;
            driver.Age          = null;
            driver.DOB          = null;
            driver.LicenseRaing = null;
            driver.Save();

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            var retrievedDriver =
                Broker.GetBusinessObject <Driver>(driver.ID);

            Assert.IsNull(retrievedDriver.DriverName);
            Assert.IsNull(retrievedDriver.Age);
            Assert.IsNull(retrievedDriver.DOB);
            Assert.IsNull(retrievedDriver.LicenseRaing);
        }
示例#6
0
        [Test]  // Ensures that property setters in the code point to the correct property
        public void Test_PropertySettersUseCorrectPropertyNames()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            var 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);

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForDriverName, driver.DriverName);
            Assert.AreEqual(valueForAge, driver.Age);
            Assert.AreEqual(valueForDOB, driver.DOB);
            Assert.AreEqual(valueForLicenseRaing, driver.LicenseRaing);
        }
示例#7
0
        [Test]  // Ensures that gets and sets in the code refer to the same property
        public void Test_PropertyGetters()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            var 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();

// ReSharper disable PossibleInvalidCastException
            driver.LicenseRaing = (System.Double)valueForLicenseRaing;
// ReSharper restore PossibleInvalidCastException
            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);
        }
示例#8
0
        public static DateTime GetRandomDate(string min, string max)
        {
            DateTime start = DateTime.Parse(min);

            int range = (DateTime.Parse(max) - start).Days;

            return(start.AddDays(TestUtilsShared.GetRandomInt(range)));
        }
示例#9
0
        /// <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);
        }
示例#10
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);
        }
        [Test]  // Ensures that property getters in the code point to the correct property
        public void Test_PropertyGettersUseCorrectPropertyNames()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = new Vehicle();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForMaxSpeed = (double)TestUtilsShared.GetRandomInt();

            vehicle.MaxSpeed = (System.Double)valueForMaxSpeed;

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForMaxSpeed, vehicle.GetPropertyValue("MaxSpeed"));
        }
        [Test]  // Ensures that updates to property values are stored and can be retrieved
        public void Test_UpdateSteeringWheel()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel();

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

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

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            SteeringWheel retrievedSteeringWheel =
                Broker.GetBusinessObject <SteeringWheel>(steeringWheel.ID);
        }
示例#13
0
        [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]  // 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();
            SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel();

            TestProjectNoDBSpecificProps.BO.Car boForRelationshipCar = steeringWheel.Car;

            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            //---------------Execute Test ----------------------
            TestProjectNoDBSpecificProps.BO.Car loadedRelatedBO = Broker.GetBusinessObject <TestProjectNoDBSpecificProps.BO.Car>(boForRelationshipCar.ID);
            SteeringWheel loadedSteeringWheel = Broker.GetBusinessObject <SteeringWheel>(steeringWheel.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(boForRelationshipCar, loadedSteeringWheel.Car);
            Assert.AreEqual(loadedRelatedBO, loadedSteeringWheel.Car);
            Assert.AreEqual(loadedRelatedBO, steeringWheel.Car);
        }
        [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-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateSavedVehicle();

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

            //---------------Execute Test ----------------------
            vehicle.MaxSpeed = null;
            vehicle.Save();

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            Vehicle retrievedVehicle =
                Broker.GetBusinessObject <Vehicle>(vehicle.ID);

            Assert.IsNull(retrievedVehicle.MaxSpeed);
        }
示例#16
0
        [Test]  // Ensures that updates to property values are stored and can be retrieved
        public void Test_UpdateDriver()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            var driver = TestUtilsDriver.CreateSavedDriver();
            //---------------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();

// ReSharper disable PossibleInvalidCastException
            driver.LicenseRaing = (System.Double)valueForLicenseRaing;
// ReSharper restore PossibleInvalidCastException
            object valueForCarID = Guid.NewGuid();

            driver.CarID = (System.Guid)valueForCarID;
            driver.Save();

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            var retrievedDriver =
                Broker.GetBusinessObject <Driver>(driver.ID);

            Assert.AreEqual(valueForDriverName, retrievedDriver.DriverName);
            Assert.AreEqual(valueForAge, retrievedDriver.Age);
            Assert.AreEqual(valueForDOB, retrievedDriver.DOB);
            Assert.AreEqual(valueForLicenseRaing, retrievedDriver.LicenseRaing);
            Assert.AreEqual(valueForCarID, retrievedDriver.CarID);
        }
        [Test]  // Ensures that updates to property values are stored and can be retrieved
        public void Test_UpdateVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateSavedVehicle();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object valueForMaxSpeed = (double)TestUtilsShared.GetRandomInt();

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

            //---------------Test Result -----------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            GC.Collect();
            TestUtilsShared.WaitForGC();
            Vehicle retrievedVehicle =
                Broker.GetBusinessObject <Vehicle>(vehicle.ID);

            Assert.AreEqual(valueForMaxSpeed, retrievedVehicle.MaxSpeed);
        }
示例#18
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);
        }
示例#19
0
        [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 valueForMaxSpeed = (double)TestUtilsShared.GetRandomInt();

            car.MaxSpeed = (System.Double)valueForMaxSpeed;

            //---------------Test Result -----------------------
            Assert.AreEqual(valueForMake, car.Make);
            Assert.AreEqual(valueForModel, car.Model);
            Assert.AreEqual(valueForMaxSpeed, car.MaxSpeed);
        }
示例#20
0
 /// <summary>
 /// Takes a lookup list generated by Habanero and randomly selects a value
 /// from the list
 /// </summary>
 public static object GetRandomLookupListValue(Dictionary <string, string> lookupList)
 {
     string[] values = new string[lookupList.Count];
     lookupList.Values.CopyTo(values, 0);
     return(values[TestUtilsShared.GetRandomInt(0, values.Length - 1)]);
 }