Created
August 7, 2025 11:46
-
-
Save M-Yankov/c2d0922b2f07c37fc1e6f5d52912b3a6 to your computer and use it in GitHub Desktop.
Method for ILogger mock verification used i unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SetupLogger(LogLevel logLevel, string partialMessageToContains, Times timesInvoked) | |
{ | |
_loggerMock | |
.Setup(x => x.Log( | |
It.Is<LogLevel>(level => level == logLevel), | |
It.IsAny<EventId>(), | |
It.Is<It.IsAnyType>((o, t) => o.ToString().Contains(partialMessageToContains)), | |
It.IsAny<Exception?>(), | |
It.IsAny<Func<It.IsAnyType, Exception?, string>>())) | |
.Verifiable(timesInvoked, failMessage: $"Expect to contain {partialMessageToContains}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment