I have a method:
public class MyClass
{
public ILogger _logger;
public async void TestLogMethod(string msg)
{
await Task.Run(async ()=> await _logger.Log(msg));
}
}
And a testcase:
[Test]
public async Task TestLogMethod_LogMessage_Test()
{
var fakeLogger = A.Fake<ILogger>();
var testClass = new MyClass();
testClass._logger = fakeLogger;
testClass.TestLogMethod("Test Message");
A.CallTo(() => fakeLogger.Log(A<string>._)).MustHaveHappened();
}
MustHaveHappened Assert always fails saying
Assertion failed for the following call:
MyClass.TestLogMethod<System.Object>(<Ignored>)
Expected to find it at least once but no calls were made to the fake object.
It is clear that _logger.Log() is called, but why is Asserting always failing here ?