additionally you could rather than using a StrictMock (which I try to shy
away from) use a DynamicMock (GenerateMock()) and do
foo.AssertWasNotCalled().

>From an expresiveness standpoint, I think foo.AssertWasNotCalled would give
future readers of the test (yourself included) a better clue on what exactly
is going on.

On Thu, Feb 11, 2010 at 7:40 AM, Aaron Alexander <[email protected]>wrote:

> With some test frameworks you can assert that a specific exception
> type was thrown and (optionally) capture the exception so you can do
> further assertions on it.  This allows you to verify that a call threw
> an exception and then continue performing assertions (such as the
> VerifyAllExpectations() call) without needing to put try/catch/finally
> blocks in the test method.
>
> In MbUnit v3, you would change your test code to:
>
> var uut = new Container(foo);
> Assert.Throws<Exception>(() => uut.Open());
>
> uut.Close();
>
> foo.VerifyAllExpectations();
>
> I think that NUnit 2.5 has similar capabilities.  I'm not sure which
> other test frameworks have similar syntax available.
>
> On Feb 10, 6:42 pm, Kevinst <[email protected]> wrote:
> > Thank you guys. I think I will just live with it.
> >
> > I would have used that ExpectedException attribute but I have to call
> > mock.VerifyAllExpectations() after the exception was thrown to make
> > sure no Close was executed.. so I have to catch it I guess?
> > The Exception is a custom one.. I just didnt want to overload my
> > thread ;-)
> >
> > What would your new name suggestion be?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rhinomocks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rhinomocks?hl=en.
>
>


-- 
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to