[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()); }
/// <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 ---------------------- Car car = new Car(); //---------------Test Result ----------------------- Assert.IsNull(car.Make); Assert.IsNull(car.Model); Assert.IsNull(car.MaxSpeed); }
[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] // 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 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); }
/// <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; }