I am just starting here with mocking about, and I am trying something which I think should be quite simple.
I have a class that reads Google calendar data. First, it creates a CalendarService
object, then it calls Query
on that object, receives a EventFeed
and iterates on the Item collection of AtomEntryCollection
.
I want it all to be mocked, as I don't want my tests to send any web requests around.
I tried mocking it all with
var service = MockManager.Mock<CalendarService>();
var events = MockManager.MockAll<EventFeed>();
var entries = MockManager.MockAll<AtomEntryCollection>();
service.ExpectAndReturn("Query", events.MockedInstance);
events.ExpectGet("Entries", entries.MockedInstance);
entries.ExpectGetAlways("Count", 3);
but my test fails as soon as the object returned from the service.Query()
method is used. I understand that in the 5th line the entries.MockedInstance
was still null, so the ExpectAndReturn
recorded the null as the return value - so what am I supposed to do? How can I set the mocks to return valid mock objects, instead of nulls?
Note - I am writing a .NET 2.0 project, so I can't use the Isolator features (I think). Would that have helped me? Or maybe switching to Rhino or MOQ would make it all easier?