Rhino Mock Assert was called

Leave a comment

January 5, 2010 by temebele

I came across a unit test that I needed to verify that a method got called but didn’t really care about the parameter being passed except that it shouldn’t be null.
After researching a bit I was able to find how to do it with Rhinomocks.

repository.AssertWasCalled(k => k.SaveAndCommit<ProposalFlight>(Arg<ProposalFlight>.Matches(s => s != null)));

I only care that a non-null parameter of the type specified gets passed.

The repository was mocked as below.

Mocks = new MockRepository();
repository = MockRepository.GenerateMock<IRepository>();
And the method was stubbed as below:
repository.Stub(b => b.SaveAndCommit<ProposalFlight>(null)).IgnoreArguments();
Hopefully this information it will save few minutes for somebody.
Advertisements

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

%d bloggers like this: