コード例 #1
0
        public void ResurrectInvalidObject()
        {
            Assert.That(TestableClientTransaction.IsInvalid(_invalidObject.ID), Is.True);

            ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, _invalidObject.ID);

            Assert.That(TestableClientTransaction.IsInvalid(_invalidObject.ID), Is.False);
        }
コード例 #2
0
        public void DiscardedNewObject()
        {
            var newObject = Order.NewObject();

            newObject.Delete();

            CheckStateIsInvalid(newObject, TestableClientTransaction);

            ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, newObject.ID);

            CheckStateIsNotInvalid(newObject, TestableClientTransaction, StateType.NotLoadedYet);
        }
コード例 #3
0
        public void UnloadDataInReadOnlyMiddleTransaction_IsAllowed()
        {
            CheckState(ReadOnlyRootTransaction, _invalidOrder, StateType.Invalid);
            CheckState(ReadOnlyMiddleTransaction, _invalidOrder, StateType.Invalid);
            CheckState(WriteableSubTransaction, _invalidOrder, StateType.Invalid);

            ResurrectionService.ResurrectInvalidObject(ReadOnlyMiddleTransaction, _invalidOrder.ID);

            CheckState(ReadOnlyRootTransaction, _invalidOrder, StateType.NotLoadedYet);
            CheckState(ReadOnlyMiddleTransaction, _invalidOrder, StateType.NotLoadedYet);
            CheckState(WriteableSubTransaction, _invalidOrder, StateType.NotLoadedYet);
        }
コード例 #4
0
        public void NotFoundObject()
        {
            var notFoundID     = new ObjectID(typeof(Order), Guid.NewGuid());
            var notFoundObject = LifetimeService.GetObjectReference(TestableClientTransaction, notFoundID);

            notFoundObject.TryEnsureDataAvailable();

            CheckStateIsInvalid(notFoundObject, TestableClientTransaction);

            ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, notFoundID);

            CheckStateIsNotInvalid(notFoundObject, TestableClientTransaction, StateType.NotLoadedYet);
        }
コード例 #5
0
        public void DiscardedDeletedObject()
        {
            SetDatabaseModifyable();

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

            deletedObject.Delete();
            TestableClientTransaction.Commit();

            CheckStateIsInvalid(deletedObject, TestableClientTransaction);

            ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, deletedObject.ID);

            CheckStateIsNotInvalid(deletedObject, TestableClientTransaction, StateType.NotLoadedYet);
        }
コード例 #6
0
        public void InvalidObject()
        {
            var domainObject = ClassWithAllDataTypes.NewObject();

            domainObject.Delete();
            Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid));

            Assert.That(() => domainObject.RegisterForCommit(), Throws.TypeOf <ObjectInvalidException> ());

            Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid));

            ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, domainObject.ID);

            Assert.That(domainObject.State, Is.EqualTo(StateType.NotLoadedYet));
        }
コード例 #7
0
        public void ResurrectInvalidObject_Hierarchy()
        {
            var subTransaction = TestableClientTransaction.CreateSubTransaction();

            using (subTransaction.EnterDiscardingScope())
            {
                Assert.That(TestableClientTransaction.IsInvalid(_invalidObject.ID), Is.True);
                Assert.That(subTransaction.IsInvalid(_invalidObject.ID), Is.True);

                ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, _invalidObject.ID);

                Assert.That(TestableClientTransaction.IsInvalid(_invalidObject.ID), Is.False);
                Assert.That(subTransaction.IsInvalid(_invalidObject.ID), Is.False);
            }
        }
コード例 #8
0
        public void ResurrectObject_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);

                ResurrectionService.ResurrectInvalidObject(subTransaction, notFoundID);

                CheckStateIsNotInvalid(notFoundObject, TestableClientTransaction, StateType.NotLoadedYet);
                CheckStateIsNotInvalid(notFoundObject, subTransaction, StateType.NotLoadedYet);
            }
        }
コード例 #9
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);
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        private DataContainer GetTargetDataContainer(TransportItem transportItem, Dictionary <ObjectID, DomainObject> existingObjects, ClientTransaction bindingTargetTransaction)
        {
            DomainObject existingObject;

            if (existingObjects.TryGetValue(transportItem.ID, out existingObject))
            {
                return(bindingTargetTransaction.DataManager.GetDataContainerWithLazyLoad(existingObject.ID, throwOnNotFound: true));
            }
            else
            {
                var id = transportItem.ID;

                var instance = bindingTargetTransaction.GetInvalidObjectReference(id);
                ResurrectionService.ResurrectInvalidObject(bindingTargetTransaction, id);

                var newDataContainer = DataContainer.CreateNew(id);
                newDataContainer.SetDomainObject(instance);
                bindingTargetTransaction.DataManager.RegisterDataContainer(newDataContainer);

                return(newDataContainer);
            }
        }