1
我们使用MVP(监督控制器)用于带有3.5 SP1的ASP.NET WebForms。用RhinoMocks嘲笑视图
什么是首选的方式来检查视图属性的值,只有与RhinoMocks设置操作?
这里是我们至今:
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
我们应该使用预计或另一种方式,任何投入将是巨大的。
感谢
更新基于达林季米特洛夫的答复。
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
这是行不通的。我应该以这种方式进行测试还是有更好的方法?
感谢您的答复,这是有道理的。我根据你的帮助更新了我的问题。 – blu 2010-03-03 17:56:13