public void EnsureDataAvailable_ReloadsObject()
        {
            var order1 = DomainObjectIDs.Order1.GetObject <Order> ();

            UnloadService.UnloadData(TestableClientTransaction, order1.ID);
            Assert.That(order1.State, Is.EqualTo(StateType.NotLoadedYet));

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            order1.EnsureDataAvailable();

            AssertObjectWasLoaded(listenerMock, order1);
            Assert.That(order1.State, Is.EqualTo(StateType.Unchanged));
        }
        public void WritingValueProperties_ReloadsObject()
        {
            var order1 = DomainObjectIDs.Order1.GetObject <Order> ();

            UnloadService.UnloadData(TestableClientTransaction, order1.ID);
            Assert.That(order1.State, Is.EqualTo(StateType.NotLoadedYet));

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            order1.OrderNumber = 4711;

            AssertObjectWasLoaded(listenerMock, order1);
            Assert.That(order1.State, Is.EqualTo(StateType.Changed));
        }
Beispiel #3
0
        public void SetValue_WithRelatedObject_Notifies()
        {
            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            var order     = DomainObjectIDs.Order1.GetObject <Order> ();
            var oldTicket = order.OrderTicket;
            var newTicket = OrderTicket.NewObject();

            var propertyAccessor = CreateAccessor(order, "OrderTicket");

            propertyAccessor.SetValue(newTicket);

            listenerMock.AssertWasCalled(
                mock => mock.RelationChanged(TestableClientTransaction, order, propertyAccessor.PropertyData.RelationEndPointDefinition, oldTicket, newTicket));
        }
        public void AddingToCollectionEndPoint_ReloadsObjectBeingAdded()
        {
            var customer = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var order3   = DomainObjectIDs.Order3.GetObject <Order> ();

            UnloadService.UnloadData(TestableClientTransaction, order3.ID);
            Assert.That(order3.State, Is.EqualTo(StateType.NotLoadedYet));

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            customer.Orders.Add(order3); // reloads order3 because order3's foreign key is changed

            AssertObjectWasLoaded(listenerMock, order3);
            Assert.That(order3.State, Is.EqualTo(StateType.Changed));
        }
