public void DomainObjectCollection_Events_Contents() { var collection = new DomainObjectCollection(typeof(Order)) { DomainObjectIDs.Order1.GetObject <Order> () }; var eventReceiver = new DomainObjectCollectionEventReceiver(collection); var deserializedCollectionAndEventReceiver = Serializer.SerializeAndDeserialize(Tuple.Create(collection, eventReceiver)); var deserializedCollection = deserializedCollectionAndEventReceiver.Item1; var deserializedEventReceiver = deserializedCollectionAndEventReceiver.Item2; Assert.That(deserializedEventReceiver.HasAddedEventBeenCalled, Is.False); Assert.That(deserializedEventReceiver.HasAddingEventBeenCalled, Is.False); Assert.That(deserializedEventReceiver.HasRemovedEventBeenCalled, Is.False); Assert.That(deserializedEventReceiver.HasRemovingEventBeenCalled, Is.False); deserializedCollection.Add(Order.NewObject()); deserializedCollection.RemoveAt(0); Assert.That(deserializedEventReceiver.HasAddedEventBeenCalled, Is.True); Assert.That(deserializedEventReceiver.HasAddingEventBeenCalled, Is.True); Assert.That(deserializedEventReceiver.HasRemovedEventBeenCalled, Is.True); Assert.That(deserializedEventReceiver.HasRemovingEventBeenCalled, 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)); }
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); }
public void SetCollection_RaisesNoEventsOnCollections() { var oldOpposites = _customerEndPoint.Collection; var oldEventListener = new DomainObjectCollectionEventReceiver(oldOpposites); var newOpposites = new OrderCollection { _order2 }; var newEventListener = new DomainObjectCollectionEventReceiver(newOpposites); SetCollectionAndNotify(_customerEndPoint, newOpposites); Assert.That(oldEventListener.HasAddedEventBeenCalled, Is.False); Assert.That(oldEventListener.HasAddingEventBeenCalled, Is.False); Assert.That(oldEventListener.HasRemovedEventBeenCalled, Is.False); Assert.That(oldEventListener.HasRemovingEventBeenCalled, Is.False); Assert.That(newEventListener.HasAddedEventBeenCalled, Is.False); Assert.That(newEventListener.HasAddingEventBeenCalled, Is.False); Assert.That(newEventListener.HasRemovedEventBeenCalled, Is.False); Assert.That(newEventListener.HasRemovingEventBeenCalled, Is.False); }
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)); }