Mocking View with RhinoMocks

Posted by blu on Stack Overflow See other posts from Stack Overflow or by blu
Published on 2010-03-03T16:31:26Z Indexed on 2010/04/10 16:03 UTC
Read the original article Hit count: 397

Filed under:
|
|
|

We are using MVP (Supervising Controller) for ASP.NET WebForms with 3.5 SP1.

What is the preferred way to check the value of a view property that only has the a set operation with RhinoMocks?

Here is what we have so far:

var service = MockRepository.GenerateStub<IFooService>();
// stub some data for the method used in OnLoad in the presenter

var view = MockRepository.GenerateMock<IFooView>();
var presenter = new FooPresenter(view, service);

view.Raise(v => v.Load += null, this, EventArgs.Empty);

Assert.IsTrue(view.Bars.Count == 10); // there is no get on Bars

Should we use Expects or another way, any input would be great.

Thanks

Update based on Darin Dimitrov's reply.

var bars = new List<Bar>() { new Bar() { BarId = 1 } };

var fooService = MockRepository.GenerateStub<IFooService>();

// this is called in OnLoad in the Presenter
fooService.Stub(x => x.GetBars()).Return(bars);

var view = MockRepository.GenerateMock<IFooView>();
var presenter = new FooPresenter(view, fooService);

view.Raise(v => v.Load += null, this, EventArgs.Empty);
view.AssertWasCalled(x => x.Bars = bars); // this does not pass

This doesn't work. Should I be testing it this way or is there a better way?

© Stack Overflow or respective owner

Related posts about rhino-mocks

Related posts about unit-testing