Beispiel #5
0
        public void SetValue_WithObjectList_Notifies()
        {
            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            IndustrialSector sector = IndustrialSector.NewObject();
            var newCompanies        = new ObjectList <Company> {
                Company.NewObject()
            };

            var propertyAccessor = CreateAccessor(sector, "Companies");

            propertyAccessor.SetValue(newCompanies);

            listenerMock.AssertWasCalled(
                mock => mock.RelationChanged(TestableClientTransaction, sector, propertyAccessor.PropertyData.RelationEndPointDefinition, null, newCompanies[0]));
        }
        public void ReadingRealRelationEndPoints_ReloadsObject()
        {
            var order1   = DomainObjectIDs.Order1.GetObject <Order> ();
            var customer = order1.Customer;

            UnloadService.UnloadData(TestableClientTransaction, order1.ID);
            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            Assert.That(order1.State, Is.EqualTo(StateType.NotLoadedYet));

            Assert.That(order1.Customer, Is.SameAs(customer)); // reloads the object because the foreign key is stored in order1

            AssertObjectWasLoaded(listenerMock, order1);

            Assert.That(order1.State, Is.EqualTo(StateType.Unchanged));
        }
        public void Rollback()
        {
            var newObject = ClassWithAllDataTypes.NewObject();

            Assert.That(newObject.State, Is.EqualTo(StateType.New));

            var changedObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();

            ++changedObject.Int32Property;
            Assert.That(changedObject.State, Is.EqualTo(StateType.Changed));

            var unchangedObject = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();

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

            newObject.RegisterForCommit();
            changedObject.RegisterForCommit();
            unchangedObject.RegisterForCommit();

            Assert.That(newObject.State, Is.EqualTo(StateType.New));
            CheckNotMarkedAsChanged(newObject);
            Assert.That(changedObject.State, Is.EqualTo(StateType.Changed));
            CheckMarkedAsChanged(changedObject);
            Assert.That(unchangedObject.State, Is.EqualTo(StateType.Changed));
            CheckMarkedAsChanged(unchangedObject);

            var objectEventReceiverMock      = MockRepository.GenerateMock <DomainObjectMockEventReceiver> (unchangedObject);
            var transactionEventReceiverMock = MockRepository.GenerateMock <ClientTransactionMockEventReceiver> (TestableClientTransaction);
            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            TestableClientTransaction.Rollback();

            listenerMock.AssertWasCalled(
                mock => mock.TransactionRollingBack(
                    Arg.Is(TestableClientTransaction),
                    Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(new[] { newObject, changedObject, unchangedObject })));
            objectEventReceiverMock.AssertWasCalled(mock => mock.RollingBack());
            objectEventReceiverMock.AssertWasCalled(mock => mock.RolledBack());
            transactionEventReceiverMock.AssertWasCalled(mock => mock.RollingBack(newObject, changedObject, unchangedObject));
            transactionEventReceiverMock.AssertWasCalled(mock => mock.RolledBack(changedObject, unchangedObject));

            Assert.That(newObject.State, Is.EqualTo(StateType.Invalid));
            Assert.That(changedObject.State, Is.EqualTo(StateType.Unchanged));
            CheckNotMarkedAsChanged(changedObject);
            Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged));
            CheckNotMarkedAsChanged(unchangedObject);
        }
        public void ChangingCollectionEndPoint_ReloadsCollectionAndObject()
        {
            var order1         = DomainObjectIDs.Order1.GetObject <Order> ();
            var customer       = order1.Customer;
            var customerOrders = customer.Orders;

            UnloadService.UnloadData(TestableClientTransaction, order1.ID);

            Assert.That(order1.State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(customerOrders.IsDataComplete, Is.False);

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            customer.Orders.Add(Order.NewObject()); // reloads the relation contents and thus the object

            AssertObjectWasLoadedAmongOthers(listenerMock, order1);

            Assert.That(order1.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(customerOrders.IsDataComplete, Is.True);
        }
        public void CommitSub()
        {
            ClassWithAllDataTypes newObject;
            ClassWithAllDataTypes changedObject;
            ClassWithAllDataTypes unchangedObject;

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                newObject = ClassWithAllDataTypes.NewObject();
                Assert.That(newObject.State, Is.EqualTo(StateType.New));

                changedObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                ++changedObject.Int32Property;
                Assert.That(changedObject.State, Is.EqualTo(StateType.Changed));

                unchangedObject = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();
                Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged));

                newObject.RegisterForCommit();
                changedObject.RegisterForCommit();
                unchangedObject.RegisterForCommit();

                Assert.That(newObject.State, Is.EqualTo(StateType.New));
                CheckNotMarkedAsChanged(newObject);
                Assert.That(changedObject.State, Is.EqualTo(StateType.Changed));
                CheckMarkedAsChanged(changedObject);
                Assert.That(unchangedObject.State, Is.EqualTo(StateType.Changed));
                CheckMarkedAsChanged(unchangedObject);

                var objectEventReceiverMock      = MockRepository.GenerateMock <DomainObjectMockEventReceiver> (newObject);
                var transactionEventReceiverMock = MockRepository.GenerateMock <ClientTransactionMockEventReceiver> (ClientTransaction.Current);
                var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(ClientTransaction.Current);
                try
                {
                    ClientTransaction.Current.Commit();
                }
                finally
                {
                    ClientTransactionTestHelper.RemoveListener(ClientTransaction.Current, listenerMock);
                }

                listenerMock.AssertWasCalled(
                    mock => mock.TransactionCommitting(
                        Arg.Is(ClientTransaction.Current),
                        Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(new[] { newObject, changedObject, unchangedObject }),
                        Arg <ICommittingEventRegistrar> .Is.Anything));
                listenerMock.AssertWasCalled(
                    mock => mock.TransactionCommitValidate(
                        Arg.Is(ClientTransaction.Current),
                        Arg <ReadOnlyCollection <PersistableData> > .Matches(
                            x => x.Select(d => d.DomainObject).SetEquals(new[] { newObject, changedObject, unchangedObject }))));
                objectEventReceiverMock.AssertWasCalled(mock => mock.Committing());
                objectEventReceiverMock.AssertWasCalled(mock => mock.Committed());
                transactionEventReceiverMock.AssertWasCalled(mock => mock.Committing(newObject, changedObject, unchangedObject));
                transactionEventReceiverMock.AssertWasCalled(mock => mock.Committed(newObject, changedObject, unchangedObject));

                Assert.That(newObject.State, Is.EqualTo(StateType.Unchanged));
                CheckNotMarkedAsChanged(newObject);
                Assert.That(changedObject.State, Is.EqualTo(StateType.Unchanged));
                CheckNotMarkedAsChanged(changedObject);
                Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged));
                CheckNotMarkedAsChanged(unchangedObject);
            }

            Assert.That(newObject.State, Is.EqualTo(StateType.New));
            CheckNotMarkedAsChanged(newObject);
            Assert.That(changedObject.State, Is.EqualTo(StateType.Changed));
            CheckMarkedAsChanged(changedObject);
            Assert.That(unchangedObject.State, Is.EqualTo(StateType.Changed));
            CheckMarkedAsChanged(unchangedObject);
        }
