[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(); TestProject.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); } TestProject.BO.Car relatedBO = Broker.GetBusinessObject <TestProject.BO.Car>(boForRelationshipCar.ID); Assert.AreEqual(relatedBO.ID.ToString(), boForRelationshipCar.ID.ToString()); }
[Test] // Ensures that a saved class can be loaded public void Test_LoadSteeringWheel() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel(); //---------------Execute Test ---------------------- SteeringWheel loadedSteeringWheel = Broker.GetBusinessObject <SteeringWheel>(steeringWheel.ID); //---------------Test Result ----------------------- Assert.AreEqual(steeringWheel.SteeringWheelID, loadedSteeringWheel.SteeringWheelID); Assert.AreEqual(steeringWheel.CarID, loadedSteeringWheel.CarID); }
public void Test_ToString() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- string toStringValue = steeringWheel.ToString(); //---------------Test Result ----------------------- Assert.Fail("Implement ToString() for SteeringWheel and refine this test"); //Assert.AreEqual(steeringWheel.SomeProperty, toStringValue); }
[Test] // Ensures that a class can be successfully saved public void Test_SaveSteeringWheel() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel(); //---------------Assert Precondition---------------- Assert.IsTrue(steeringWheel.Status.IsNew); BusinessObjectCollection <SteeringWheel> col = new BusinessObjectCollection <SteeringWheel>(); col.LoadAll(); Assert.AreEqual(0, col.Count); //---------------Execute Test ---------------------- steeringWheel.Save(); //---------------Test Result ----------------------- Assert.IsFalse(steeringWheel.Status.IsNew); col.LoadAll(); Assert.AreEqual(1, col.Count); }
[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(); TestProject.BO.Car boForRelationshipCar = steeringWheel.Car; BusinessObjectManager.Instance.ClearLoadedObjects(); GC.Collect(); TestUtilsShared.WaitForGC(); //---------------Execute Test ---------------------- TestProject.BO.Car loadedRelatedBO = Broker.GetBusinessObject <TestProject.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------------------- SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- steeringWheel.CarID = null; steeringWheel.Save(); //---------------Test Result ----------------------- BusinessObjectManager.Instance.ClearLoadedObjects(); GC.Collect(); TestUtilsShared.WaitForGC(); SteeringWheel retrievedSteeringWheel = Broker.GetBusinessObject <SteeringWheel>(steeringWheel.ID); Assert.IsNull(retrievedSteeringWheel.CarID); }
[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 ---------------------- object valueForCarID = Guid.NewGuid(); steeringWheel.CarID = (System.Guid)valueForCarID; steeringWheel.Save(); //---------------Test Result ----------------------- BusinessObjectManager.Instance.ClearLoadedObjects(); GC.Collect(); TestUtilsShared.WaitForGC(); SteeringWheel retrievedSteeringWheel = Broker.GetBusinessObject <SteeringWheel>(steeringWheel.ID); Assert.AreEqual(valueForCarID, retrievedSteeringWheel.CarID); }
public void Test_NotSettingCompulsoryPropertiesThrowsException() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- steeringWheel.SteeringWheelID = null; try { steeringWheel.Save(); Assert.Fail("Should throw an exception when compulsory properties are null"); } //---------------Test Result ----------------------- catch (BusObjectInAnInvalidStateException ex) { StringAssert.Contains("Steering Wheel ID' is a compulsory field and has no value", ex.Message); } }
[Test] // Ensures that a class can be deleted public void Test_DeleteSteeringWheel() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateSavedSteeringWheel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- steeringWheel.MarkForDelete(); steeringWheel.Save(); //---------------Test Result ----------------------- try { SteeringWheel retrievedSteeringWheel = Broker.GetBusinessObject <SteeringWheel>(steeringWheel.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: SteeringWheel", ex.Message); } }