예제 #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();

            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]);
        }
예제 #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);
        }
예제 #3
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);
        }
        [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());
        }
        [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);
        }
        [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);
        }
예제 #7
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-------------------
            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);
        }
예제 #8
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);
        }
예제 #9
0
        [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);
        }
예제 #10
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);
        }