1

I inject a stub generated with FakeItEasy to my class. At some point my class subscribes to dependency's event. I want to invoke this event afterwards as part of my test method but it does not seem to work:

var restApiManager = A.Fake<IRestApiManager>(); //IRestApiManager has Connected event
var target = new ViewModel(restApiManager);

target.Connect(); //some private method subscribes to RestApiManager.Connected

restApiManager.Connected(); //obviously not working

Is there a way to invoke an event from a stub?

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

1 Answers1

2

Event raising is covered in the Raising events topic in the FakeItEasy documentation.

You'll want to call something like this

restApiManager.Connected += Raise.With(arguments);

or some variant, depending on the arguments the event supplies to the listeners.

If you've defined the event using a custom delegate, then you will need to supply a typeparam:

restApiManager.Connected += Raise.With<CustomEventHandler>(arguments);
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111