Delegates?

B

Berryl Hesh

I'm wondering if a delegate will help me solve how to reuse the unit test
fixture below (I only show one test of several here).

The parts that I want to vary in it are the IClosingWindowView &
IClosingWindowPresenter. Ideally I could call one method from a different
test fixture and run all related tests (ie,
_assertClosingBehavior(IClosingWindowView view, IClosingWindowPresenter
presenter).

The only way I can kind of do this now would be to make the test methods an
abstract class and override a property or method, but this would be pretty
fragile. I don't get delegates very well.

TIA - BH

------
[TestFixture]
public class ClosingViewPresenterTest
{
private static MockRepository _mocks;
private static IYesNoMessageAsker _mockYesNoAsker;
private static IClosingWindowView _mockView;
private IClosingWindowPresenter _presenter;

[SetUp]
public void SetUp() {
_mocks = new MockRepository();
_mockYesNoAsker = _mocks.CreateMock<IYesNoMessageAsker>();
_mockView = _mocks.DynamicMock<IClosingWindowView>();
}

[Test]
public void PresenterInjectsItselfIntoTheView() {
_mockView = _mocks.CreateMock<IClosingWindowView>();
using(_mocks.Record()) {
Expect.Call(() =>
_mockView.InitializeClosingWindowPresenter(_presenter)).IgnoreArguments();
}
using(_mocks.Playback()) {
_presenter = new ClosingWindowPresenter(_mockView, _mockYesNoAsker);
}
}
 
B

Berryl Hesh

The goal was/is to ""vary" the class by providing different instances that
implement the IClosingWindowView and IClosingWindowPresenter interfaces". I
managed to do that by turning the original test class into an abstract class
with protected fields and one abstract method. I was expecting the
combination of [TextFixture] attributes and field dependencies to be
"fragile" across projects, but that didn't turn out to be the case after I
refactored it sloowly.

Thanks for the response!

Berryl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top