public void Test_WithIncompatibleVariables() { var object1 = new object(); var object2 = new object(); var invalidOperationException = new InvalidOperationException("Oh nos!"); TransactionMock.BackToRecord(); TransactionFactoryMock.BackToRecord(); TransactionMock.Stub(mock => mock.Release()); TransactionFactoryMock.Stub(mock => mock.Create()).Return(_newTransactionMock); ExecutionContextMock.Stub(mock => mock.GetVariables()).Return(new[] { object1, object2 }); _newTransactionMock .Stub(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))) .Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => _strategy.Reset(), Throws .TypeOf <WxeException>() .With.Message.EqualTo( "One or more of the variables of the WxeFunction are incompatible with the new transaction after the Reset. Oh nos! " + "(To avoid this exception, clear the Variables collection from incompatible objects before calling Reset and repopulate it " + "afterwards.)") .And.InnerException.SameAs(invalidOperationException)); Assert.That(_strategy.Scope, Is.Null); Assert.That(_strategy.Transaction, Is.SameAs(_newTransactionMock)); }
public override void SetUp() { base.SetUp(); ExecutionContextMock.BackToRecord(); ExecutionContextMock.Stub(stub => stub.GetInParameters()).Return(new object[0]).Repeat.Any(); ExecutionContextMock.Replay(); TransactionMock.BackToRecord(); TransactionMock.Stub(stub => stub.EnsureCompatibility(Arg <IEnumerable> .Is.NotNull)); TransactionMock.Replay(); _strategy = MockRepository.PartialMock <ScopedTransactionStrategyBase> ( true, (Func <ITransaction>)(() => TransactionMock), OuterTransactionStrategyMock, ExecutionContextMock); _strategy.Replay(); ExecutionContextMock.BackToRecord(); TransactionMock.BackToRecord(); }
public void Test_WithIncompatibleInParameters() { var object1 = new object(); var invalidOperationException = new InvalidOperationException("Objects no good!"); ExecutionContextMock.Stub(mock => mock.GetInParameters()).Return(new[] { object1 }); TransactionMock .Stub(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1 }))) .Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => new RootTransactionStrategy(false, () => TransactionMock, NullTransactionStrategy.Null, ExecutionContextMock), Throws .TypeOf <WxeException>() .With.Message.EqualTo( "One or more of the input parameters passed to the WxeFunction are incompatible with the function's transaction. Objects no good!") .And.InnerException.SameAs(invalidOperationException)); }