Tuesday, February 24, 2009

Presenter Tests 101

What to wrtite a test to make sure the prsenter load dats from a service/moeld/repository to the view?

IFooEditView view ;
IFooService service ;

public void MyTestInitialize()
view = MockRepository.GenerateMock<IFooEditView>();
service = MockRepository.GenerateMock<IFooService>();

public void MyTestCleanup()
//global assertion

public void CanInitialiseFooEditPresenter()
var id = 1;
var record = new Foo(id);
view.Expect(v => v.LoadRecord(record));
service.Expect(s => s.RetrieveFooRecord(id)).Return(record);
var pres = new FooEditPresenter(view, service);
//assert - mock verification in tear down

NB: I really should stop posting code by writing staight in to the blogger create post screen. just lazy...

No comments: