public void GetObject_Subtransaction()
        {
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                Assert.That(
                    () => _nonExistingObjectIDForSubtransaction.GetObject <TestDomainBase> (includeDeleted: true),
                    ThrowsObjectInvalidException(_nonExistingObjectIDForSubtransaction));

                CheckObjectIsMarkedInvalid(_nonExistingObjectIDForSubtransaction);

                Assert.That(
                    () => _nonExistingObjectID.GetObject <TestDomainBase> (includeDeleted: true),
                    ThrowsObjectNotFoundException(_nonExistingObjectID));

                CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            }

            CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            CheckObjectIsNotMarkedInvalid(_nonExistingObjectIDForSubtransaction);
        }
        public void TryEnsureDataAvailable_Subtransaction()
        {
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                var instance = LifetimeService.GetObjectReference(ClientTransaction.Current, _nonExistingObjectIDForSubtransaction);
                CheckObjectIsMarkedInvalid(instance.ID);

                Assert.That(() => instance.TryEnsureDataAvailable(), ThrowsObjectInvalidException(_nonExistingObjectIDForSubtransaction));

                var instance2 = LifetimeService.GetObjectReference(ClientTransaction.Current, _nonExistingObjectID);

                var result = instance2.TryEnsureDataAvailable();

                Assert.That(result, Is.False);
                CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            }

            CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            CheckObjectIsNotMarkedInvalid(_nonExistingObjectIDForSubtransaction);
        }
