public void GetDataManager()
        {
            var clientTransaction = new TestableClientTransaction();
            var dataManager       = DataManagementService.GetDataManager(clientTransaction);

            Assert.That(dataManager, Is.SameAs(clientTransaction.DataManager));
        }
Esempio n. 2
0
        protected DataContainer GetDataContainer(DomainObject domainObject)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);

            return(DataManagementService.GetDataManager(ClientTransaction.Current)
                   .GetDataContainerWithLazyLoad(domainObject.ID, true));
        }
        public void UnloadAll_Transactions()
        {
            TestableClientTransaction.EnsureDataAvailable(DomainObjectIDs.Order1);
            EnsureEndPointLoadedAndComplete(_collectionEndPointID);
            Assert.That(TestableClientTransaction.DataManager.DataContainers[DomainObjectIDs.Order1], Is.Not.Null);
            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(_collectionEndPointID), Is.Not.Null);

            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                var middleTransaction = ClientTransaction.Current;
                middleTransaction.EnsureDataAvailable(DomainObjectIDs.Order3);
                Assert.That(DataManagementService.GetDataManager(middleTransaction).DataContainers[DomainObjectIDs.Order3], Is.Not.Null);

                using (middleTransaction.CreateSubTransaction().EnterDiscardingScope())
                {
                    ClientTransaction.Current.EnsureDataAvailable(DomainObjectIDs.Order4);
                    Assert.That(DataManagementService.GetDataManager(ClientTransaction.Current).DataContainers[DomainObjectIDs.Order4], Is.Not.Null);

                    UnloadService.UnloadAll(middleTransaction);

                    Assert.That(DataManagementService.GetDataManager(ClientTransaction.Current).DataContainers[DomainObjectIDs.Order4], Is.Null);
                    Assert.That(DataManagementService.GetDataManager(middleTransaction).DataContainers[DomainObjectIDs.Order3], Is.Null);
                    Assert.That(TestableClientTransaction.DataManager.DataContainers[DomainObjectIDs.Order1], Is.Null);
                }
            }
        }
Esempio n. 4
0
        public void GetState_Invalidated_AfterMarkInvalid()
        {
            var stateBeforeChange = _cachingListener.GetState(_notYetLoadedOrder.ID);

            _transaction.ExecuteInScope(() => DataManagementService.GetDataManager(_transaction).MarkInvalid(_notYetLoadedOrder));
            var stateAfterChange = _cachingListener.GetState(_notYetLoadedOrder.ID);

            Assert.That(stateBeforeChange, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(stateAfterChange, Is.EqualTo(StateType.Invalid));
        }
Esempio n. 5
0
        protected void CheckEndPointExists(RelationEndPointID endPointID, bool shouldEndPointExist)
        {
            ArgumentUtility.CheckNotNull("endPointID", endPointID);

            var endPoint = DataManagementService.GetDataManager(ClientTransaction.Current).GetRelationEndPointWithoutLoading(endPointID);

            if (shouldEndPointExist)
            {
                Assert.That(endPoint, Is.Not.Null, "End point '{0}' does not exist.", endPointID);
            }
            else
            {
                Assert.That(endPoint, Is.Null, "End point '{0}' should not exist.", endPointID);
            }
        }
Esempio n. 6
0
        protected void CheckDataContainerExists(DomainObject domainObject, bool dataContainerShouldExist)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);

            var dataContainer = DataManagementService.GetDataManager(ClientTransaction.Current).DataContainers[domainObject.ID];

            if (dataContainerShouldExist)
            {
                Assert.That(dataContainer, Is.Not.Null, "Data container '{0}' does not exist.", domainObject.ID);
            }
            else
            {
                Assert.That(dataContainer, Is.Null, "Data container '{0}' should not exist.", domainObject.ID);
            }
        }
