-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a test case for AddSerilog
- Loading branch information
1 parent
e88ec93
commit 10c4e3e
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/Serilog.Extensions.Hosting.Tests/SerilogLoggingBuilderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog.Sinks.InMemory; | ||
using Serilog.Sinks.InMemory.Assertions; | ||
using Xunit; | ||
|
||
namespace Serilog.Extensions.Hosting.Tests; | ||
|
||
public class SerilogLoggingBuilderExtensionsTests | ||
{ | ||
[Fact] | ||
public async Task LoggingBuilderExtensions_AddSerilog_SuccessAsync() | ||
{ | ||
// Arrange | ||
var builder = WebApplication.CreateBuilder(); | ||
var logger = new LoggerConfiguration() | ||
.WriteTo.InMemory() | ||
.CreateLogger(); | ||
builder.Logging.AddSerilog(logger); | ||
builder.WebHost.UseTestServer(); | ||
var app = builder.Build(); | ||
|
||
// Act | ||
var message = "Hello World!"; | ||
app.Logger.LogInformation("Hello World!"); | ||
await app.StartAsync(); | ||
|
||
// Assert | ||
InMemorySink.Instance.Should().HaveMessage(message); | ||
} | ||
} |