Ejemplo n.º 3
0
        public void UnloadVirtualEndPointAndItemData_IsAtomicWithinTransaction_WhenCollectionIsChanged()
        {
            var order1     = DomainObjectIDs.Order1.GetObject <Order> ();
            var endPointID = RelationEndPointID.Resolve(order1, o => o.OrderItems);
            var orderItemA = order1.OrderItems[0];
            var orderItemB = order1.OrderItems[1];

            // Change the collection, but not the items; we need to test this within a subtransaction because this is the only way to get the collection to
            // change without changing items (or the collection reference, which doesn't influence unloadability).
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                order1.OrderItems.Clear();
                order1.OrderItems.Add(orderItemB);
                order1.OrderItems.Add(orderItemA);

                Assert.That(orderItemA.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(orderItemB.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(DataManagementService.GetDataManager(ClientTransaction.Current).GetRelationEndPointWithoutLoading(endPointID).HasChanged, Is.True);
                Assert.That(order1.OrderItems.IsDataComplete, Is.True);

                CheckDataContainerExists(orderItemA, true);
                CheckDataContainerExists(orderItemB, true);
                CheckVirtualEndPointExistsAndComplete(endPointID, true, true);

                Assert.That(() => UnloadService.UnloadVirtualEndPointAndItemData(ClientTransaction.Current, endPointID), Throws.InvalidOperationException);

                CheckDataContainerExists(orderItemA, true);
                CheckDataContainerExists(orderItemB, true);
                CheckVirtualEndPointExistsAndComplete(endPointID, true, true);

                Assert.That(UnloadService.TryUnloadVirtualEndPointAndItemData(ClientTransaction.Current, endPointID), Is.False);

                CheckDataContainerExists(orderItemA, true);
                CheckDataContainerExists(orderItemB, true);
                CheckVirtualEndPointExistsAndComplete(endPointID, true, true);

                Assert.That(orderItemA.State, Is.Not.EqualTo(StateType.NotLoadedYet));
                Assert.That(orderItemB.State, Is.Not.EqualTo(StateType.NotLoadedYet));
                Assert.That(order1.OrderItems.IsDataComplete, Is.True);
            }
        }
        public void ThrowingObject_AlsoThrowingFromOnDeleting_CausesObjectCleanupException()
        {
            OrderItem throwingInstance = null;

            RegisterThrowingCtorHandler <OrderItem> (instance =>
            {
                throwingInstance   = instance;
                instance.Deleting += (sender, args) => { throw _deleteException; };
            });

            // Unfortunately, we can't use Assert.That (() => ..., Throws) here because the throwingInstance (required for constructing the message
            // check constraint) only exists once the NewObject call has executed. Therefore, use manual try/catch instead.
            try
            {
                OrderItem.NewObject();
                Assert.Fail("Expected ObjectCleanupException.");
            }
            catch (ObjectCleanupException ex)
            {
                Assert.That(ex, Is.TypeOf <ObjectCleanupException> ()
                            .With.Message.EqualTo(
                                "While cleaning up an object of type 'Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem' that threw an exception of type "
                                + "'System.Exception' from its constructor, another exception of type 'System.InvalidOperationException' was encountered. "
                                + "Cleanup was therefore aborted, and a partially constructed object with ID '" + throwingInstance.ID + "' remains "
                                + "within the ClientTransaction '" + TestableClientTransaction
                                + "'. Rollback the transaction to get rid of the partially constructed instance." + Environment.NewLine
                                + "Message of original exception: Test exception." + Environment.NewLine
                                + "Message of exception occurring during cleanup: Thrown from Deleting!")
                            .And.Property("ObjectID").Matches <ObjectID> (id => throwingInstance != null && id == throwingInstance.ID)
                            .And.InnerException.SameAs(_exception)
                            .And.Property("CleanupException").SameAs(_deleteException));
            }

            Assert.That(throwingInstance.State, Is.EqualTo(StateType.New));
            Assert.That(TestableClientTransaction.DataManager.DataContainers[throwingInstance.ID], Is.Not.Null);

            TestableClientTransaction.Rollback();

            Assert.That(throwingInstance.State, Is.EqualTo(StateType.Invalid));
            Assert.That(TestableClientTransaction.DataManager.DataContainers[throwingInstance.ID], Is.Null);
        }
Ejemplo n.º 5
0
        public void SubTransactionHasDifferentExtensions()
        {
            ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction();

            Assert.That(subTransaction.Extensions, Is.Not.SameAs(TestableClientTransaction.Extensions));

            var extensionStub1 = MockRepository.GenerateStub <IClientTransactionExtension>();

            extensionStub1.Stub(stub => stub.Key).Return("E1");
            var extensionStub2 = MockRepository.GenerateStub <IClientTransactionExtension>();

            extensionStub2.Stub(stub => stub.Key).Return("E2");

            TestableClientTransaction.Extensions.Add(extensionStub1);
            Assert.That(TestableClientTransaction.Extensions, Has.Member(extensionStub1));
            Assert.That(subTransaction.Extensions, Has.No.Member(extensionStub1));

            subTransaction.Extensions.Add(extensionStub2);
            Assert.That(subTransaction.Extensions, Has.Member(extensionStub2));
            Assert.That(TestableClientTransaction.Extensions, Has.No.Member(extensionStub2));
        }
        public void TryGetObject_Subtransaction()
        {
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                DomainObject instance = null;
                CheckObjectIsMarkedInvalid(_nonExistingObjectIDForSubtransaction);

                Assert.That(() => instance = _nonExistingObjectIDForSubtransaction.TryGetObject <TestDomainBase> (), Throws.Nothing);

                Assert.That(instance, Is.Not.Null);
                Assert.That(instance.State, Is.EqualTo(StateType.Invalid));

                Assert.That(() => instance = _nonExistingObjectID.TryGetObject <TestDomainBase> (), Throws.Nothing);

                Assert.That(instance, Is.Null);
                CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            }

            CheckObjectIsMarkedInvalid(_nonExistingObjectID);
            CheckObjectIsNotMarkedInvalid(_nonExistingObjectIDForSubtransaction);
        }
        public void StateInRootAndSubTransaction()
        {
            Customer customer = DomainObjectIDs.Customer1.GetObject <Customer> ();

            customer.Name = "New name";

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                Assert.That(customer.State, Is.EqualTo(StateType.NotLoadedYet));

                customer.EnsureDataAvailable();

                Assert.That(customer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(customer.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.Changed));

                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                {
                    Assert.That(customer.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.Changed)); // must not throw a ClientTransactionDiffersException
                }
            }
        }
        public void ResurrectInvalidObject_Hierarchy_InvalidInRootOnly()
        {
            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            using (subTransaction.EnterDiscardingScope())
            {
                var objectInvalidInRootOnly = Order.NewObject();

                Assert.That(TestableClientTransaction.IsInvalid(objectInvalidInRootOnly.ID), Is.True);
                Assert.That(subTransaction.IsInvalid(objectInvalidInRootOnly.ID), Is.False);

                Assert.That(
                    () => ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, objectInvalidInRootOnly.ID),
                    Throws.InvalidOperationException.With.Message.EqualTo(
                        "Cannot resurrect object '" + objectInvalidInRootOnly.ID + "' because it is not invalid within the whole transaction hierarchy. "
                        + "In transaction '" + subTransaction + "', the object has state 'New'."));

                Assert.That(TestableClientTransaction.IsInvalid(objectInvalidInRootOnly.ID), Is.True);
                Assert.That(subTransaction.IsInvalid(objectInvalidInRootOnly.ID), Is.False);
            }
        }
