Mocking a method that raises an event with Moq

_myProvider = new Mock<IMyProvider>();
_myProvider.Setup(m => m.StartReceivingData()).Callback(() =>
{
    var doc = XDocument.Load(string.Format(@"{0}\Feeds\myFeed.xml", Environment.CurrentDirectory));
    _myProvider.Raise(m => m.MyFeedReceived += null, this, new MyFeedModel(doc));
});

The second argument is the sender of the event, the third argument is the event argument.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s