Glen
unread,Sep 1, 2010, 6:30:31 AM9/1/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.