Ejemplo n.º 9
0
        public void TryResurrectObject_ViaSubTransaction()
        {
            var notFoundID     = new ObjectID(typeof(Order), Guid.NewGuid());
            var notFoundObject = LifetimeService.GetObjectReference(TestableClientTransaction, notFoundID);

            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            using (subTransaction.EnterDiscardingScope())
            {
                notFoundObject.TryEnsureDataAvailable();

                CheckStateIsInvalid(notFoundObject, TestableClientTransaction);
                CheckStateIsInvalid(notFoundObject, subTransaction);

                var result = ResurrectionService.TryResurrectInvalidObject(subTransaction, notFoundID);

                Assert.That(result, Is.True);
                CheckStateIsNotInvalid(notFoundObject, TestableClientTransaction, StateType.NotLoadedYet);
                CheckStateIsNotInvalid(notFoundObject, subTransaction, StateType.NotLoadedYet);
            }
        }
Ejemplo n.º 10
0
        public void Sort_NotSortedYet_StateAndHasChangedGoToChanged_InSubTransaction()
        {
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                Assert.That(_owningCustomer.Orders, Is.EqualTo(new[] { _itemA, _itemB }));
                Assert.That(_owningCustomer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_owningCustomer.Properties[typeof(Customer), "Orders"].HasChanged, Is.False);
                Assert.That(_owningCustomer.Properties[typeof(Customer), "Orders"].HasBeenTouched, Is.False);
                Assert.That(_itemA.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_itemB.State, Is.EqualTo(StateType.Unchanged));

                _owningCustomer.Orders.Sort(_reversingComparison);

                Assert.That(_owningCustomer.Orders, Is.EqualTo(new[] { _itemB, _itemA }));
                Assert.That(_owningCustomer.State, Is.EqualTo(StateType.Changed));
                Assert.That(_owningCustomer.Properties[typeof(Customer), "Orders"].HasChanged, Is.True);
                Assert.That(_owningCustomer.Properties[typeof(Customer), "Orders"].HasBeenTouched, Is.True);
                Assert.That(_itemA.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_itemB.State, Is.EqualTo(StateType.Unchanged));
            }
        }
        public void Commit_Rollback_ExistingObject()
        {
            DateTime referenceDateTime = DateTime.Now;
            Employee referenceEmployee = DomainObjectIDs.Employee1.GetObject <Employee> ();

            Computer computer = DomainObjectIDs.Computer1.GetObject <Computer> ();

            CheckDefaultValueAndValueAfterSet(computer, referenceDateTime, referenceEmployee);

            TestableClientTransaction.Rollback();
            Assert.That(computer.Int32TransactionProperty, Is.EqualTo(0));
            Assert.That(computer.DateTimeTransactionProperty, Is.EqualTo(new DateTime()));
            Assert.That(computer.EmployeeTransactionProperty, Is.Null);

            computer.Int32TransactionProperty    = 5;
            computer.DateTimeTransactionProperty = referenceDateTime;
            computer.EmployeeTransactionProperty = referenceEmployee;

            CheckValueAfterCommitAndRollback(computer, referenceDateTime, referenceEmployee);
            CheckValueInParallelRootTransaction(computer, referenceEmployee);
        }
        public void QueriedObjectsCanBeUsedInParentTransaction()
        {
            IQueryResult queriedObjects;

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                var query = QueryFactory.CreateQueryFromConfiguration("CustomerTypeQuery");
                query.Parameters.Add("@customerType", Customer.CustomerType.Standard);

                queriedObjects = ClientTransactionScope.CurrentTransaction.QueryManager.GetCollection(query);
            }

            var queriedObject = (Customer)queriedObjects.ToArray()[0];

            Assert.That(queriedObjects, Is.Not.Null);
            Assert.That(queriedObjects.Count, Is.EqualTo(1));

            Assert.That(queriedObject.ID, Is.EqualTo(DomainObjectIDs.Customer1));
            Assert.That(queriedObject.CustomerSince, Is.EqualTo(new DateTime(2000, 1, 1)));
            Assert.That(queriedObject.Orders[0], Is.SameAs(DomainObjectIDs.Order1.GetObject <Order> ()));
        }
        public void MandatoryRelationNotSetExceptionForOneToOneRelation_WithValidationExtension()
        {
            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            subTransaction.Extensions.Add(new CommitValidationClientTransactionExtension(new MandatoryRelationValidator()));

            using (subTransaction.EnterDiscardingScope())
            {
                OrderTicket newOrderTicket = OrderTicket.NewObject();

                Assert.That(
                    () => subTransaction.Commit(),
                    Throws.TypeOf <MandatoryRelationNotSetException>().With.Message.EqualTo(
                        string.Format(
                            "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order' of domain object '{0}' cannot be null.",
                            newOrderTicket.ID))
                    .And.Property <MandatoryRelationNotSetException> (ex => ex.PropertyName).EqualTo(
                        "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order")
                    .And.Property <MandatoryRelationNotSetException> (ex => ex.DomainObject).SameAs(newOrderTicket));
            }
        }
