I am looking for ways of making the following more concise.
public class MyTests
{
IPresenter presenter;
[SetUp]
public void SetUp()
{
presenter = MockRepository.GenerateStub<IPresenter>();
}
...
}
In particular specifying the type again when creating the mock seems redundant. For example I can write it this way and use reflection to get the type and create the stub automatically:
public class MyTests
{
IPresenter presenter;
[SetUp]
public void SetUp()
{
Stub(x => x.presenter);
}
void Stub(Expression<Func<MyTests, object>> expression)
{
...
}
}
This would work but the compiler can no longer detect that presenter is assigned and starts issuing warnings. This also makes ReSharper very unhappy.
Can anyone suggest a better approach?