-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiTestContext.cs
More file actions
42 lines (35 loc) · 1.23 KB
/
Copy pathApiTestContext.cs
File metadata and controls
42 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Net.Http;
using Microsoft.AspNetCore.Mvc.Testing;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using Xunit.Abstractions;
namespace SeqFixieSample.XunitTests;
public class ApiTestContext : IDisposable
{
public ApiTestContext(ITestOutputHelper outputHelper)
{
var app = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder => { });
Client = app.CreateClient();
// Comes after the app build so we clobber the app logger created there
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.Enrich.FromLogContext()
.Enrich.WithProperty("AppName", "SeqFixieSample.Api")
.Enrich.WithProperty("TestType", "xUnit")
.WriteTo.Seq("http://localhost:5341")
.WriteTo.TestOutput(outputHelper)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.CreateLogger();
Logger = Log.ForContext<ApiTestContext>();
}
public HttpClient Client { get; }
public ILogger Logger { get; }
public void Dispose()
{
Client.Dispose();
Log.CloseAndFlush();
}
}