Ejemplo n.º 14
0
        public void NewInDescendant()
        {
            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            using (subTransaction.EnterDiscardingScope())
            {
                var newObject = Order.NewObject();

                CheckStateIsInvalid(newObject, TestableClientTransaction);
                CheckStateIsNotInvalid(newObject, subTransaction, StateType.New);

                Assert.That(
                    () => ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, newObject.ID),
                    Throws.InvalidOperationException.With.Message.EqualTo(
                        "Cannot resurrect object '" + newObject.ID + "' because it is not invalid within the whole transaction hierarchy. "
                        + "In transaction '" + subTransaction + "', the object has state 'New'."));

                var result = ResurrectionService.TryResurrectInvalidObject(TestableClientTransaction, newObject.ID);
                Assert.That(result, Is.False);
            }
        }
        public void MandatoryRelationNotSetExceptionForOneToManyRelation_WithValidationExtension()
        {
            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            subTransaction.Extensions.Add(new CommitValidationClientTransactionExtension(new MandatoryRelationValidator()));

            using (subTransaction.EnterDiscardingScope())
            {
                IndustrialSector newIndustrialSector = IndustrialSector.NewObject();

                Assert.That(
                    () => subTransaction.Commit(),
                    Throws.TypeOf <MandatoryRelationNotSetException>().With.Message.EqualTo(
                        string.Format(
                            "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies' of domain object '{0}' contains no items.",
                            newIndustrialSector.ID))
                    .And.Property <MandatoryRelationNotSetException> (ex => ex.PropertyName).EqualTo(
                        "Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies")
                    .And.Property <MandatoryRelationNotSetException> (ex => ex.DomainObject).SameAs(newIndustrialSector));
            }
        }
        public void RollbackForNewObjectWithRelations()
        {
            Order    newOrder   = Order.NewObject();
            ObjectID newOrderID = newOrder.ID;

            Order       order1       = DomainObjectIDs.Order1.GetObject <Order> ();
            OrderTicket orderTicket1 = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> ();
            Customer    customer     = DomainObjectIDs.Customer1.GetObject <Customer> ();
            OrderItem   orderItem1   = DomainObjectIDs.OrderItem1.GetObject <OrderItem>();

            newOrder.OrderTicket = orderTicket1;
            customer.Orders.Add(newOrder);
            orderItem1.Order = newOrder;

            TestableClientTransaction.Rollback();

            Assert.That(order1.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(order1.OrderTicket, Is.SameAs(orderTicket1));
            Assert.That(customer.Orders.Contains(newOrderID), Is.False);
            Assert.That(orderItem1.Order, Is.SameAs(order1));
        }
Ejemplo n.º 17
0
        public void NotInvalidAtAll()
        {
            var notInvalidObject = DomainObjectIDs.Order1.GetObject <Order> ();

            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            using (subTransaction.EnterDiscardingScope())
            {
                CheckStateIsNotInvalid(notInvalidObject, TestableClientTransaction, StateType.Unchanged);
                CheckStateIsNotInvalid(notInvalidObject, subTransaction, StateType.NotLoadedYet);

                Assert.That(
                    () => ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, notInvalidObject.ID),
                    Throws.InvalidOperationException.With.Message.EqualTo(
                        "Cannot resurrect object '" + notInvalidObject.ID + "' because it is not invalid within the whole transaction hierarchy. "
                        + "In transaction '" + subTransaction + "', the object has state 'NotLoadedYet'."));

                var result = ResurrectionService.TryResurrectInvalidObject(TestableClientTransaction, notInvalidObject.ID);
                Assert.That(result, Is.False);
            }
        }
