0

We mock an interface which has an event on it like so:

public interface IThing<TKey, TValue>
{
    event EventHandler<Message<TKey, TValue>> OnMessage;
}

Using NSubstitue we make a mock of the interface and try to raise the event using NSubstitute guidelines:

var mockThing = Substitute.For<IThing>();

mockThing.OnMessage += Raise.EventWith(???)

Despite many attempts, we can't get that line to compile - is it just a case of placing the generic types and arguments in the correct position?

The actual OnMessage() function called will look like this:

private void OnMessage(object sender, Message<string, string> message)
FBryant87
  • 4,273
  • 2
  • 44
  • 72
  • This seems to be a dublicate of the question https://stackoverflow.com/questions/51930227/how-to-raise-an-event-with-nsubstitute-with-eventhandlert – lars k. Aug 21 '18 at 15:14

1 Answers1

2

It should be something like

mockThing.OnMessage += Raise.Event<EventHandler<Message<string, string>>>(this, new Message<string, string>("yes", "what"))
lars k.
  • 562
  • 4
  • 18