jeudi 2 janvier 2020

.NET Core 3.0 ILogger testing

I just migrated from .NET Core 2.2 to .NET Core 3.0 and... My tests have failed.

Below code is working in .NET Core 2.2 but is failing in .NET Core 3.0 with

Expected invocation on the mock once, but was 0 times: l => l.Log<object>(LogLevel.Error, 0, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>())

var services = Mock.Of<IServiceCollection>();
var configurationMock = new Mock<IConfiguration>();
var loggerMock = new Mock<ILogger>();

services.AddCustomersConfiguration(configurationMock.Object, loggerMock.Object);

configurationMock.Verify(c => c.GetSection(Customers), Times.Once);
loggerMock.Verify(l => l.Log<object>(LogLevel.Error, (EventId)0, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()), Times.Once);

That would be helpful if you would have any suggestions

Aucun commentaire:

Enregistrer un commentaire