Ejemplo n.º 18
0
        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 override void SetUp()
        {
            base.SetUp();

            _folder1 = Folder.NewObject();

            _fileSystemItem1 = FileSystemItem.NewObject();
            _fileSystemItem2 = FileSystemItem.NewObject();
            _fileSystemItem3 = FileSystemItem.NewObject();

            _folder1.FileSystemItems.Add(_fileSystemItem1);
            _folder1.FileSystemItems.Add(_fileSystemItem2);

            TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope();

            _folder1.FileSystemItems.EnsureDataComplete();
            _collectionEndPoint = (CollectionEndPoint)GetEndPoint <StateUpdateRaisingCollectionEndPointDecorator> (RelationEndPointID.Resolve(_folder1, o => o.FileSystemItems)).InnerEndPoint;

            _fileSystemItem1EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem1, oi => oi.ParentFolder));
            _fileSystemItem2EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem2, oi => oi.ParentFolder));
            _fileSystemItem3EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem3, oi => oi.ParentFolder));
        }
        public void GetCollectionWithNullValues()
        {
            var query = QueryFactory.CreateCollectionQuery(
                "test",
                DomainObjectIDs.Computer1.ClassDefinition.StorageEntityDefinition.StorageProviderDefinition,
                "SELECT [Employee].* FROM [Computer] LEFT OUTER JOIN [Employee] ON [Computer].[EmployeeID] = [Employee].[ID] "
                + "WHERE [Computer].[ID] IN (@1, @2, @3) "
                + "ORDER BY [Computer].[ID] asc",
                new QueryParameterCollection(),
                typeof(DomainObjectCollection));

            query.Parameters.Add("@1", DomainObjectIDs.Computer5); // no employee
            query.Parameters.Add("@3", DomainObjectIDs.Computer4); // no employee
            query.Parameters.Add("@2", DomainObjectIDs.Computer1); // employee 3

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                var result = ClientTransaction.Current.QueryManager.GetCollection(query);
                Assert.That(result.ContainsNulls(), Is.True);
                Assert.That(result.ToArray(), Is.EqualTo(new[] { null, null, DomainObjectIDs.Employee3.GetObject <Employee> () }));
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            _parentTransaction = new TestableClientTransaction();
            _parentInvalidDomainObjectManagerStub  = MockRepository.GenerateStub <IInvalidDomainObjectManager> ();
            _parentEnlistedDomainObjectManagerStub = MockRepository.GenerateStub <IEnlistedDomainObjectManager> ();
            _parentTransactionHierarchyManagerStub = MockRepository.GenerateStub <ITransactionHierarchyManager> ();
            _parentTransactionHierarchyManagerStub
            .Stub(stub => stub.TransactionHierarchy)
            .Return(MockRepository.GenerateStub <IClientTransactionHierarchy>());
            _parentEventSink = MockRepository.GenerateStub <IClientTransactionEventSink>();

            _factory = SubClientTransactionComponentFactory.Create(
                _parentTransaction,
                _parentInvalidDomainObjectManagerStub,
                _parentEnlistedDomainObjectManagerStub,
                _parentTransactionHierarchyManagerStub,
                _parentEventSink);

            _fakeConstructedTransaction = new TestableClientTransaction();
        }
        public void GetObjects_LoadedObjects_Events()
        {
            DomainObjectIDs.Order1.GetObject <Order> ();
            DomainObjectIDs.Order3.GetObject <Order> ();
            DomainObjectIDs.OrderItem1.GetObject <OrderItem>();

            _eventReceiver.Clear();

            var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> ();

            TestableClientTransaction.AddListener(listenerMock);

            LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, 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 GetObjects_UnloadedObjects_Events()
        {
            var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> ();

            TestableClientTransaction.AddListener(listenerMock);

            DomainObject[] objects = LifetimeService.GetObjects <DomainObject> (
                TestableClientTransaction,
                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(TestableClientTransaction),
                                             Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 })));

            listenerMock.AssertWasCalled(mock => mock.ObjectsLoaded(
                                             Arg.Is(TestableClientTransaction),
                                             Arg <ReadOnlyCollection <DomainObject> > .List.Equal(objects)));
        }
        public void PropertyValueChangedAreNotPropagatedToParent()
        {
            Order newChangedOrder = Order.NewObject();

            newChangedOrder.OrderNumber = 4711;

            Order loadedChangedOrder = DomainObjectIDs.Order3.GetObject <Order> ();

            loadedChangedOrder.OrderNumber = 13;

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                newChangedOrder.OrderNumber    = 17;
                loadedChangedOrder.OrderNumber = 4;

                using (TestableClientTransaction.EnterNonDiscardingScope())
                {
                    Assert.That(newChangedOrder.OrderNumber, Is.EqualTo(4711));
                    Assert.That(loadedChangedOrder.OrderNumber, Is.EqualTo(13));
                }
            }
        }
        public void DeleteMultipleObjectsAndCommit()
        {
            SetDatabaseModifyable();

            _location.Delete();
            _oldClient.Delete();
            _newClient.Delete();

            Client client3 = DomainObjectIDs.Client3.GetObject <Client> ();

            client3.Delete();

            Location location2 = DomainObjectIDs.Location2.GetObject <Location>();

            location2.Delete();

            Location location3 = DomainObjectIDs.Location3.GetObject <Location>();

            location3.Delete();

            TestableClientTransaction.Commit();
        }
