I am trying to convert a helper method I wrote mocking ILogger
using Moq to FakeItEasy. The Log()
method mocked in the ILogger
requires 5 arguments.
Log(LogLevel, EventId, FormattedLogValues, Exception, Func<object, Exception, string>)
It appears that FakeItEasy has capped the number of arguments to 4. (From the docs):
// Pass up to 4 original call argument values into the method that creates the exception.
A.CallTo(()=>fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
.Invokes((DateTime when) => System.Console.Out.WriteLine("showing sweet sales for " + when))
.Returns(17);
Therefore when I write this code...
var logs = new List<string>();
var logger = A.Fake<ILogger<ElasticSearchRepository>>();
A.CallTo(() => logger.Log(A<LogLevel>._, A<EventId>._, A<FormattedLogValues>._, A<Exception>._, A<Func<object, Exception, string>>._))
.Invokes((LogLevel a, EventId b, FormattedLogValues x, Exception c, Func<object, Exception, string> d) => logs.Add(x.ToString()));
... I get the following error
Delegate 'Action<IFakeObjectCall>' does not take 5 arguments
Is there something I should be doing differently? It's hard to imagine anyone arbitrarily picking 4 as the max arguments that can be passed so I'm guessing there is a reason. Moq's Callback()
doesn't have the same limitations.