I am using Test Driven Development to develop a simple application using Xamarin Studio on Mac OS X. I'm using NUnit as the test harness and FakeItEasy for mocking. I've developed an object that fires an event, and I want to test that another object response to that event, however it seems that responding object never receives any events that are fires in the test.
The following code illustrates the problem:
using System;
using NUnit.Framework;
using FakeItEasy;
namespace EventTest
{
public class EventProvider
{
public delegate void EventDelegate(object sender, EventArgs arguments);
public EventDelegate Event;
}
class EventResponder
{
public EventResponder(EventProvider provider)
{
provider.Event += (sender, arguments) => ++EventCount;
}
public uint EventCount { get; private set; }
}
[TestFixture]
public class EventResponderTest
{
[Test]
public void ResponseToFiredEvent()
{
var eventProvider = A.Fake<EventProvider>();
EventResponder responder = new EventResponder(eventProvider);
eventProvider.Event += Raise.WithEmpty().Now;
eventProvider.Event += Raise.WithEmpty().Now;
eventProvider.Event += Raise.WithEmpty().Now;
Assert.AreEqual(3, responder.EventCount);
}
}
}
The test fails because EventCount is 0. What does it take to make this test pass?