public void OnLoaded_CannotCauseSameObjectToBeLoadedInSubTx_WhileItIsLoadedIntoParent_InitiatedFromParent()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_order))
                .WhenCalled(
                    mi =>
                {
                    Assert.That(ClientTransaction.Current, Is.SameAs(ReadOnlyRootTransaction));
                    Assert.That(
                        () => WriteableSubTransaction.EnsureDataAvailable(_order.ID),
                        Throws.InvalidOperationException.With.Message.EqualTo(
                            "It's not possible to load objects into a subtransaction while they are being loaded into a parent transaction: "
                            + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid'."));
                });

                ReadOnlyRootTransaction.EnsureDataAvailable(_order.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckState(ReadOnlyRootTransaction, _order, StateType.Unchanged);
                CheckState(ReadOnlyMiddleTransaction, _order, StateType.NotLoadedYet);
                CheckState(WriteableSubTransaction, _order, StateType.NotLoadedYet);
            }
        }
Exemplo n.º 2
0
        public void PropertyValueReadInReadOnlyMiddleTransaction_WithoutLoading_IsAllowed()
        {
            WriteableSubTransaction.EnsureDataAvailable(_order1.ID);

            var value = ExecuteInReadOnlyMiddleTransaction(() => _order1.OrderNumber);

            Assert.That(value, Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public void RelationReadInReadOnlyMiddleTransaction_WithoutLoading_IsAllowed()
        {
            WriteableSubTransaction.EnsureDataComplete(_relationEndPointID);
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.Customer1);

            var customer = ExecuteInReadOnlyMiddleTransaction(() => _order1.Customer);

            Assert.That(customer.ID, Is.EqualTo(DomainObjectIDs.Customer1));
        }
        public void QueryInReadOnlyMiddleTransaction_WithoutLoading_IsAllowed()
        {
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.Order1);

            var resultSet = ExecuteInReadOnlyMiddleTransaction(() => QueryFactory.CreateLinqQuery <Order>().Where(obj => obj.OrderNumber == 1).ToList());

            Assert.That(resultSet, Has.Count.EqualTo(1));
            Assert.That(resultSet[0].ID, Is.EqualTo(DomainObjectIDs.Order1));
        }
Exemplo n.º 5
0
        public void RelationReadInReadOnlyMiddleTransaction_IsAllowed_NoLoading()
        {
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.Order1);
            WriteableSubTransaction.EnsureDataComplete(_relationEndPointID);
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.OrderTicket1);

            var orderTicket = ExecuteInReadOnlyMiddleTransaction(() => _order1.OrderTicket);

            Assert.That(orderTicket.ID, Is.EqualTo(DomainObjectIDs.OrderTicket1));
        }
        public void RelationReadInReadOnlyMiddleTransaction_WithoutLoading_IsAllowed()
        {
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.Order1);
            WriteableSubTransaction.EnsureDataComplete(_relationEndPointID);
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.OrderItem1);
            WriteableSubTransaction.EnsureDataAvailable(DomainObjectIDs.OrderItem2);

            var orderItems = ExecuteInReadOnlyMiddleTransaction(() => _order1.OrderItems.ToList());

            Assert.That(orderItems.Select(oi => oi.ID), Is.EquivalentTo(new[] { DomainObjectIDs.OrderItem1, DomainObjectIDs.OrderItem2 }));
        }
        public void OnLoaded_CannotDeleteObject()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                var expectedSpecificMessage = "Object 'Client|1627ade8-125f-4819-8e33-ce567c42b00c|System.Guid' cannot be deleted.";
                ExpectOnLoadedCalls(
                    _order,
                    mi => CheckForbiddenOperation(ReadOnlyRootTransaction, () => _client1.Delete(), _order, expectedSpecificMessage),
                    mi => CheckForbiddenOperation(ReadOnlyMiddleTransaction, () => _client1.Delete(), _order, expectedSpecificMessage),
                    mi => CheckForbiddenOperation(WriteableSubTransaction, () => _client1.Delete(), _order, expectedSpecificMessage));

                WriteableSubTransaction.EnsureDataAvailable(_order.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckState(ReadOnlyRootTransaction, _client1, StateType.Unchanged);
                CheckState(ReadOnlyMiddleTransaction, _client1, StateType.Unchanged);
                CheckState(WriteableSubTransaction, _client1, StateType.Unchanged);
            }
        }
        public void OnLoaded_CannotModifyThisObject_BidirectionalRelations()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                // Load _order, but trying to modify _order.OrderTicket would also modify _orderTicket1
                var offendingObject   = _orderTicket1;
                var offendingProperty = GetPropertyIdentifier(typeof(OrderTicket), "Order");
                ExpectOnLoadedCalls(
                    _order,
                    mi => CheckForbiddenSetProperty(ReadOnlyRootTransaction, _order, _order, o => o.OrderTicket, null, offendingObject, offendingProperty),
                    mi => CheckForbiddenSetProperty(ReadOnlyMiddleTransaction, _order, _order, o => o.OrderTicket, null, offendingObject, offendingProperty),
                    mi => CheckForbiddenSetProperty(WriteableSubTransaction, _order, _order, o => o.OrderTicket, null, offendingObject, offendingProperty));

                WriteableSubTransaction.EnsureDataAvailable(_order.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckProperty(ReadOnlyRootTransaction, _order, o => o.OrderTicket, expectedOriginalValue: _orderTicket1, expectedCurrentValue: _orderTicket1);
                CheckProperty(ReadOnlyMiddleTransaction, _order, o => o.OrderTicket, expectedOriginalValue: _orderTicket1, expectedCurrentValue: _orderTicket1);
                CheckProperty(WriteableSubTransaction, _order, o => o.OrderTicket, expectedOriginalValue: _orderTicket1, expectedCurrentValue: _orderTicket1);
            }
        }
        public void OnLoaded_CanModifyThisObject_PropertyValues()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_order))
                .WhenCalled(mi => CheckTransactionAndSetProperty(ReadOnlyRootTransaction, _order, o => o.OrderNumber, expectedValue: 1, newValue: 2));
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_order))
                .WhenCalled(mi => CheckTransactionAndSetProperty(ReadOnlyMiddleTransaction, _order, o => o.OrderNumber, expectedValue: 2, newValue: 3));
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_order))
                .WhenCalled(mi => CheckTransactionAndSetProperty(WriteableSubTransaction, _order, o => o.OrderNumber, expectedValue: 3, newValue: 4));
            }
            WriteableSubTransaction.EnsureDataAvailable(_order.ID);

            _loadEventReceiverMock.VerifyAllExpectations();

            CheckProperty(ReadOnlyRootTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 1, expectedCurrentValue: 2);
            CheckProperty(ReadOnlyMiddleTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 2, expectedCurrentValue: 3);
            CheckProperty(WriteableSubTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 3, expectedCurrentValue: 4);
        }
        public void OnLoaded_CannotModifyOtherObject_UnidirectionalRelations()
        {
            // No load events for _location
            _location.SetLoadEventReceiver(null);

            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                // Load _order, but try to modify _location
                ExpectOnLoadedCalls(
                    _order,
                    mi => CheckForbiddenSetProperty(ReadOnlyRootTransaction, _order, _location, l => l.Client, newValue: _client2),
                    mi => CheckForbiddenSetProperty(ReadOnlyMiddleTransaction, _order, _location, l => l.Client, newValue: _client3),
                    mi => CheckForbiddenSetProperty(WriteableSubTransaction, _order, _location, l => l.Client, newValue: _client4));

                WriteableSubTransaction.EnsureDataAvailable(_order.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckProperty(ReadOnlyRootTransaction, _location, l => l.Client, expectedOriginalValue: _client1, expectedCurrentValue: _client1);
                CheckProperty(ReadOnlyMiddleTransaction, _location, l => l.Client, expectedOriginalValue: _client1, expectedCurrentValue: _client1);
                CheckProperty(WriteableSubTransaction, _location, l => l.Client, expectedOriginalValue: _client1, expectedCurrentValue: _client1);
            }
        }
        public void OnLoaded_CannotModifyOtherObject_PropertyValues()
        {
            // No load events for _order
            _order.SetLoadEventReceiver(null);

            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                // Load _location, but try to modify _order
                ExpectOnLoadedCalls(
                    _location,
                    mi => CheckForbiddenSetProperty(ReadOnlyRootTransaction, _location, _order, o => o.OrderNumber, newValue: 2),
                    mi => CheckForbiddenSetProperty(ReadOnlyMiddleTransaction, _location, _order, o => o.OrderNumber, newValue: 3),
                    mi => CheckForbiddenSetProperty(WriteableSubTransaction, _location, _order, o => o.OrderNumber, newValue: 4));

                WriteableSubTransaction.EnsureDataAvailable(_location.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckProperty(ReadOnlyRootTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 1, expectedCurrentValue: 1);
                CheckProperty(ReadOnlyMiddleTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 1, expectedCurrentValue: 1);
                CheckProperty(WriteableSubTransaction, _order, o => o.OrderNumber, expectedOriginalValue: 1, expectedCurrentValue: 1);
            }
        }
        public void OnLoaded_CanModifyThisObject_UnidirectionalRelations()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_location))
                .WhenCalled(mi => CheckTransactionAndSetProperty(ReadOnlyRootTransaction, _location, l => l.Client, expectedValue: _client1, newValue: _client2));
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_location))
                .WhenCalled(mi => CheckTransactionAndSetProperty(ReadOnlyMiddleTransaction, _location, l => l.Client, expectedValue: _client2, newValue: _client3));
                _loadEventReceiverMock
                .Expect(mock => mock.OnLoaded(_location))
                .WhenCalled(mi => CheckTransactionAndSetProperty(WriteableSubTransaction, _location, l => l.Client, expectedValue: _client3, newValue: _client4));
            }

            WriteableSubTransaction.EnsureDataAvailable(_location.ID);

            _loadEventReceiverMock.VerifyAllExpectations();

            CheckProperty(ReadOnlyRootTransaction, _location, l => l.Client, expectedOriginalValue: _client1, expectedCurrentValue: _client2);
            CheckProperty(ReadOnlyMiddleTransaction, _location, l => l.Client, expectedOriginalValue: _client2, expectedCurrentValue: _client3);
            CheckProperty(WriteableSubTransaction, _location, l => l.Client, expectedOriginalValue: _client3, expectedCurrentValue: _client4);
        }
        public void OnLoaded_CannotCreateObject()
        {
            using (_loadEventReceiverMock.GetMockRepository().Ordered())
            {
                var expectedSpecificMessage = "An object of type 'Partner' cannot be created.";
                ExpectOnLoadedCalls(
                    _order,
                    mi => CheckForbiddenOperation(ReadOnlyRootTransaction, () => Partner.NewObject(), _order, expectedSpecificMessage),
                    mi => CheckForbiddenOperation(ReadOnlyMiddleTransaction, () => Partner.NewObject(), _order, expectedSpecificMessage),
                    mi => CheckForbiddenOperation(WriteableSubTransaction, () => Partner.NewObject(), _order, expectedSpecificMessage));

                WriteableSubTransaction.EnsureDataAvailable(_order.ID);

                _loadEventReceiverMock.VerifyAllExpectations();

                CheckNoDataLoadedForType(ReadOnlyRootTransaction);
                Assert.That(
                    ClientTransactionTestHelper.GetIDataManager(ReadOnlyMiddleTransaction).DataContainers.All(
                        dc => dc.DomainObjectType != typeof(ClassWithAllDataTypes)));
                Assert.That(
                    ClientTransactionTestHelper.GetIDataManager(WriteableSubTransaction).DataContainers.All(
                        dc => dc.DomainObjectType != typeof(ClassWithAllDataTypes)));
            }
        }