rickgaribay.net

Space shuttles aren't built for rocket scientists, they're built for astronauts. The goal isn't the ship, its the moon.
posts - 303, comments - 180, trackbacks - 35

My Links

News

Where's Rick?


AgileAlliance deliver:Agile 2019- 4/29
Desert Code Camp, PHX - 10/11
VS Live Austin, TX - 6/3
VS Live SF - 6/17


About Me
Hands on leader, developer, architect specializing in the design and delivery of distributed systems in lean, agile environments with an emphasis in continuous improvement across people, process and technology. Speaker and published author with 18 years' experience leading the delivery of large and/or complex, high-impact distributed solutions in Retail, Intelligent Transportation, and Gaming & Hospitality.

I'm currently a Principal Engineer at Amazon, within the North America Consumer organization leading our global listings strategy that enable bulk and non-bulk listing experiences for our WW Selling Partners via apps, devices and APIs.

Full bio

Note: All postings on this site are my own and don’t necessarily represent the views of my employer.



Check out my publications on Amazon Kindle!





Archives

Post Categories

Published Works

Rhino Mocks Ignore Arguments

I am writing some tests for a project I am working on called Green Fee Broker.

The first thing I am doing is mocking the business layer for the WCF service that I am writing so I can inject it into the service’s constructor and write the service while isolating dependencies:

MockRepository mockRepository = new MockRepository();

IBookingManager manager = mockRepository.DynamicMock<IBookingManager>();

Next, I set an expectation that CreateTeeTime is called on the manager mock, which is injected into the service constructor:

Expect.Call(manager.CreateTeeTime(course, DateTime.Now)).Return(teeTimeStub);

Finally, I ReplayAll to record the mock, call the service and assert that I am getting back a TeeTime object:

mockRepository.ReplayAll();

BookingService service = new BookingService(manager);

TeeTime teeTime = service.CreateTeeTime(course, DateTime.Now);

Assert.IsTrue(teeTime.ConfirmationNumber == "ABC123");

Unfortunately, there is a bug in the line of code that sets up the expectation. With Rhino Mocks, for an expected behavior to be a match, the parameters must be an exact match. Notice the second parameter uses DateTime.Now. This means that the expectation will have a different parameter than the actual call, even if it is just a few milleseconds of a difference. As a result, the assertion will fail because the return is null.

The solution is to add the IgnoreArguments method call on the expectation:

Expect.Call(manager.CreateTeeTime(course, DateTime.Now)).Return(teeTimeStub).IgnoreArguments();

The IgnoreArguments() call will ensure that the parameters are discarded completely in determining a match.

Now I am green, and good to go!

image

Print | posted on Friday, June 12, 2009 12:47 AM | Filed Under [ WCF .NET 3.5 TDD ]

Comments have been closed on this topic.

Powered by: