public void GetObjects_LoadedObjects_Events() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var eventReceiver = new ClientTransactionEventReceiver(subTransaction); DomainObjectIDs.Order1.GetObject <Order> (); DomainObjectIDs.Order3.GetObject <Order> (); DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); eventReceiver.Clear(); var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); PrivateInvoke.InvokeNonPublicMethod(subTransaction, "AddListener", listenerMock); LifetimeService.GetObjects <DomainObject> (subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(eventReceiver.LoadedDomainObjectLists, Is.Empty); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoading( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <ObjectID> > .Is.Anything)); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoaded( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything)); } }
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 GetObjects_UnloadedObjects_Events() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); PrivateInvoke.InvokeNonPublicMethod(subTransaction, "AddListener", listenerMock); var eventReceiver = new ClientTransactionEventReceiver(subTransaction); DomainObject[] objects = LifetimeService.GetObjects <DomainObject> ( subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(1)); Assert.That(eventReceiver.LoadedDomainObjectLists[0], Is.EqualTo(objects)); listenerMock.AssertWasCalled(mock => mock.ObjectsLoading( Arg.Is(subTransaction), Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 }))); listenerMock.AssertWasCalled(mock => mock.ObjectsLoaded( Arg.Is(subTransaction), Arg <ReadOnlyCollection <DomainObject> > .List.Equal(objects))); } }
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 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 })); }
public void CommitWithoutChanges() { var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); TestableClientTransaction.Commit(); 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(0)); Assert.That(committedDomainObjects.Count, Is.EqualTo(0)); }
public void IsNullRelatedObjectNonVirtualEndPoint() { Order newOrder = Order.NewObject(); Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer"].IsNull, Is.True); newOrder.Customer = Customer.NewObject(); Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer"].IsNull, Is.False); newOrder.Customer = null; Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer"].IsNull, Is.True); var eventReceiver = new ClientTransactionEventReceiver(ClientTransactionScope.CurrentTransaction); Order existingOrder = DomainObjectIDs.Order1.GetObject <Order> (); eventReceiver.Clear(); Assert.That(eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0)); Assert.That(existingOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer"].IsNull, Is.False); Assert.AreEqual(0, eventReceiver.LoadedDomainObjectLists.Count, "The IsNull check did not cause the object to be loaded."); }
public void CommitWithExistingObjectDeleted() { var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); ClassWithAllDataTypes classWithAllDataTypes = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); ObjectID classWithAllDataTypesID = classWithAllDataTypes.ID; classWithAllDataTypes.Delete(); TestableClientTransaction.Commit(); 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)); Assert.That(committingDomainObjects.Any(obj => obj.ID == classWithAllDataTypesID), Is.True); }
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)); }
public void IsNullRelatedObjectVirtualEndPoint() { Order newOrder = Order.NewObject(); Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket"].IsNull, Is.True); newOrder.OrderTicket = OrderTicket.NewObject(); Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket"].IsNull, Is.False); newOrder.OrderTicket = null; Assert.That(newOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket"].IsNull, Is.True); var eventReceiver = new ClientTransactionEventReceiver(ClientTransactionScope.CurrentTransaction); Order existingOrder = DomainObjectIDs.Order1.GetObject <Order> (); eventReceiver.Clear(); Assert.That(eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0)); Assert.That(existingOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket"].IsNull, Is.False); Assert.AreEqual(1, eventReceiver.LoadedDomainObjectLists.Count, "For virtual end points, the IsNull unfortunately does cause a load."); Assert.That(existingOrder.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket"].GetValue <OrderTicket> () == null, Is.False); Assert.AreEqual(1, eventReceiver.LoadedDomainObjectLists.Count, "An ordinary check does cause the object to be loaded."); }
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 override void SetUp() { base.SetUp(); _eventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); }