Woah, Nellie.NET!

From my simple mind to… mine…

Exception: "Previous method requires a return value or an exception to throw"

leave a comment »

I felt stupid on this one… :)

Rhino Mocks kept throwing: System.InvalidOperationException: Previous method ‘DateTimeService.GetNow();’ requires a return value or an exception to throw.

Well, after many hours staring at my code, it turns out that I simply had forgotten to put the state of the mock into replay mode.

So:

dateTimeService.Expect(x => x.GetNow()).Return(new DateTime(2008, 2, 2));
 

Becomes:

dateTimeService.Expect(x => x.GetNow()).Return(new DateTime(2008, 2, 2));
dateTimeService.Replay();
 

Or you can use:

mockRepositoryInstance.ReplayAll();

to set all your mock instances into playback mode.

About these ads

Written by Nelson

September 19, 2008 at 10:58 am

Posted in .NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: