Nmock2 and Event Expectations
- by Kildareflare
Im in the process of writing a test for a small application that follows the MVP pattern.
Technically, I know I should have written the test before the code, but I needed to knock up a demo app quick smart and so im now going back to the test before moving on to the real development.
In short I am attempting to test the presenter, however I cannot even get an empty test to run due to an Internal.ExpectationException.
The exception is raised on a unexpected invocation of an event assignation.
Here is the presenter class,
public LBCPresenter(IView view, IModel model)
{
m_model = model;
m_model.BatteryModifiedEvent += new EventHandler(m_model_BatteryModifiedEvent);
}
Model Interface
public interface IModel
{
event EventHandler BatteryModifiedEvent;
}
And here is the test class, I can't see what im missing, ive told NMock to expect the event...
[TestFixture]
public class MVP_PresenterTester
{
private Mockery mocks;
private IView _mockView;
private IViewObserver _Presenter;
private IModel _mockModel;
[SetUp]
public void SetUp()
{
mocks = new Mockery();
_mockView = mocks.NewMock<IView>();
_mockModel = mocks.NewMock<IModel>();
_Presenter = new LBCPresenter(_mockView, _mockModel);
}
[Test]
public void TestClosingFormWhenNotDirty()
{
Expect.Once.On(_mockModel).EventAdd("BatteryModifiedEvent", NMock2.Is.Anything);
//makes no difference if following line is commented out or not
//mocks.VerifyAllExpectationsHaveBeenMet();
}
}
Every time I run the test I get the same expectation Exception.
Any ideas?