public void Test_DereferenceRelatedObjects_ForSingle_IsOwner_WhenHasNoRelatedBO() { //The Car has a single relationship to engine. The car->engine relationship is marked // as a dereference related relationship. BORegistry.DataAccessor = new DataAccessorInMemory(); //---------------Set up test pack------------------- new Car(); Engine engine = new Engine(); engine.SetPropertyValue("EngineNo", "NO111"); engine.Save(); engine.MarkForDelete(); SingleRelationshipDef relationshipDef = (SingleRelationshipDef)engine.Relationships["Car"].RelationshipDef; relationshipDef.DeleteParentAction = DeleteParentAction.DereferenceRelated; //---------------Assert Precondition---------------- Assert.IsTrue(relationshipDef.OwningBOHasForeignKey); Assert.AreEqual(DeleteParentAction.DereferenceRelated, relationshipDef.DeleteParentAction); Assert.IsNull(engine.GetCar()); //---------------Execute Test ---------------------- engine.Save(); //---------------Test Result ----------------------- Assert.IsNull(engine.GetCar()); Assert.IsTrue(engine.Status.IsNew && engine.Status.IsDeleted); }
public void TestDereferenceRelatedObjects() { //The Car has a single relationship to engine. The car->engine relationship is marked // as a dereference related relationship. BORegistry.DataAccessor = new DataAccessorInMemory(); //---------------Set up test pack------------------- Car car = new Car(); car.SetPropertyValue("CarRegNo", "NP32459"); car.Save(); Engine engine = new Engine(); engine.SetPropertyValue("EngineNo", "NO111"); const string carIDProp = "CarID"; engine.SetPropertyValue(carIDProp, car.GetPropertyValue(carIDProp)); engine.Save(); BORegistry.DataAccessor.BusinessObjectLoader.Refresh(engine); Assert.AreSame(engine.GetCar(), car); //---------------Execute Test ---------------------- car.MarkForDelete(); car.Save(); //---------------Test Result ----------------------- Assert.IsNull(engine.GetPropertyValue(carIDProp)); Assert.IsNull(engine.GetCar()); //---------------Test TearDown ----------------------- }