Example #1
0
        public void DeleteOrderTicketEvents()
        {
            _orderTicket.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_orderTicket, "1. Deleting event of orderTicket"),
                new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket", _orderTicket, null, "2. Relation changing event of order"),
                new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket", null, null, "3. Relation changed event of order"),
                new ObjectDeletionState(_orderTicket, "4. Deleted event of orderTicket")
            };

            _eventReceiver.Check(expectedStates);
        }
        public void OldOrderCancelsReplace()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _customer, _oldCustomerOfNewOrder, _oldOrder, _newOrder };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _customer.Orders, _oldCustomerOfNewOrder.Orders };

            SequenceEventReceiver eventReceiver =
                new SequenceEventReceiver(domainObjectEventSources, collectionEventSources, 1);

            int replaceIndex = _customer.Orders.IndexOf(_oldOrder);

            try
            {
                _customer.Orders[replaceIndex] = _newOrder;
                Assert.Fail("EventReceiverCancelException should be raised.");
            }
            catch (EventReceiverCancelException)
            {
                ChangeState[] expectedChangeStates = new ChangeState[]
                { new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _customer, null, "1. Changing event of old order from old customer to null") };

                eventReceiver.Check(expectedChangeStates);

                Assert.That(_customer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldCustomerOfNewOrder.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldOrder.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_newOrder.State, Is.EqualTo(StateType.Unchanged));

                Assert.That(_customer.Orders[replaceIndex], Is.SameAs(_oldOrder));
                Assert.That(_oldOrder.Customer, Is.SameAs(_customer));

                Assert.That(_oldCustomerOfNewOrder.Orders.ContainsObject(_newOrder), Is.True);
                Assert.That(_newOrder.Customer, Is.SameAs(_oldCustomerOfNewOrder));
            }
        }
Example #3
0
        public void OrderCancelsChangeEvent()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _oldCustomer, _newCustomer, _order1 };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _oldCustomer.Orders, _newCustomer.Orders };
            SequenceEventReceiver    eventReceiver            = new SequenceEventReceiver(domainObjectEventSources, collectionEventSources, 1);

            try
            {
                _newCustomer.Orders.Add(_order1);
                Assert.Fail("EventReceiverCancelException should be raised.");
            }
            catch (EventReceiverCancelException)
            {
                ChangeState[] expectedChangeStates = new ChangeState[]
                { new RelationChangeState(_order1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _oldCustomer, _newCustomer, "1. Changing event of order from old to new customer") };

                eventReceiver.Check(expectedChangeStates);

                Assert.That(_order1.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldCustomer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_newCustomer.State, Is.EqualTo(StateType.Unchanged));

                Assert.That(_order1.Customer, Is.SameAs(_oldCustomer));
                Assert.That(_oldCustomer.Orders[_order1.ID], Is.SameAs(_order1));
                Assert.That(_newCustomer.Orders[_order1.ID], Is.Null);
            }
        }
        public void SetRelatedObjectWithSameOldAndNewObject()
        {
            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(new DomainObject[] { _location, _oldClient, _newClient }, new DomainObjectCollection[0]);

            _location.Client = _oldClient;

            eventReceiver.Check(new ChangeState[0]);
            Assert.That(_location.State, Is.EqualTo(StateType.Unchanged));
        }
