public void Test_ToString_WhenHasObjectID_ShouldReturnObjectIDToString() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); Car myBO = new Car(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- string toString = myBO.ToString(); //---------------Test Result ----------------------- Assert.AreEqual(myBO.ID.GetAsValue().ToString(), toString); }
public void Test_DereferenceRelatedObjects_ForSingle_NonOwner_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------------------- Car car = new Car(); car.SetPropertyValue("CarRegNo", "NP32459"); car.Save(); car.MarkForDelete(); new Engine(); //---------------Assert Precondition---------------- SingleRelationshipDef relationshipDef = (SingleRelationshipDef)car.Relationships["Engine"].RelationshipDef; Assert.IsFalse(relationshipDef.OwningBOHasForeignKey); Assert.AreEqual(DeleteParentAction.DereferenceRelated, relationshipDef.DeleteParentAction); Assert.IsNull(car.GetEngine()); //---------------Execute Test ---------------------- car.Save(); //---------------Test Result ----------------------- Assert.IsNull(car.GetEngine()); Assert.IsTrue(car.Status.IsNew && car.Status.IsDeleted); }
public void TestGetPropertyValue_ThroughRelationship() { //---------------Set up test pack------------------- Car car1 = new Car(); car1.CarRegNo = "5"; Engine engine1 = new Engine(); engine1.CarID = car1.CarID; engine1.EngineNo = "20"; ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter(); committer.AddBusinessObject(car1); committer.AddBusinessObject(engine1); committer.CommitTransaction(); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- object carregno = engine1.GetPropertyValue(new Source("Car"), "CarRegNo"); //---------------Test Result ----------------------- Assert.AreEqual(car1.CarRegNo, carregno); //---------------Tear Down ------------------------- }
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 ----------------------- }
private static Car CreateUnsavedCar(string registrationNo) { Car car = new Car(); car.RegistrationNo = registrationNo; return car; }