VerifyAll not called when using Playback() when an exception is thrown

5 views
Skip to first unread message

Glen

unread,
Sep 1, 2010, 6:30:31 AM9/1/10
to Rhino.Mocks
Hi,
I noticed that a test I expected to fail due to unexcerised
expectations was actually succeeeding, I've reduced it down to a
synthetic repro...

[Test, ExpectedException(typeof(Exception), ExpectedMessage =
"expectedMessage")]
public void ExceptionTest()
{
var mocks = new MockRepository();
using (mocks.Record())
{
var disposable = mocks.StrictMock<IDisposable>();
Expect.Call(disposable.Dispose);
}
using (mocks.Playback())
{
throw new Exception("expectedMessage");
}
}


this appears to be due to a check in PlaybackModeChanger.Dispose

public void Dispose()
{
if (!
DisposableActionsHelper.ExceptionWasThrownAndDisposableActionShouldNotBeCalled())
{
this.m_repository.VerifyAll();
}
}

I'm assuming this supression is to do with avoiding the original
exception being eclipsed by the one from verify all?, however in the
ExpectedException test case it would be nice if the behaviour could be
controlled, e.g. a Playback(bool verifyAllOnException).

btw I have a current work around using an extension, something like...
public static void Playback(this MockRepository mockRepository,
Action action)
{
try
{
action();
mockRepository.VerifyAll();
}
catch (Exception e)
{
try
{
mockRepository.VerifyAll();
}
catch (Exception e2)
{
throw new InvalidOperationException(e2.Message, e);
}
}
}

Regards,
Glen.
Reply all
Reply to author
Forward
0 new messages