public void Test_WithParentTransactionStrategy() { var strategy = CreateScopedTransactionStrategy(true, OuterTransactionStrategyMock); var expectedObjects = new[] { new object() }; InvokeOnExecutionPlay(strategy); using (MockRepository.Ordered()) { ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); TransactionMock.Expect(mock => mock.Commit()); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(expectedObjects); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(expectedObjects)); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); } MockRepository.ReplayAll(); strategy.OnExecutionStop(Context, ExecutionListenerStub); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_EnsureCompatibility_ThrowsBecauseOfIncompatibleOutParameters() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var invalidOperationException = new InvalidOperationException("Completely bad objects!"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => strategy.OnExecutionStop(Context, ExecutionListenerStub), Throws .TypeOf <WxeException> () .With.Message.EqualTo( "One or more of the output parameters returned from the WxeFunction are incompatible with the function's parent transaction. " + "Completely bad objects!") .And.InnerException.SameAs(invalidOperationException)); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }
public void Test_ReleaseThrows() { var strategy = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null); var innerException = new Exception("Release Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()).Throw(innerException); MockRepository.ReplayAll(); try { strategy.OnExecutionStop(Context, ExecutionListenerStub); Assert.Fail("Expected Exception"); } catch (WxeFatalExecutionException actualException) { Assert.That(actualException.InnerException, Is.SameAs(innerException)); } MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_WithScope() { var object1 = new object(); var object2 = new object(); InvokeOnExecutionPlay(_strategy); TransactionMock.BackToRecord(); TransactionFactoryMock.BackToRecord(); var newScopeMock = MockRepository.StrictMock <ITransactionScope>(); using (MockRepository.Ordered()) { ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); TransactionFactoryMock.Expect(mock => mock.Create()).Return(_newTransactionMock); _newTransactionMock.Expect(mock => mock.EnterScope()).Return(newScopeMock); ExecutionContextMock.Expect(mock => mock.GetVariables()).Return(new[] { object1, object2 }); _newTransactionMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))); } Assert.That(_strategy.Scope, Is.SameAs(ScopeMock)); MockRepository.ReplayAll(); _strategy.Reset(); MockRepository.VerifyAll(); Assert.That(_strategy.Scope, Is.SameAs(newScopeMock)); }
public void Test_WithNullValue() { var object1 = new object(); var object2 = new object(); using (MockRepository.Ordered()) { ExecutionContextMock.Expect(mock => mock.GetInParameters()).Return(new[] { object1, null, object2 }); TransactionMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))); } MockRepository.ReplayAll(); new RootTransactionStrategy(false, () => TransactionMock, NullTransactionStrategy.Null, ExecutionContextMock); MockRepository.VerifyAll(); }
public void Test_WithoutAutoCommit() { var strategy = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null); InvokeOnExecutionPlay(strategy); using (MockRepository.Ordered()) { ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); } MockRepository.ReplayAll(); strategy.OnExecutionStop(Context, ExecutionListenerStub); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_EnsureCompatibilityThrowsUnexpected_GetsBubbledOut() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var innerException = new ApplicationException("GetOutParameters Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(innerException); MockRepository.ReplayAll(); Assert.That( () => strategy.OnExecutionStop(Context, ExecutionListenerStub), Throws.Exception.SameAs(innerException)); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }
public void Test_GetOutParameterThrows() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var innerException = new ApplicationException("GetOutParameters Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Throw(innerException); MockRepository.ReplayAll(); try { strategy.OnExecutionStop(Context, ExecutionListenerStub); Assert.Fail("Expected Exception"); } catch (ApplicationException actualException) { Assert.That(actualException, Is.SameAs(innerException)); } MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }