Beispiel #1
0
        public void ModifyOtherObjectInClientTransactionCommitting()
        {
            _customer.Name = "New name";
            TestableClientTransaction.Committing += ClientTransaction_CommittingForModifyOtherObjectInClientTransactionCommitting;

            Ceo ceo = _customer.Ceo;

            var ceoEventReceiver = new DomainObjectEventReceiver(ceo);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            TestableClientTransaction.Commit();

            Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjectsForFirstCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committingDomainObjectsForSecondCommit     = clientTransactionEventReceiver.CommittingDomainObjectLists[1];
            var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjectsForFirstCommitEvent.Count, Is.EqualTo(1));
            Assert.That(committingDomainObjectsForSecondCommit.Count, Is.EqualTo(1));
            Assert.That(committedDomainObjects.Count, Is.EqualTo(2));

            Assert.That(committingDomainObjectsForFirstCommitEvent.Contains(_customer), Is.True);
            Assert.That(committingDomainObjectsForFirstCommitEvent.Contains(ceo), Is.False);

            Assert.That(committingDomainObjectsForSecondCommit.Contains(_customer), Is.False);
            Assert.That(committingDomainObjectsForSecondCommit.Contains(ceo), Is.True);

            Assert.That(committedDomainObjects.Contains(_customer), Is.True);
            Assert.That(committedDomainObjects.Contains(ceo), Is.True);
        }
        public void Events()
        {
            Order     order     = Order.NewObject();
            OrderItem orderItem = OrderItem.NewObject();

            DomainObjectEventReceiver orderEventReceiver     = new DomainObjectEventReceiver(order);
            DomainObjectEventReceiver orderItemEventReceiver = new DomainObjectEventReceiver(orderItem);

            DomainObjectCollectionEventReceiver collectionEventReceiver = new DomainObjectCollectionEventReceiver(
                order.OrderItems);

            order.DeliveryDate = new DateTime(2010, 1, 1);
            order.OrderItems.Add(orderItem);

            Assert.That(orderEventReceiver.HasChangingEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.HasChangedEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.ChangingPropertyDefinition.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.DeliveryDate"));
            Assert.That(orderEventReceiver.ChangedPropertyDefinition.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.DeliveryDate"));

            Assert.That(orderEventReceiver.HasRelationChangingEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.HasRelationChangedEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.ChangingRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems"));
            Assert.That(orderEventReceiver.ChangedRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems"));

            Assert.That(orderItemEventReceiver.HasRelationChangingEventBeenCalled, Is.True);
            Assert.That(orderItemEventReceiver.HasRelationChangedEventBeenCalled, Is.True);
            Assert.That(orderItemEventReceiver.ChangingRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem.Order"));
            Assert.That(orderItemEventReceiver.ChangedRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem.Order"));

            Assert.That(collectionEventReceiver.HasAddingEventBeenCalled, Is.True);
            Assert.That(collectionEventReceiver.HasAddedEventBeenCalled, Is.True);
            Assert.That(collectionEventReceiver.AddingDomainObject, Is.SameAs(orderItem));
            Assert.That(collectionEventReceiver.AddedDomainObject, Is.SameAs(orderItem));
        }
Beispiel #3
0
        public void ModifyOtherObjectInDomainObjectCommitting()
        {
            var ceo = _customer.Ceo;

            _customer.Name        = "New name";
            _customer.Committing += (sender, e) => ceo.Name = "New CEO name";

            var ceoEventReceiver = new DomainObjectEventReceiver(ceo);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            TestableClientTransaction.Commit();

            Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjects1 = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committingDomainObjects2 = clientTransactionEventReceiver.CommittingDomainObjectLists[1];
            var committedDomainObjects   = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjects1, Is.EqualTo(new[] { _customer }));
            Assert.That(committingDomainObjects2, Is.EqualTo(new[] { ceo }));
            Assert.That(committedDomainObjects, Is.EquivalentTo(new DomainObject[] { _customer, ceo }));
        }
        public override void SetUp()
        {
            base.SetUp();

            _supervisor  = DomainObjectIDs.Employee1.GetObject <Employee> ();
            _subordinate = DomainObjectIDs.Employee2.GetObject <Employee> ();

            _supervisorEventReceiver            = new DomainObjectEventReceiver(_supervisor);
            _subordinateEventReceiver           = new DomainObjectEventReceiver(_subordinate);
            _subordinateCollectionEventReceiver = new DomainObjectCollectionEventReceiver(_supervisor.Subordinates);
        }
Beispiel #5
0
        public void ModifyOtherObjects()
        {
            _customer.Name = "New name";

            Ceo ceo = _customer.Ceo;

            ceo.Name = "New CEO name";

            Order            order            = _customer.Orders[DomainObjectIDs.Order1];
            IndustrialSector industrialSector = _customer.IndustrialSector;

            var ceoEventReceiver               = new DomainObjectEventReceiver(ceo);
            var customerEventReceiver          = new DomainObjectEventReceiver(_customer);
            var orderEventReceiver             = new DomainObjectEventReceiver(order);
            var industrialSectorEventReceiver  = new DomainObjectEventReceiver(industrialSector);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            _customer.Committing += (sender, e) => order.OrderNumber = 1000;
            TestableClientTransaction.Committing += (sender1, args) =>
            {
                var customer = (Customer)args.DomainObjects.SingleOrDefault(obj => obj.ID == DomainObjectIDs.Customer1);
                if (customer != null)
                {
                    customer.IndustrialSector.Name = "New industrial sector name";
                }
            };

            TestableClientTransaction.Commit();

            Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(customerEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(customerEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(orderEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(industrialSectorEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(industrialSectorEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjectsForFirstCommitEvent  = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committingDomainObjectsForSecondCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[1];
            var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjectsForFirstCommitEvent, Is.EquivalentTo(new DomainObject[] { _customer, ceo }));
            Assert.That(committingDomainObjectsForSecondCommitEvent, Is.EquivalentTo(new DomainObject[] { order, industrialSector }));
            Assert.That(committedDomainObjects, Is.EquivalentTo(new DomainObject[] { _customer, ceo, order, industrialSector }));
        }
Beispiel #6
0
        public override void SetUp()
        {
            base.SetUp();

            _order                    = DomainObjectIDs.Order1.GetObject <Order> ();
            _oldOrderTicket           = _order.OrderTicket;
            _newOrderTicket           = DomainObjectIDs.OrderTicket2.GetObject <OrderTicket> ();
            _oldOrderOfNewOrderTicket = DomainObjectIDs.Order2.GetObject <Order> ();

            _orderEventReceiver                    = new DomainObjectEventReceiver(_order);
            _oldOrderTicketEventReceiver           = new DomainObjectEventReceiver(_oldOrderTicket);
            _newOrderTicketEventReceiver           = new DomainObjectEventReceiver(_newOrderTicket);
            _oldOrderOfNewOrderTicketEventReceiver = new DomainObjectEventReceiver(_oldOrderOfNewOrderTicket);
        }
        public void ChangeTrackingEvents()
        {
            Customer customer = DomainObjectIDs.Customer1.GetObject <Customer> ();

            var eventReceiver = new DomainObjectEventReceiver(customer, false);

            customer.Name = "New name";

            Assert.That(eventReceiver.HasChangingEventBeenCalled, Is.EqualTo(true));
            Assert.That(eventReceiver.HasChangedEventBeenCalled, Is.EqualTo(true));
            Assert.That(customer.Name, Is.EqualTo("New name"));
            Assert.That(eventReceiver.ChangingOldValue, Is.EqualTo("Kunde 1"));
            Assert.That(eventReceiver.ChangingNewValue, Is.EqualTo("New name"));
            Assert.That(eventReceiver.ChangedOldValue, Is.EqualTo("Kunde 1"));
            Assert.That(eventReceiver.ChangedNewValue, Is.EqualTo("New name"));
        }
Beispiel #8
0
        public void Serialization_WithISerializable_IncludesEventHandlers()
        {
            ClassWithAllDataTypes instance = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
            var eventReceiver = new DomainObjectEventReceiver(instance);

            var deserializedData = Serializer.SerializeAndDeserialize(Tuple.Create(instance, eventReceiver));

            AssertEventRegistered(deserializedData.Item1, "RelationChanging", deserializedData.Item2, GetEventHandlerMethod(instance, "RelationChanging"));
            AssertEventRegistered(deserializedData.Item1, "RelationChanged", deserializedData.Item2, GetEventHandlerMethod(instance, "RelationChanged"));
            AssertEventRegistered(deserializedData.Item1, "PropertyChanging", deserializedData.Item2, GetEventHandlerMethod(instance, "PropertyChanging"));
            AssertEventRegistered(deserializedData.Item1, "PropertyChanged", deserializedData.Item2, GetEventHandlerMethod(instance, "PropertyChanged"));
            AssertEventRegistered(deserializedData.Item1, "Deleting", deserializedData.Item2, GetEventHandlerMethod(instance, "Deleting"));
            AssertEventRegistered(deserializedData.Item1, "Deleted", deserializedData.Item2, GetEventHandlerMethod(instance, "Deleted"));
            AssertEventRegistered(deserializedData.Item1, "Committing", deserializedData.Item2, GetEventHandlerMethod(instance, "Committing"));
            AssertEventRegistered(deserializedData.Item1, "Committed", deserializedData.Item2, GetEventHandlerMethod(instance, "Committed"));
            AssertEventRegistered(deserializedData.Item1, "RollingBack", deserializedData.Item2, GetEventHandlerMethod(instance, "RollingBack"));
            AssertEventRegistered(deserializedData.Item1, "RolledBack", deserializedData.Item2, GetEventHandlerMethod(instance, "RolledBack"));
        }
        public void CancelChangeTrackingEvents()
        {
            Customer customer = DomainObjectIDs.Customer1.GetObject <Customer> ();

            var eventReceiver = new DomainObjectEventReceiver(customer, true);

            try
            {
                customer.Name = "New name";
                Assert.Fail("EventReceiverCancelException should be raised.");
            }
            catch (EventReceiverCancelException)
            {
                Assert.That(eventReceiver.HasChangingEventBeenCalled, Is.EqualTo(true));
                Assert.That(eventReceiver.HasChangedEventBeenCalled, Is.EqualTo(false));
                Assert.That(customer.Name, Is.EqualTo("Kunde 1"));
                Assert.That(eventReceiver.ChangingOldValue, Is.EqualTo("Kunde 1"));
                Assert.That(eventReceiver.ChangingNewValue, Is.EqualTo("New name"));
            }
        }
Beispiel #10
0
        public void CommittedEventForObjectChangedBackToOriginal()
        {
            _customer.Name = "New name";

            var customerEventReceiver          = new DomainObjectEventReceiver(_customer);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            _customer.Committing += (sender, e) => { _customer.Name = _customer.Properties[typeof(Company), "Name"].GetOriginalValue <string>(); };

            TestableClientTransaction.Commit();

            Assert.That(customerEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(customerEventReceiver.HasCommittedEventBeenCalled, Is.False);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(1));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjects = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committedDomainObjects  = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjects.Count, Is.EqualTo(1));
            Assert.That(committedDomainObjects.Count, Is.EqualTo(0));
        }
Beispiel #11
0
        public void CommitEvents()
        {
            _customer.Name = "New name";

            var domainObjectEventReceiver      = new DomainObjectEventReceiver(_customer);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            TestableClientTransaction.Commit();

            Assert.That(domainObjectEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(domainObjectEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(1));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjects = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committedDomainObjects  = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjects.Count, Is.EqualTo(1));
            Assert.That(committedDomainObjects.Count, Is.EqualTo(1));

            Assert.That(committingDomainObjects[0], Is.SameAs(_customer));
            Assert.That(committedDomainObjects[0], Is.SameAs(_customer));
        }
        public void AddSubordinateWithOldSupervisor()
        {
            Employee subordinate = DomainObjectIDs.Employee3.GetObject <Employee> ();
            Employee oldSupervisorOfSubordinate = DomainObjectIDs.Employee2.GetObject <Employee> ();

            var subordinateEventReceiver = new DomainObjectEventReceiver(subordinate);

            subordinateEventReceiver.Cancel = false;

            var oldSupervisorEventReceiver = new DomainObjectEventReceiver(oldSupervisorOfSubordinate);

            oldSupervisorEventReceiver.Cancel = false;

            var oldSupervisorSubordinateCollectionEventReceiver = new DomainObjectCollectionEventReceiver(oldSupervisorOfSubordinate.Subordinates);

            oldSupervisorSubordinateCollectionEventReceiver.Cancel = false;

            _subordinateCollectionEventReceiver.Cancel = false;
            _supervisorEventReceiver.Cancel            = false;

            _supervisor.Subordinates.Add(subordinate);

            Assert.That(oldSupervisorEventReceiver.HasRelationChangingEventBeenCalled, Is.True);
            Assert.That(oldSupervisorEventReceiver.HasRelationChangedEventBeenCalled, Is.True);
            Assert.That(oldSupervisorEventReceiver.ChangingRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Subordinates"));
            Assert.That(oldSupervisorEventReceiver.ChangedRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Subordinates"));

            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.HasRemovingEventBeenCalled, Is.True);
            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.HasRemovedEventBeenCalled, Is.True);
            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.RemovingDomainObjects.Count, Is.EqualTo(1));
            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.RemovingDomainObjects[0], Is.SameAs(subordinate));
            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.RemovingDomainObjects.Count, Is.EqualTo(1));
            Assert.That(oldSupervisorSubordinateCollectionEventReceiver.RemovingDomainObjects[0], Is.SameAs(subordinate));


            Assert.That(subordinateEventReceiver.HasRelationChangingEventBeenCalled, Is.True);
            Assert.That(subordinateEventReceiver.HasRelationChangedEventBeenCalled, Is.True);
            Assert.That(subordinateEventReceiver.ChangingRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor"));
            Assert.That(subordinateEventReceiver.ChangedRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Supervisor"));
            Assert.That(subordinateEventReceiver.ChangingOldRelatedObject, Is.SameAs(oldSupervisorOfSubordinate));
            Assert.That(subordinateEventReceiver.ChangingNewRelatedObject, Is.SameAs(_supervisor));
            Assert.That(subordinateEventReceiver.ChangedOldRelatedObject, Is.SameAs(oldSupervisorOfSubordinate));
            Assert.That(subordinateEventReceiver.ChangedNewRelatedObject, Is.SameAs(_supervisor));

            Assert.That(_subordinateCollectionEventReceiver.HasAddingEventBeenCalled, Is.True);
            Assert.That(_subordinateCollectionEventReceiver.HasAddedEventBeenCalled, Is.True);
            Assert.That(_subordinateCollectionEventReceiver.AddingDomainObject, Is.SameAs(subordinate));
            Assert.That(_subordinateCollectionEventReceiver.AddedDomainObject, Is.SameAs(subordinate));

            Assert.That(_supervisorEventReceiver.HasRelationChangingEventBeenCalled, Is.True);
            Assert.That(_supervisorEventReceiver.HasRelationChangedEventBeenCalled, Is.True);
            Assert.That(_supervisorEventReceiver.ChangingRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Subordinates"));
            Assert.That(_supervisorEventReceiver.ChangedRelationPropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Subordinates"));
            Assert.That(_supervisorEventReceiver.ChangingOldRelatedObject, Is.Null);
            Assert.That(_supervisorEventReceiver.ChangingNewRelatedObject, Is.SameAs(subordinate));
            Assert.That(_supervisorEventReceiver.ChangedOldRelatedObject, Is.Null);
            Assert.That(_supervisorEventReceiver.ChangedNewRelatedObject, Is.SameAs(subordinate));

            Assert.That(subordinate.State, Is.EqualTo(StateType.Changed));
            Assert.That(_supervisor.State, Is.EqualTo(StateType.Changed));
            Assert.That(oldSupervisorOfSubordinate.State, Is.EqualTo(StateType.Changed));

            Assert.That(_supervisor.Subordinates[subordinate.ID], Is.Not.Null);
            Assert.That(_supervisor.Subordinates.IndexOf(subordinate), Is.EqualTo(_supervisor.Subordinates.Count - 1));
            Assert.That(oldSupervisorOfSubordinate.Subordinates.ContainsObject(subordinate), Is.False);
            Assert.That(subordinate.Supervisor, Is.SameAs(_supervisor));
        }