public void ManageOneToManyRelation()
        {
            var firstCar = new CarEntity("1st Car");
            var secondCar = new CarEntity("2nd Car");
            var thirdCar = new CarEntity("3d Car");

            var originalGarage = new GarageEntity("Original garage");

            this.AssertUnbound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            originalGarage.AddCar(firstCar);
            this.AssertBound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            originalGarage.AddCar(secondCar);
            this.AssertBound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            originalGarage.AddCar(thirdCar);
            this.AssertBound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);

            originalGarage.RemoveCar(firstCar);
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);

            originalGarage.RemoveCar(secondCar);
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);

            originalGarage.RemoveCar(thirdCar);
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            firstCar.Garage = originalGarage;
            this.AssertBound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            secondCar.Garage = originalGarage;
            this.AssertBound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);

            thirdCar.Garage = originalGarage;
            this.AssertBound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);

            var anotherGarage = new GarageEntity("Another garage");

            firstCar.Garage = anotherGarage;
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertBound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);
            this.AssertBound(anotherGarage, firstCar);
            this.AssertUnbound(anotherGarage, secondCar);
            this.AssertUnbound(anotherGarage, thirdCar);

            secondCar.Garage = anotherGarage;
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertBound(originalGarage, thirdCar);
            this.AssertBound(anotherGarage, firstCar);
            this.AssertBound(anotherGarage, secondCar);
            this.AssertUnbound(anotherGarage, thirdCar);

            thirdCar.Garage = anotherGarage;
            this.AssertUnbound(originalGarage, firstCar);
            this.AssertUnbound(originalGarage, secondCar);
            this.AssertUnbound(originalGarage, thirdCar);
            this.AssertBound(anotherGarage, firstCar);
            this.AssertBound(anotherGarage, secondCar);
            this.AssertBound(anotherGarage, thirdCar);
        }
 private void AssertUnbound(GarageEntity garage, CarEntity car)
 {
     Assert.NotEqual(garage, car.Garage);
     Assert.False(garage.HasCar(car));
 }
 private void AssertBound(GarageEntity garage, CarEntity car)
 {
     Assert.Equal(garage, car.Garage);
     Assert.True(garage.HasCar(car));
 }
 private void AssertUnbound(PersonEntity person, CarEntity car)
 {
     Assert.NotEqual(person, car.Driver);
     Assert.NotEqual(person.Car, car);
 }
        public void ManageOneToOneRelation()
        {
            var person = new PersonEntity("A person");
            var originalCar = new CarEntity("Original Car");

            Assert.Null(person.Car);
            Assert.Null(originalCar.Driver);

            person.Car = originalCar;
            this.AssertBound(person, originalCar);

            originalCar.Driver = null;
            Assert.Null(originalCar.Driver);
            Assert.Null(person.Car);
            this.AssertUnbound(person, originalCar);

            originalCar.Driver = person;
            this.AssertBound(person, originalCar);

            var newCar = new CarEntity("New Car");
            person.Car = newCar;
            this.AssertBound(person, newCar);
            this.AssertUnbound(person, originalCar);
        }