コード例 #1
0
        public void DeleteInReadOnlyRootTransaction_IsForbidden_Loaded()
        {
            CheckState(ReadOnlyRootTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);
            CheckState(ReadOnlyMiddleTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);
            CheckState(WriteableSubTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);

            CheckForbidden(() => ExecuteInReadOnlyRootTransaction(() => _loadedClassWithAllDataTypes.Delete()), "ObjectDeleting");

            CheckState(ReadOnlyRootTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);
            CheckState(ReadOnlyMiddleTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);
            CheckState(WriteableSubTransaction, _loadedClassWithAllDataTypes, StateType.Unchanged);
        }
コード例 #2
0
        public void InvalidStateType()
        {
            ClassWithAllDataTypes newObject = ClassWithAllDataTypes.NewObject();
            DataContainer         newObjectDataContainer    = newObject.InternalDataContainer;
            ClassWithAllDataTypes loadedObject              = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
            DataContainer         loadedObjectDataContainer = newObject.InternalDataContainer;

            Assert.That(newObject.IsInvalid, Is.False);
            Assert.That(newObject.State, Is.EqualTo(StateType.New));
            Assert.That(loadedObject.IsInvalid, Is.False);
            Assert.That(loadedObject.State, Is.EqualTo(StateType.Unchanged));

            newObject.Delete();

            Assert.That(newObject.IsInvalid, Is.True);
            Assert.That(newObject.State, Is.EqualTo(StateType.Invalid));
            Assert.That(newObjectDataContainer.IsDiscarded, Is.True);
            Assert.That(newObjectDataContainer.State, Is.EqualTo(StateType.Invalid));

            loadedObject.Delete();
            TestableClientTransaction.Commit();

            Assert.That(loadedObject.IsInvalid, Is.True);
            Assert.That(loadedObject.State, Is.EqualTo(StateType.Invalid));
            Assert.That(loadedObjectDataContainer.IsDiscarded, Is.True);
            Assert.That(loadedObjectDataContainer.State, Is.EqualTo(StateType.Invalid));
        }
コード例 #3
0
        public void IsInvalid()
        {
            Assert.That(_loadedClassWithAllDataTypesMixin.IsInvalid, Is.EqualTo(_loadedClassWithAllDataTypes.IsInvalid));
            Assert.That(_newClassWithAllDataTypesMixin.IsInvalid, Is.EqualTo(_newClassWithAllDataTypes.IsInvalid));

            _newClassWithAllDataTypes.Delete();

            Assert.That(_newClassWithAllDataTypesMixin.IsInvalid, Is.EqualTo(_newClassWithAllDataTypes.IsInvalid));
        }
コード例 #4
0
        public void State()
        {
            Assert.That(_loadedClassWithAllDataTypesMixin.State, Is.EqualTo(_loadedClassWithAllDataTypes.State));
            Assert.That(_newClassWithAllDataTypesMixin.State, Is.EqualTo(_newClassWithAllDataTypes.State));

            ++_loadedClassWithAllDataTypes.Int32Property;
            Assert.That(_loadedClassWithAllDataTypesMixin.State, Is.EqualTo(_loadedClassWithAllDataTypes.State));

            _loadedClassWithAllDataTypes.Delete();
            Assert.That(_loadedClassWithAllDataTypesMixin.State, Is.EqualTo(_loadedClassWithAllDataTypes.State));
        }
        public void CommitRootNewSubDeleted()
        {
            ClassWithAllDataTypes obj = GetNewUnchanged();

            Assert.That(obj.State, Is.EqualTo(StateType.New));
            using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope())
            {
                obj.Delete();
                Assert.That(obj.State, Is.EqualTo(StateType.Deleted));
                ClientTransactionScope.CurrentTransaction.Commit();
            }
            Assert.That(obj.State, Is.EqualTo(StateType.Invalid));
        }
コード例 #6
0
        public void SubCommit_OfDeletedObject_DoesNotRaiseDeletedEvent()
        {
            using (_subTransaction.EnterDiscardingScope())
            {
                ClassWithAllDataTypes domainObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();

                MockRepository repository = new MockRepository();

                IClientTransactionExtension extensionMock = repository.StrictMock <IClientTransactionExtension>();
                extensionMock.Stub(stub => stub.Key).Return("Mock");
                extensionMock.Replay();
                _subTransaction.Extensions.Add(extensionMock);
                try
                {
                    extensionMock.BackToRecord();

                    extensionMock.ObjectDeleting(_subTransaction, domainObject);
                    extensionMock.ObjectDeleted(_subTransaction, domainObject);

                    repository.ReplayAll();
                    domainObject.Delete();
                    repository.VerifyAll();

                    repository.BackToRecordAll();
                    extensionMock.Committing(null, null, null);
                    LastCall.IgnoreArguments();
                    extensionMock.CommitValidate(null, null);
                    LastCall.IgnoreArguments();
                    extensionMock.Committed(null, null);
                    LastCall.IgnoreArguments();
                    repository.ReplayAll();

                    _subTransaction.Commit();
                    repository.VerifyAll();
                }
                finally
                {
                    _subTransaction.Extensions.Remove("Mock");
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        public void FinishTransport_FilterCalledForEachChangedObject()
        {
            var transporter = new DomainObjectTransporter();

            transporter.Load(DomainObjectIDs.ClassWithAllDataTypes1);
            transporter.Load(DomainObjectIDs.ClassWithAllDataTypes2);
            transporter.Load(DomainObjectIDs.Order1);

            ModifyDatabase(
                delegate
            {
                ClassWithAllDataTypes c1 = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                ClassWithAllDataTypes c2 = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();
                c1.Delete();
                c2.Delete();
            });

            TransportedDomainObjects transportedObjects = Transport(transporter);

            var expectedObjects = new List <DomainObject>();

            using (transportedObjects.DataTransaction.EnterNonDiscardingScope())
            {
                expectedObjects.Add(DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ());
                expectedObjects.Add(DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ());
            }

            var filteredObjects = new List <DomainObject>();

            transportedObjects.FinishTransport(
                delegate(DomainObject domainObject)
            {
                filteredObjects.Add(domainObject);
                return(true);
            });
            Assert.That(filteredObjects, Is.EquivalentTo(expectedObjects));
        }