Esempio n. 7
0
        private static bool UsePersistentProperty(DomainObject domainObject, PropertyInfo property)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);
            ArgumentUtility.CheckNotNull("property", property);

            if (!ReflectionUtility.IsRelationType(property.PropertyType))
            {
                return(true);
            }

            var dataManager = DataManagementService.GetDataManager(domainObject.DefaultTransactionContext.ClientTransaction);
            var endPointID  = RelationEndPointID.Create(domainObject.ID, property.DeclaringType, property.Name);
            var endPoint    = dataManager.GetRelationEndPointWithLazyLoad(endPointID);

            return(endPoint.IsDataComplete);
        }
Esempio n. 8
0
        public void DataContainerMapUnregistering_IgnoresNonNewObjects()
        {
            var middleTopTransaction = CreateSubTransactionAndClearListeners(_rootTransaction);

            var domainObject  = middleTopTransaction.ExecuteInScope(() => DomainObjectIDs.Order1.GetObject <Order> ());
            var dataContainer = DataManagementService.GetDataManager(middleTopTransaction).GetDataContainerWithoutLoading(domainObject.ID);

            Assert.That(dataContainer, Is.Not.Null);

            var middleBottomTransaction = CreateSubTransactionAndClearListeners(middleTopTransaction);
            var subTransaction          = CreateSubTransactionAndClearListeners(middleBottomTransaction);

            _listener.DataContainerMapUnregistering(middleTopTransaction, dataContainer);

            Assert.That(middleBottomTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False);
            Assert.That(subTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False);
        }
Esempio n. 9
0
        protected void CheckVirtualEndPointExistsAndComplete(RelationEndPointID endPointID, bool shouldEndPointExist, bool shouldDataBeComplete)
        {
            ArgumentUtility.CheckNotNull("endPointID", endPointID);
            CheckEndPointExists(endPointID, shouldEndPointExist);

            if (shouldEndPointExist)
            {
                var endPoint = DataManagementService.GetDataManager(ClientTransaction.Current).GetRelationEndPointWithoutLoading(endPointID);
                if (shouldDataBeComplete)
                {
                    Assert.That(endPoint.IsDataComplete, Is.True, "End point '{0}' should have complete data.", endPoint.ID);
                }
                else
                {
                    Assert.That(endPoint.IsDataComplete, Is.False, "End point '{0}' should not have complete data.", endPoint.ID);
                }
            }
        }
Esempio n. 10
0
        public void DataContainerMapUnregistering_MarksNewObjectsInvalidInSubtransactions()
        {
            var middleTopTransaction = CreateSubTransactionAndClearListeners(_rootTransaction);

            var domainObject  = middleTopTransaction.ExecuteInScope(() => Order.NewObject());
            var dataContainer = DataManagementService.GetDataManager(middleTopTransaction).GetDataContainerWithoutLoading(domainObject.ID);

            Assert.That(dataContainer, Is.Not.Null);

            var middleBottomTransaction = CreateSubTransactionAndClearListeners(middleTopTransaction);
            var subTransaction          = CreateSubTransactionAndClearListeners(middleBottomTransaction);

            _listener.DataContainerMapUnregistering(middleTopTransaction, dataContainer);

            Assert.That(middleBottomTransaction.IsInvalid(domainObject.ID), Is.True);
            Assert.That(ClientTransactionTestHelper.CallGetInvalidObjectReference(middleBottomTransaction, domainObject.ID), Is.SameAs(domainObject));
            Assert.That(subTransaction.IsInvalid(domainObject.ID), Is.True);
            Assert.That(ClientTransactionTestHelper.CallGetInvalidObjectReference(subTransaction, domainObject.ID), Is.SameAs(domainObject));
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
 public static IDataManager GetIDataManager(ClientTransaction clientTransaction)
 {
     return(DataManagementService.GetDataManager(clientTransaction));
 }
Esempio n. 13
0
 private void CheckTransactionIsEmpty(ClientTransaction clientTransaction)
 {
     Assert.That(DataManagementService.GetDataManager(clientTransaction).DataContainers, Is.Empty);
     Assert.That(DataManagementService.GetDataManager(clientTransaction).RelationEndPoints, Is.Empty);
 }