public void ManageManyToManyRelation()
        {
            var firstAddress = new AddressEntity("1st address");
            var secondAddress = new AddressEntity("2nd address");

            var firstPerson = new PersonEntity("1st person");
            var secondPerson = new PersonEntity("2nd person");

            firstAddress.AddPerson(firstPerson);
            this.AssertBound(firstPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);
            this.AssertUnbound(secondPerson, firstAddress);

            secondPerson.AddAddress(secondAddress);
            this.AssertBound(secondPerson, secondAddress);
            this.AssertUnbound(secondPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);

            firstAddress.AddPerson(secondPerson);
            this.AssertBound(firstPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);
            this.AssertBound(secondPerson, firstAddress);

            secondPerson.AddAddress(firstAddress);
            this.AssertBound(firstPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);
            this.AssertBound(secondPerson, firstAddress);
            this.AssertBound(secondPerson, secondAddress);

            secondAddress.AddPerson(firstPerson);
            this.AssertBound(firstPerson, firstAddress);
            this.AssertBound(firstPerson, secondAddress);
            this.AssertBound(secondPerson, firstAddress);
            this.AssertBound(secondPerson, secondAddress);

            firstAddress.RemovePerson(firstPerson);
            this.AssertUnbound(firstPerson, firstAddress);
            this.AssertBound(firstPerson, secondAddress);
            this.AssertBound(secondPerson, firstAddress);
            this.AssertBound(secondPerson, secondAddress);

            secondPerson.RemoveAddress(firstAddress);
            this.AssertUnbound(firstPerson, firstAddress);
            this.AssertBound(firstPerson, secondAddress);
            this.AssertUnbound(secondPerson, firstAddress);
            this.AssertBound(secondPerson, secondAddress);

            firstPerson.RemoveAddress(secondAddress);
            this.AssertUnbound(firstPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);
            this.AssertUnbound(secondPerson, firstAddress);
            this.AssertBound(secondPerson, secondAddress);

            secondAddress.RemovePerson(secondPerson);
            this.AssertUnbound(firstPerson, firstAddress);
            this.AssertUnbound(firstPerson, secondAddress);
            this.AssertUnbound(secondPerson, firstAddress);
            this.AssertUnbound(secondPerson, secondAddress);
        }
 private void AssertUnbound(PersonEntity person, CarEntity car)
 {
     Assert.NotEqual(person, car.Driver);
     Assert.NotEqual(person.Car, car);
 }
 private void AssertUnbound(PersonEntity person, AddressEntity address)
 {
     Assert.False(person.Addresses.Contains(address));
     Assert.False(address.People.Contains(person));
 }
        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);
        }