Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/Moq.ILogger.Tests/VerifyLogExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,39 @@ public void Verify_includes_the_fail_message_with_Times_Never()
act.Should().ThrowExactly<VerifyLogException>()
.WithMessage("*Expected invocation on the mock should never have been performed, but was 1 time*");
}

[Fact]
public void Verify_log_error_with_an_expected_event_id_and_message_it_verifies()
{
var loggerMock = new Mock<ILogger>();
loggerMock.Object.LogError(50100, "the description of the error goes here");

Action act = () => loggerMock.VerifyLog(l => l.LogError(50100, It.IsAny<string>()), Times.Once(), "an error must be logged");

act.Should().NotThrow();
}

[Fact]
public void Verify_log_error_with_an_expected_event_id_and_message_it_fails_with_expected_message()
{
var loggerMock = new Mock<ILogger<object>>();
loggerMock.Object.LogError(50100, "the description of the error goes here");

Action act = () => loggerMock.VerifyLog(logger => logger.LogError(50200, "the description of the error goes here"), Times.Once(), "an error must be logged");

act.Should().ThrowExactly<VerifyLogException>()
.WithMessage("*an error must be logged*")
.WithMessage("*Expected invocation on the mock once, but was 0 times*");
}

[Fact]
public void Verify_log_error_with_an_expected_event_id_and_message_it_fails_with_expected_message_fail_on_purpose()
{
var loggerMock = new Mock<ILogger<object>>();
loggerMock.Object.LogError(50100, "the description of the error goes here");

loggerMock.VerifyLog(logger => logger.LogError(50200, "the description of the error goes here"), Times.Once(), "an error must be logged");
}
}

internal static class OtherExtensions
Expand Down