Open kippermand opened 1 year ago
I think the problem might be the usage with the LogError itself.
The signature of any LogXXX is
public static void LogInformation(this ILogger logger, string message, params object[] args)
So the args is a param.
That means if you pass an array, what it actually happens is the following call is actually made
"Bowler(s) alreadyInducted[0] already inducted to hall of fame";
So the first element it will appear in the log.
I see that there is a popular question on Stackoverflow here https://stackoverflow.com/questions/66317482/serilog-only-logs-first-element-of-array and the suggestion is to change the calling code, to cast the array to an object, so the params will be called with one object and not with as many objects the entire alreadyInducted has.
Logger.LogError("Bowler(s) {alreadyInducted} already inducted to hall of fame", (object)alreadyInducted);
But even so, you can't do much with this library, most you can do is
_logger.VerifyLog(logger => logger.LogError("Bowler(s) {alreadyInducted} already inducted to hall of fame", hallOfFameInductees, It.Is<object[]>(s => s.Length == 1))), Times.Once);
Or to use pattern matching
_logger.VerifyLog(logger => logger.LogError("Bowler(s)*{ BowlerId = 1*BowlerId = 2*already inducted to hall of fame"));
You can verify what data is in the "Performed invocations:" section when the test fails.
When running unit tests to verify logger is called as expected, Moq.ILogger threw this exception:
Stack Trace:
Code:
Unit Test (hallOfFameInductees and hallOfFamers generated via Bogus, Fluent calls override properties set via Bogus):
Models: