public void DiscardReadOnlyMiddleTransaction_IsAllowed() { Assert.That(ReadOnlyRootTransaction.IsDiscarded, Is.False); Assert.That(ReadOnlyMiddleTransaction.IsDiscarded, Is.False); Assert.That(WriteableSubTransaction.IsDiscarded, Is.False); var extensionMock = CreateAndAddExtensionMock(); using (extensionMock.GetMockRepository().Ordered()) { extensionMock .Expect(mock => mock.TransactionDiscard(ReadOnlyMiddleTransaction)) .WhenCalled(mi => CheckTransactionHierarchy()); extensionMock .Expect(mock => mock.TransactionDiscard(WriteableSubTransaction)) .WhenCalled(mi => CheckTransactionHierarchy()); } ReadOnlyMiddleTransaction.Discard(); Assert.That(ReadOnlyRootTransaction.IsDiscarded, Is.False); Assert.That(ReadOnlyMiddleTransaction.IsDiscarded, Is.True); Assert.That(WriteableSubTransaction.IsDiscarded, Is.True); Assert.That(ReadOnlyRootTransaction.SubTransaction, Is.Null); Assert.That(ReadOnlyRootTransaction.IsWriteable, Is.True); }
public void CreateSubTransactionInReadOnlyMiddleTransaction_IsForbidden() { Assert.That(ReadOnlyRootTransaction.SubTransaction, Is.SameAs(ReadOnlyMiddleTransaction)); Assert.That(ReadOnlyMiddleTransaction.SubTransaction, Is.SameAs(WriteableSubTransaction)); CheckForbidden(() => ReadOnlyMiddleTransaction.CreateSubTransaction(), "SubTransactionCreating"); Assert.That(ReadOnlyRootTransaction.SubTransaction, Is.SameAs(ReadOnlyMiddleTransaction)); Assert.That(ReadOnlyMiddleTransaction.SubTransaction, Is.SameAs(WriteableSubTransaction)); }
public void EnsureDataAvailableInReadOnlyMiddleTransaction_IsAllowed() { CheckDataNotLoaded(ReadOnlyRootTransaction, DomainObjectIDs.Order1); CheckDataNotLoaded(ReadOnlyMiddleTransaction, DomainObjectIDs.Order1); CheckDataNotLoaded(WriteableSubTransaction, DomainObjectIDs.Order1); ReadOnlyMiddleTransaction.EnsureDataAvailable(_order1.ID); CheckDataLoaded(ReadOnlyRootTransaction, _order1); CheckDataLoaded(ReadOnlyMiddleTransaction, _order1); CheckDataNotLoaded(WriteableSubTransaction, _order1); }
public void RollbackInReadOnlyMiddleTransaction_IsForbidden() { Assert.That(ReadOnlyRootTransaction.HasChanged(), Is.True); Assert.That(ReadOnlyMiddleTransaction.HasChanged(), Is.True); Assert.That(WriteableSubTransaction.HasChanged(), Is.True); CheckForbidden(() => ReadOnlyMiddleTransaction.Rollback(), "TransactionRollingBack"); Assert.That(ReadOnlyRootTransaction.HasChanged(), Is.True); Assert.That(ReadOnlyMiddleTransaction.HasChanged(), Is.True); Assert.That(WriteableSubTransaction.HasChanged(), Is.True); }
public void CommitInReadOnlyMiddleTransaction_IsForbidden() { Assert.That(ReadOnlyRootTransaction.HasChanged(), Is.True); Assert.That(ReadOnlyMiddleTransaction.HasChanged(), Is.True); Assert.That(WriteableSubTransaction.HasChanged(), Is.True); CheckForbidden(() => ReadOnlyMiddleTransaction.Commit(), "TransactionCommitting"); Assert.That(ReadOnlyRootTransaction.HasChanged(), Is.True); Assert.That(ReadOnlyMiddleTransaction.HasChanged(), Is.True); Assert.That(WriteableSubTransaction.HasChanged(), Is.True); }
public override void SetUp() { base.SetUp(); _listenerDynamicMock = MockRepository.GenerateMock <IClientTransactionListener> (); _extensionStrictMock = MockRepository.GenerateStrictMock <IClientTransactionExtension> (); _readOnlyRootTransaction = ClientTransaction.CreateRootTransaction(); ExecuteInReadOnlyRootTransaction(InitializeReadOnlyRootTransaction); _readOnlyMiddleTransaction = ReadOnlyRootTransaction.CreateSubTransaction(); ExecuteInReadOnlyMiddleTransaction(InitializeReadOnlyMiddleTransaction); _writeableSubTransaction = ReadOnlyMiddleTransaction.CreateSubTransaction(); ExecuteInWriteableSubTransaction(InitializeWriteableSubTransaction); }
public void OnLoaded_CannotCauseSameObjectToBeLoadedInSubTx_WhileItIsLoadedIntoParent_InitiatedFromSub() { using (_loadEventReceiverMock.GetMockRepository().Ordered()) { _loadEventReceiverMock .Expect(mock => mock.OnLoaded(_order)) .WhenCalled( mi => { Assert.That(ClientTransaction.Current, Is.SameAs(ReadOnlyRootTransaction)); Assert.That( () => ReadOnlyMiddleTransaction.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'.")); 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'.")); }); _loadEventReceiverMock .Expect(mock => mock.OnLoaded(_order)) .WhenCalled( mi => { Assert.That(ClientTransaction.Current, Is.SameAs(ReadOnlyMiddleTransaction)); 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'.")); }); _loadEventReceiverMock .Expect(mock => mock.OnLoaded(_order)) .WhenCalled(mi => Assert.That(ClientTransaction.Current, Is.SameAs(WriteableSubTransaction))); WriteableSubTransaction.EnsureDataAvailable(_order.ID); _loadEventReceiverMock.VerifyAllExpectations(); CheckState(ReadOnlyRootTransaction, _order, StateType.Unchanged); CheckState(ReadOnlyMiddleTransaction, _order, StateType.Unchanged); CheckState(WriteableSubTransaction, _order, StateType.Unchanged); } }
protected T ExecuteInReadOnlyMiddleTransaction <T> (Func <T> func) { return(ReadOnlyMiddleTransaction.ExecuteInScope(func)); }
protected void ExecuteInReadOnlyMiddleTransaction(Action action) { ReadOnlyMiddleTransaction.ExecuteInScope(action); }