Ejemplo n.º 26
0
        public void EagerFetching_UsesRelationDataFromParent_InsteadOfFetching()
        {
            // Load - and change - relation data prior to executing the query
            var customer = DomainObjectIDs.Customer1.GetObject <Customer>();

            Assert.That(
                customer.Orders,
                Is.EquivalentTo(new[] { DomainObjectIDs.Order1.GetObject <Order>(), DomainObjectIDs.Order2.GetObject <Order>() }));

            var customersQuery = QueryFactory.CreateCollectionQuery(
                "test",
                TestDomainStorageProviderDefinition,
                "SELECT * FROM [Company] WHERE ID = '" + DomainObjectIDs.Customer1.Value + "'",
                new QueryParameterCollection(),
                typeof(DomainObjectCollection));

            var relationEndPointDefinition = GetEndPointDefinition(typeof(Customer), "Orders");

            // This will yield different orders (none) than the actual relation query above - simulating the database has changed in between
            var orderItemsFetchQuery = QueryFactory.CreateCollectionQuery(
                "test fetch",
                TestDomainStorageProviderDefinition,
                "SELECT NULL WHERE 1 = 0",
                new QueryParameterCollection(),
                typeof(DomainObjectCollection));

            customersQuery.EagerFetchQueries.Add(relationEndPointDefinition, orderItemsFetchQuery);

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                // This executes the fetch query, but should discard the result (since the relation data already exists in the parent transaction)
                ClientTransaction.Current.QueryManager.GetCollection(customersQuery);

                Assert.That(
                    customer.Orders,
                    Is.EquivalentTo(new[] { DomainObjectIDs.Order1.GetObject <Order>(), DomainObjectIDs.Order2.GetObject <Order>() }));
            }
        }
        public void UnloadVirtualEndPointAndItemData_AppliedToParentTransaction_UnloadsFromWholeHierarchy()
        {
            var order = DomainObjectIDs.Order1.GetObject <Order> ();
            var parentOrderItemsEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order.OrderItems);

            EnsureEndPointLoadedAndComplete(parentOrderItemsEndPoint.ID);

            var orderItem1 = parentOrderItemsEndPoint.Collection[0];

            var subTransaction        = TestableClientTransaction.CreateSubTransaction();
            var subOrderItemsEndPoint = ClientTransactionTestHelper.GetDataManager(subTransaction).GetRelationEndPointWithLazyLoad(
                parentOrderItemsEndPoint.ID);

            EnsureEndPointLoadedAndComplete(ClientTransactionTestHelper.GetDataManager(subTransaction), subOrderItemsEndPoint.ID);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, parentOrderItemsEndPoint.ID);

            Assert.That(subOrderItemsEndPoint.IsDataComplete, Is.False);
            Assert.That(parentOrderItemsEndPoint.IsDataComplete, Is.False);

            Assert.That(orderItem1.TransactionContext[subTransaction].State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(orderItem1.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.NotLoadedYet));
        }
