I have been stuck on this for a day or two, I have recently started using RhinoMocks (v3.5)and I have setup a test. A stub web service that returns a List collection and a class that calls it, and a mock object with a property i expect to be set as a result of the call to the web service. My code is like this:
[Test]
public void Call_WebService_list_populated()
{
IData stService = MockRepository.GenerateStub<IData>();
IDefault mockView = MockRepository.GenerateMock<IDefault>();
DefaultPresenter presenter = new DefaultPresenter(mockView);
presenter.StService = stService;
mockView.Stub(x => x.RequestingUser).Return("test");
List<string> testList = new List<string> { new string() };
stService.Stub(x => x.GetList("test")).Return(testList);
presenter.LoadList();
Assert.AreEqual(testList,mockView.List);
}
In the LoadList function it just assigns the List property of mockView the list returned from the webservice. I can get the test to work using this line:
mockView.AssertWasCalled(a => a.StoryListing = testList);
but i expected that the mock object would hold state and i could check the property directly. Am i doing something wrong or is this just the way you have to use rhino mocks ie: the mock object cant hold state as when i do the assert.areequal nunit says the mockView.List property is null.