Skip to content

Commit

Permalink
Improve code-coverage by testing AddNLogWeb (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Dec 13, 2022
1 parent 897be87 commit c5768c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NLog.Web.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASP.NET Core 3 - VS2019", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASP.NET Core 5 NLog Example", "examples\ASP.NET Core 5\ASP.NET Core 5 NLog Example\ASP.NET Core 5 NLog Example.csproj", "{6B629300-2FD1-4465-B077-24D01E2BB5E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASP.NET Core 6 NLog Example", "examples\ASP.NET Core 6\ASP.NET Core 6 NLog Example\ASP.NET Core 6 NLog Example.csproj", "{C7F367FA-9DFC-4AA4-81AF-1B4933EAE516}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASP.NET Core 6 NLog Example", "examples\ASP.NET Core 6\ASP.NET Core 6 NLog Example\ASP.NET Core 6 NLog Example.csproj", "{C7F367FA-9DFC-4AA4-81AF-1B4933EAE516}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
15 changes: 12 additions & 3 deletions tests/NLog.Web.AspNetCore.Tests/AspNetCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public void Dispose()

#endregion

[Fact]
public void UseNLogShouldLogTest()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void UseNLogShouldLogTest(bool useNLogWeb)
{
var webhost = CreateWebHost();
var webhost = useNLogWeb ? CreateWebHost() : CreateWebHostAddNLogWeb();

var loggerFact = GetLoggerFactory(webhost);

Expand Down Expand Up @@ -306,6 +308,13 @@ private static IWebHost CreateWebHost(NLogAspNetCoreOptions options = null)
.Build();
}

private static IWebHost CreateWebHostAddNLogWeb()
{
return CreateWebHostBuilder()
.ConfigureLogging(builder => builder.ClearProviders().AddNLogWeb())
.Build();
}

private static ILoggerFactory GetLoggerFactory(IWebHost webhost)
{
return webhost.Services.GetService<Microsoft.Extensions.Logging.ILoggerFactory>();
Expand Down

0 comments on commit c5768c1

Please sign in to comment.