Ejemplo n.º 28
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));
        }
Ejemplo n.º 29
0
        public void Events_EmptyTransaction()
        {
            var mockRepository = new MockRepository();
            // Actual events are more comprehensive, since all opposite objects are also unloaded. We only test for some of them, so use a dynamic mock.
            var clientTransactionListener = mockRepository.DynamicMock <IClientTransactionListener> ();

            mockRepository.ReplayAll();

            TestableClientTransaction.AddListener(clientTransactionListener);
            try
            {
                UnloadService.UnloadAll(TestableClientTransaction);
            }
            finally
            {
                TestableClientTransaction.RemoveListener(clientTransactionListener);
            }

            clientTransactionListener.AssertWasNotCalled(
                mock => mock.ObjectsUnloading(Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything));
            clientTransactionListener.AssertWasNotCalled(
                mock => mock.ObjectsUnloaded(Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything));
        }
        public void UnloadUnsynchronizedFK_LeavesNullCompleteVirtualObjectEndPoint()
        {
            SetDatabaseModifyable();

            var employee          = DomainObjectIDs.Employee1.GetObject <Employee> ();
            var virtualEndPointID = RelationEndPointID.Resolve(employee, e => e.Computer);

            TestableClientTransaction.EnsureDataComplete(virtualEndPointID);
            Assert.That(employee.Computer, Is.Null);

            var unsynchronizedComputerID =
                RelationInconcsistenciesTestHelper.CreateObjectAndSetRelationInOtherTransaction <Computer, Employee> (
                    employee.ID,
                    (c, e) => c.Employee = e);
            var unsynchronizedComputer = unsynchronizedComputerID.GetObject <Computer> ();

            Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null);
            Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True);

            UnloadService.UnloadData(TestableClientTransaction, unsynchronizedComputer.ID);
            Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null);
            Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True);
        }