Example #5
0
        public void DeleteSupervisor()
        {
            _supervisor.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_supervisor, "1. Deleting of supervisor"),
                new CollectionDeletionState(_supervisor.Subordinates, "2. Deleting of supervisor.Subordinates"),
                new RelationChangeState(_subordinate1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor", _supervisor, null, "3. Relation changing of subordinate1"),
                new RelationChangeState(_subordinate2, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor", _supervisor, null, "4. Relation changing of subordinate2"),
                new RelationChangeState(_subordinate2, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor", null, null, "5. Relation changed of subordinate2"),
                new RelationChangeState(_subordinate1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor", null, null, "6. Relation changed of subordinate1"),
                new CollectionDeletionState(_supervisor.Subordinates, "7. Deleted of supervisor.Subordinates"),
                new ObjectDeletionState(_supervisor, "8. Deleted of supervisor")
            };

            _eventReceiver.Check(expectedStates);
        }
        public void SetRelatedObjectWithOldAndNewNullObject()
        {
            Client client = DomainObjectIDs.Client4.GetObject <Client> ();
            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(client);

            client.ParentClient = null;

            eventReceiver.Check(new ChangeState[0]);
            Assert.That(client.ParentClient, Is.Null);
            Assert.That(client.Properties[typeof(Client), "ParentClient"].GetRelatedObjectID(), Is.Null);
            Assert.That(client.State, Is.EqualTo(StateType.Unchanged));
        }
        public void EventsForSetRelatedObject()
        {
            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(new DomainObject[] { _location, _oldClient, _newClient }, new DomainObjectCollection[0]);

            _location.Client = _newClient;

            ChangeState[] expectedStates = new ChangeState[]
            {
                new RelationChangeState(_location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", _oldClient, _newClient, "1. Changing event of location"),
                new RelationChangeState(_location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", null, null, "2. Changed event of location")
            };

            eventReceiver.Check(expectedStates);
        }
        public void ReplaceWithSameObject()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _customer, _oldCustomerOfNewOrder, _oldOrder, _newOrder };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _customer.Orders, _oldCustomerOfNewOrder.Orders };

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(domainObjectEventSources, collectionEventSources);

            int replaceIndex = _customer.Orders.IndexOf(_oldOrder);

            _customer.Orders[replaceIndex] = _oldOrder;

            ChangeState[] expectedChangeStates = new ChangeState[0];
            eventReceiver.Check(expectedChangeStates);
        }
        public void ChangePropertyBeforeDeletion()
        {
            _orderItem.Order = null;
            _eventReceiver   = CreateEventReceiver();

            _orderItem.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_orderItem, "1. Deleting event of orderItem"),
                new ObjectDeletionState(_orderItem, "2. Deleted event of orderItem"),
            };

            _eventReceiver.Check(expectedStates);
        }
        public void DeleteLocationAndCommit()
        {
            SetDatabaseModifyable();

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(new DomainObject[] { _location, _oldClient, _newClient }, new DomainObjectCollection[0]);

            _location.Delete();
            TestableClientTransaction.Commit();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_location, "1. Deleting event of location"),
                new ObjectDeletionState(_location, "2. Deleted event of location")
            };

            eventReceiver.Check(expectedStates);
        }
        public void Events()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _customer, _oldCustomerOfNewOrder, _oldOrder, _newOrder };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _customer.Orders, _oldCustomerOfNewOrder.Orders };
            SequenceEventReceiver    eventReceiver            = new SequenceEventReceiver(domainObjectEventSources, collectionEventSources);

            int replaceIndex = _customer.Orders.IndexOf(_oldOrder);

            _customer.Orders[replaceIndex] = _newOrder;

            ChangeState[] expectedChangeStates = new ChangeState[]
            {
                new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _customer, null, "1. Changing event of old order from old customer to null"),
                new RelationChangeState(_newOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _oldCustomerOfNewOrder, _customer, "2. Changing event of new order from null to new customer"),
                new CollectionChangeState(_customer.Orders, _oldOrder, "3. Removing event of old order from customer.Orders"),
                new CollectionChangeState(_customer.Orders, _newOrder, "4. Adding event of new order to customer.Orders"),
                new RelationChangeState(_customer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", _oldOrder, _newOrder, "5. Changing event of customer"),

                new CollectionChangeState(_oldCustomerOfNewOrder.Orders, _newOrder, "6. Removing event of new order from oldCustomerOfNewOrder.Orders"),
                new RelationChangeState(_oldCustomerOfNewOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", _newOrder, null, "7. Changing event of oldCustomerOfNewOrder"),

                new RelationChangeState(_oldCustomerOfNewOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, null, "8. Changed event of oldCustomerOfNewOrder"),
                new CollectionChangeState(_oldCustomerOfNewOrder.Orders, _newOrder, "9. Removed event of new order from oldCustomerOfNewOrder.Orders"),

                new RelationChangeState(_customer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, null, "10. Changed event of customer"),
                new CollectionChangeState(_customer.Orders, _newOrder, "11. Added event of new order to orders"),
                new CollectionChangeState(_customer.Orders, _oldOrder, "12. Removed event of old order from orders"),
                new RelationChangeState(_newOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", null, null, "13. Changed event of new order from null to new customer"),
                new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", null, null, "14. Changed event of old order from old customer to null"),
            };

            eventReceiver.Check(expectedChangeStates);

            Assert.That(_customer.State, Is.EqualTo(StateType.Changed));
            Assert.That(_oldCustomerOfNewOrder.State, Is.EqualTo(StateType.Changed));
            Assert.That(_oldOrder.State, Is.EqualTo(StateType.Changed));
            Assert.That(_newOrder.State, Is.EqualTo(StateType.Changed));

            Assert.That(_customer.Orders[replaceIndex], Is.SameAs(_newOrder));
            Assert.That(_newOrder.Customer, Is.SameAs(_customer));

            Assert.That(_customer.Orders.ContainsObject(_oldOrder), Is.False);
            Assert.That(_oldOrder.Customer, Is.Null);

            Assert.That(_oldCustomerOfNewOrder.Orders.ContainsObject(_newOrder), Is.False);
        }
Example #12
0
        public void ChangePropertyBeforeDeletion()
        {
            _supervisor.Subordinates.Clear();
            _eventReceiver = CreateEventReceiver();

            _supervisor.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_supervisor, "1. Deleting of supervisor"),
                new CollectionDeletionState(_supervisor.Subordinates, "2. Deleting of supervisor.Subordinates"),
                new CollectionDeletionState(_supervisor.Subordinates, "3. Deleted of supervisor.Subordinates"),
                new ObjectDeletionState(_supervisor, "4. Deleted of supervisor"),
            };

            _eventReceiver.Check(expectedStates);
        }
