Пример #1
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 valueForVehicleType = TestUtilsShared.GetRandomString();

            vehicle.VehicleType = (System.String)valueForVehicleType;
            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(valueForVehicleType, retrievedVehicle.VehicleType);
            Assert.AreEqual(valueForMaxSpeed, retrievedVehicle.MaxSpeed);
        }
Пример #2
0
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Vehicle vehicle = TestUtilsVehicle.CreateUnsavedValidVehicle();
            //---------------Assert Precondition----------------

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

            //---------------Test Result -----------------------
            Assert.Fail("Implement ToString() for Vehicle and refine this test");
            //Assert.AreEqual(vehicle.SomeProperty, toStringValue);
        }
Пример #3
0
        [Test]  // Ensures that a saved class can be loaded
        public void Test_LoadVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateSavedVehicle();

            //---------------Execute Test ----------------------
            Vehicle loadedVehicle = Broker.GetBusinessObject <Vehicle>(vehicle.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(vehicle.VehicleID, loadedVehicle.VehicleID);
            Assert.AreEqual(vehicle.VehicleType, loadedVehicle.VehicleType);
            Assert.AreEqual(vehicle.MaxSpeed, loadedVehicle.MaxSpeed);
        }
Пример #4
0
        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateUnsavedValidVehicle();

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

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

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

            //---------------Test Result -----------------------
            Assert.IsFalse(vehicle.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(1, col.Count);
        }
Пример #5
0
        public void Test_NotSettingCompulsoryPropertiesThrowsException()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Vehicle vehicle = TestUtilsVehicle.CreateUnsavedValidVehicle();

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

            //---------------Execute Test ----------------------
            vehicle.VehicleID = null;

            try
            {
                vehicle.Save();
                Assert.Fail("Should throw an exception when compulsory properties are null");
            }
            //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("Vehicle ID' is a compulsory field and has no value", ex.Message);
            }
        }
Пример #6
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.VehicleType = null;
            vehicle.MaxSpeed    = null;
            vehicle.Save();

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

            Assert.IsNull(retrievedVehicle.VehicleType);
            Assert.IsNull(retrievedVehicle.MaxSpeed);
        }
Пример #7
0
        [Test]  // Ensures that a class can be deleted
        public void Test_DeleteVehicle()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            Vehicle vehicle = TestUtilsVehicle.CreateSavedVehicle();

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

            //---------------Execute Test ----------------------
            vehicle.MarkForDelete();
            vehicle.Save();
            //---------------Test Result -----------------------
            try
            {
                Vehicle retrievedVehicle = Broker.GetBusinessObject <Vehicle>(vehicle.ID);
                Assert.Fail("expected Err");
            }
            catch (BusObjDeleteConcurrencyControlException ex)
            {
                StringAssert.Contains("A Error has occured since the object you are trying to refresh has been deleted by another user", ex.Message);
                StringAssert.Contains("There are no records in the database for the Class: Vehicle", ex.Message);
            }
        }