adrianiftode / Moq.ILogger

Easy verify ILogger Moq mocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asserting log method called 0 times or never doesnt work

ruaridhnewman opened this issue · comments

When trying to assert that the LogError method wasn't called using Times.Never or Times.Exactly(0), the result is always:

Expected invocation on the mock at least once, but was never performed

When I set the Times field to Times.Exactly(2) (for example), I get the result:

Expected invocation on the mock exactly 2 times, but was 0 times

My test is set up as follows:

    // sut
    public async Task<bool> Method() {
        var result = await _anotherService.DoSomething();  // this returns true/false

        if (!result) {
            _logger.LogError("An error");
        }

        return result;
    }


    // tests
    [Fact]
    public async void UseMethod_Success()
    {
      // Act
      var result = await _sut.Method();

      // Assert
      Assert.True(result);
      _logger.VerifyLog(x => x.LogError(It.IsAny<string>()), Times.Never); // Always expects it to be called once, even though `Times.Never` is set
    }

Thanks for opening this issue. This is now fixed in version 1.1.7

Great, thank you!