Example #13
0
        public void DeleteComputerWithoutEmployeeEvents()
        {
            Computer computer = DomainObjectIDs.Computer4.GetObject <Computer> ();

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { computer }, new DomainObjectCollection[0]);

            computer.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(computer, "1. Deleting of computer"),
                new ObjectDeletionState(computer, "2. Deleted of computer")
            };

            eventReceiver.Check(expectedStates);
        }
Example #14
0
        public void ChangeVirtualPropertyBeforeDeletion()
        {
            _order.OrderTicket = null;
            _eventReceiver     = CreateEventReceiver();

            _order.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_order, "1. Deleting event of order"),
                new CollectionDeletionState(_order.OrderItems, "2. Deleting of _order.OrderItems"),
                new CollectionDeletionState(_order.OrderItems, "3. Deleted of _order.OrderItems"),
                new ObjectDeletionState(_order, "4. Deleted event of order"),
            };

            _eventReceiver.Check(expectedStates);
        }
        public void DeleteOrderItemEvents()
        {
            _orderItem.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_orderItem, "1. Deleting event of orderItem"),
                new CollectionChangeState(_order.OrderItems, _orderItem, "2. Removing event of order.OrderItems"),
                new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems", _orderItem, null, "3. Relation changing event of order"),
                new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems", null, null, "4. Relation changed event of order"),
                new CollectionChangeState(_order.OrderItems, _orderItem, "5. Removed event of order.OrderItems"),
                new ObjectDeletionState(_orderItem, "6. Deleted event of orderItem"),
            };

            _eventReceiver.Check(expectedStates);
        }
        public void CreateObjectsAndCommit()
        {
            SetDatabaseModifyable();

            Client   client1  = Client.NewObject();
            Client   client2  = Client.NewObject();
            Location location = Location.NewObject();

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(new DomainObject[] { location, client1, client2 }, new DomainObjectCollection[0]);

            location.Client = client1;

            Assert.That(client1.State, Is.EqualTo(StateType.New));
            Assert.That(client2.State, Is.EqualTo(StateType.New));
            Assert.That(location.State, Is.EqualTo(StateType.New));

            ObjectID clientID1  = client1.ID;
            ObjectID clientID2  = client2.ID;
            ObjectID locationID = location.ID;


            ChangeState[] expectedStates = new ChangeState[]
            {
                new RelationChangeState(location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", null, client1, "1. Changing event of location"),
                new RelationChangeState(location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", null, null, "2. Changed event of location")
            };

            eventReceiver.Check(expectedStates);

            TestableClientTransaction.Commit();

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                client1  = clientID1.GetObject <Client> ();
                client2  = clientID2.GetObject <Client> ();
                location = locationID.GetObject <Location>();

                Assert.That(client1, Is.Not.Null);
                Assert.That(client2, Is.Not.Null);
                Assert.That(location, Is.Not.Null);
                Assert.That(location.Client, Is.SameAs(client1));
            }
        }
Example #17
0
        public void ChangeEvents()
        {
            DomainObject[] domainObjectEventSources = new DomainObject[] {
                _oldCustomer, _newCustomer, _order1
            };

            DomainObjectCollection[] collectionEventSources = new DomainObjectCollection[] {
                _oldCustomer.Orders, _newCustomer.Orders
            };

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(domainObjectEventSources, collectionEventSources);

            _newCustomer.Orders.Add(_order1);

            ChangeState[] expectedChangeStates = new ChangeState[]
            {
                new RelationChangeState(_order1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _oldCustomer, _newCustomer, "1. Changing event of order from old to new customer"),
                new CollectionChangeState(_newCustomer.Orders, _order1, "2. Adding event of new customer's order collection"),
                new RelationChangeState(_newCustomer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, _order1, "3. Changing event of new customer"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "4. Removing of orders of old customer"),
                new RelationChangeState(_oldCustomer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", _order1, null, "5. Changing event of old customer"),
                new RelationChangeState(_oldCustomer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, null, "6. Changed event of old customer"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "7. Removed event of old customer's order collection"),
                new RelationChangeState(_newCustomer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, null, "8. Changed event of new customer"),
                new CollectionChangeState(_newCustomer.Orders, _order1, "9. Added event of new customer's order collection"),
                new RelationChangeState(_order1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", null, null, "10. Changed event of order from old to new customer"),
            };

            eventReceiver.Check(expectedChangeStates);

            Assert.That(_order1.State, Is.EqualTo(StateType.Changed));
            Assert.That(_oldCustomer.State, Is.EqualTo(StateType.Changed));
            Assert.That(_newCustomer.State, Is.EqualTo(StateType.Changed));

            Assert.That(_order1.Customer, Is.SameAs(_newCustomer));
            Assert.That(_oldCustomer.Orders[_order1.ID], Is.Null);
            Assert.That(_newCustomer.Orders[_order1.ID], Is.SameAs(_order1));

            Assert.That(_order1.InternalDataContainer.State, Is.EqualTo(StateType.Changed));
            Assert.That(_oldCustomer.InternalDataContainer.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(_newCustomer.InternalDataContainer.State, Is.EqualTo(StateType.Unchanged));
        }
Example #18
0
        public void Events()
        {
            var orderItemsCollection            = _newOrder.OrderItems;
            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _newOrder, _newOrderTicket },
                new DomainObjectCollection[] { orderItemsCollection });

            _newOrder.Delete();

            ChangeState[] expectedStates = new ChangeState[]
            {
                new ObjectDeletionState(_newOrder, "1. Deleting event of order"),
                new CollectionDeletionState(orderItemsCollection, "2. Deleting of order.OrderItems"),
                new RelationChangeState(_newOrderTicket, "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order", _newOrder, null, "3. Relation changing event of orderTicket"),
                new RelationChangeState(_newOrderTicket, "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order", null, null, "4. Relation changed event of orderTicket"),
                new CollectionDeletionState(orderItemsCollection, "5. Deleted of order.OrderItems"),
                new ObjectDeletionState(_newOrder, "6. Deleted event of order")
            };

            eventReceiver.Check(expectedStates);
        }
Example #19
0
        public void OldObjectAndNewObjectAreSameRelationInherited()
        {
            Customer customer = DomainObjectIDs.Customer4.GetObject <Customer> ();

            Ceo ceo = customer.Ceo;

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { customer, ceo },
                new DomainObjectCollection[0]);

            Assert.That(customer.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(ceo.State, Is.EqualTo(StateType.Unchanged));

            customer.Ceo = ceo;

            Assert.That(customer.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(ceo.State, Is.EqualTo(StateType.Unchanged));

            ChangeState[] expectedStates = new ChangeState[0];

            eventReceiver.Check(expectedStates);
        }
Example #20
0
        public void Clear_CancelAtSecondObject()
        {
            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));

            var eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _oldCustomer, _order1, _order2 },
                new[] { _oldCustomer.Orders });

            eventReceiver.CancelEventNumber = 6;

            try
            {
                _oldCustomer.Orders.Clear();
                Assert.Fail("Expected cancellation");
            }
            catch (EventReceiverCancelException)
            {
                // ok
            }

            var expectedStates = new ChangeState[]
            {
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", _oldCustomer, null, "1. Setting _order2.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "2. Removing _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order2, null, "3. Removing _order2 from _oldCustomer"),

                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", _oldCustomer, null, "4. Setting _order1.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "5. Removing _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order1, null, "6. Removing _order1 from _oldCustomer"),
            };

            eventReceiver.Check(expectedStates);

            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));
            Assert.That(_order2.Customer, Is.SameAs(_oldCustomer));
            Assert.That(_order1.Customer, Is.SameAs(_oldCustomer));
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(_oldCustomer.Orders).HasBeenTouched, Is.False);
        }
