I have a small class which has a small method which gets invoked when the event is raised.
public class DemoUI
{
public DemoUI(TestRunner runner)
{
runner.UserMessage += OnEventRunThis;
}
protected void OnEventRunThis(object sender, UserMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
Now in my test I create an object of type TestRunner
and execute Execute
method on it. This raises an event which is then intercepted and the OnEventRunThis
dutifully runs printing the message. But the Fake it easy reports the error that "No calls were made to the fake object".
var _sutTestRunner = new TestRunner();
var fakeDemoUI = A.Fake<DemoUI>(x => x.WithArgumentsForConstructor(() => new DemoUI(_sutTestRunner)));
_sutTestRunner.Execute();
A.CallTo(fakeDemoUI).Where(x => x.Method.Name == "OnEventRunThis").MustHaveHappened();
The method OnEventRunThis
is getting called because I see the output getting printed in the output window. So this in my limited understanding means that the call has been made to Fake object.
Or am I missing something? Or is there any other way out to do this?