Skip to content

Commit

Permalink
NullLogger was used
Browse files Browse the repository at this point in the history
  • Loading branch information
litichevskiydv committed Nov 20, 2024
1 parent 81a3d3d commit 6c977ec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
{
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddMockLogger(this IServiceCollection services, Mock<ILogger> mockLogger)
public static IServiceCollection AddNullLogger(this IServiceCollection services)
{
var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(mockLogger.Object);

return services
.AddSingleton(mockLoggerFactory.Object)
.AddSingleton<ILoggerFactory, NullLoggerFactory>()
.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static KafkaDependencyValidatorTests()
Dependencies = Array.Empty<DependencyBase>(),
ServiceImplementation = CreateServiceImplementation(
services => services
.AddMockLogger(MockLoggerExtensions.CreateMockLogger())
.AddNullLogger()
.AddKafkaBus(new KafkaSettings {Hosts = new[] {"localhost"}})
),
ExpectedErrors
Expand Down Expand Up @@ -112,7 +112,7 @@ static KafkaDependencyValidatorTests()
},
ServiceImplementation = CreateServiceImplementation(
services => services
.AddMockLogger(MockLoggerExtensions.CreateMockLogger())
.AddNullLogger()
.AddKafkaBus(new KafkaSettings {Hosts = new[] {"localhost"}})
),
ExpectedErrors = Array.Empty<string>()
Expand Down

0 comments on commit 6c977ec

Please sign in to comment.