Example #21
0
        public void Clear_Events()
        {
            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));

            var eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _oldCustomer, _order1, _order2 },
                new[] { _oldCustomer.Orders });

            _oldCustomer.Orders.Clear();

            var expectedStates = new ChangeState[]
            {
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", _oldCustomer, null, "1. Setting _order2.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "2. Removing _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order2, null, "3. Removing _order2 from _oldCustomer"),

                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", _oldCustomer, null, "4. Setting _order1.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "5. Removing _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order1, null, "6. Removing _order1 from _oldCustomer"),

                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", null, null, "7. Removed _order1 from _oldCustomer"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "8. Removed _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", null, null, "9. Setting _order1.Customer to null"),

                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", null, null, "10. Removed _order2 from _oldCustomer"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "11. Removed _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", null, null, "12. Set _order2.Customer to null"),
            };

            eventReceiver.Check(expectedStates);

            Assert.That(_oldCustomer.Orders, Is.Empty);
            Assert.That(_order2.Customer, Is.Null);
            Assert.That(_order1.Customer, Is.Null);
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(_oldCustomer.Orders).HasBeenTouched, Is.True);
        }
        public void ChangeEventsWithOldRelatedObjectNotLoaded()
        {
            Order newOrder = DomainObjectIDs.Order4.GetObject <Order> ();

            SequenceEventReceiver eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _oldOrder, newOrder, _customer },
                new DomainObjectCollection[] { _customer.Orders });

            int replaceIndex = _customer.Orders.IndexOf(_oldOrder);

            _customer.Orders[replaceIndex] = newOrder;

            Assert.That(newOrder.Customer, Is.SameAs(_customer));
            Assert.That(_customer.Orders.ContainsObject(newOrder), Is.True);

            Customer oldCustomerOfNewOrder = DomainObjectIDs.Customer4.GetObject <Customer> ();

            Assert.That(oldCustomerOfNewOrder.Orders.ContainsObject(newOrder), Is.False);

            ChangeState[] expectedStates = new ChangeState[]
            {
                new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _customer, null, "1. Changing event of old order from new customer to null"),
                new RelationChangeState(newOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", oldCustomerOfNewOrder, _customer, "2. Changing event of new order from old to new customer"),
                new CollectionChangeState(_customer.Orders, _oldOrder, "3. Removing event of new customer's order collection"),
                new CollectionChangeState(_customer.Orders, newOrder, "4. Adding event of new customer's order collection"),
                new RelationChangeState(_customer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", _oldOrder, newOrder, "5. Changing event of new customer from old order to new order"),

                new RelationChangeState(_customer, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders", null, null, "6. Changed event of new customer from old order to new order"),
                new CollectionChangeState(_customer.Orders, newOrder, "7. Added event of new customer's order collection"),
                new CollectionChangeState(_customer.Orders, _oldOrder, "8. Removed event of new customer's order collection"),
                new RelationChangeState(newOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", null, null, "9. Changed event of new order from old to new customer"),
                new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", null, null, "10. Changed event of old order from new customer to null"),
            };

            eventReceiver.Check(expectedStates);
        }