Beispiel #10
0
        public override void SetUp()
        {
            base.SetUp();

            _listenerDynamicMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);
        }
Beispiel #11
0
        public void UnloadVirtualEndPointAndItemData_Collection_Events()
        {
            var order1     = DomainObjectIDs.Order1.GetObject <Order> ();
            var orderItemA = order1.OrderItems[0];
            var orderItemB = order1.OrderItems[1];

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            using (listenerMock.GetMockRepository().Ordered())
            {
                listenerMock
                .Expect(mock => mock.ObjectsUnloading(
                            Arg.Is(TestableClientTransaction),
                            Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { orderItemA, orderItemB })))
                .WhenCalled(
                    mi =>
                {
                    Assert.That(orderItemA.OnUnloadingCalled, Is.False, "items unloaded after this method is called");
                    Assert.That(orderItemB.OnUnloadingCalled, Is.False, "items unloaded after this method is called");
                    Assert.That(orderItemA.OnUnloadedCalled, Is.False, "items unloaded after this method is called");
                    Assert.That(orderItemB.OnUnloadedCalled, Is.False, "items unloaded after this method is called");

                    Assert.That(orderItemA.State, Is.EqualTo(StateType.Unchanged));
                    Assert.That(orderItemB.State, Is.EqualTo(StateType.Unchanged));
                });
                listenerMock
                .Expect(mock => mock.ObjectsUnloaded(
                            Arg.Is(TestableClientTransaction),
                            Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { orderItemA, orderItemB })))
                .WhenCalled(
                    mi =>
                {
                    Assert.That(orderItemA.OnUnloadingCalled, Is.True, "items unloaded before this method is called");
                    Assert.That(orderItemB.OnUnloadingCalled, Is.True, "items unloaded before this method is called");
                    Assert.That(orderItemA.OnUnloadedCalled, Is.True, "items unloaded before this method is called");
                    Assert.That(orderItemB.OnUnloadedCalled, Is.True, "items unloaded before this method is called");

                    Assert.That(orderItemA.State, Is.EqualTo(StateType.NotLoadedYet));
                    Assert.That(orderItemB.State, Is.EqualTo(StateType.NotLoadedYet));
                });
            }

            listenerMock.Replay();

            try
            {
                UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, order1.OrderItems.AssociatedEndPointID);
                listenerMock.VerifyAllExpectations();
            }
            finally
            {
                listenerMock.BackToRecord(); // For Discarding
            }

            Assert.That(orderItemA.UnloadingState, Is.EqualTo(StateType.Unchanged), "OnUnloading before state change");
            Assert.That(orderItemB.UnloadingState, Is.EqualTo(StateType.Unchanged), "OnUnloading before state change");
            Assert.That(orderItemA.OnUnloadingDateTime, Is.LessThan(orderItemB.OnUnloadingDateTime), "orderItemA.OnUnloading before orderItemB.OnUnloading");

            Assert.That(orderItemA.UnloadedState, Is.EqualTo(StateType.NotLoadedYet), "OnUnloaded after state change");
            Assert.That(orderItemB.UnloadedState, Is.EqualTo(StateType.NotLoadedYet), "OnUnloaded after state change");
            Assert.That(orderItemA.OnUnloadedDateTime, Is.GreaterThan(orderItemB.OnUnloadedDateTime), "orderItemA.OnUnloaded after orderItemB.OnUnloaded");
        }