-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDebugProbeTestApp.cs
More file actions
67 lines (58 loc) · 2.06 KB
/
Copy pathDebugProbeTestApp.cs
File metadata and controls
67 lines (58 loc) · 2.06 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using DebugProbe.AspNetCore.Extensions;
using DebugProbe.AspNetCore.Models;
using DebugProbe.AspNetCore.Options;
using DebugProbe.AspNetCore.Storage;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace DebugProbe.AspNetCore.Tests.Infrastructure;
internal sealed class DebugProbeTestApp : IAsyncDisposable
{
private readonly IHost _host;
private DebugProbeTestApp(IHost host)
{
_host = host;
Client = host.GetTestClient();
Store = host.Services.GetRequiredService<DebugEntryStore>();
}
public HttpClient Client { get; }
public DebugEntryStore Store { get; }
public DebugEntry SingleEntry => Assert.Single(Store.GetAll());
public static async Task<DebugProbeTestApp> CreateAsync(
Action<IEndpointRouteBuilder> mapEndpoints,
Action<DebugProbeOptions>? configureOptions = null,
Action<IApplicationBuilder>? configureAfterDebugProbe = null,
Action<IServiceCollection>? configureServices = null)
{
var host = await new HostBuilder()
.ConfigureWebHost(webHost =>
{
webHost.UseTestServer();
webHost.ConfigureServices(services =>
{
services.AddRouting();
services.AddDebugProbe(configureOptions);
configureServices?.Invoke(services);
});
webHost.Configure(app =>
{
app.UseRouting();
app.UseDebugProbe();
configureAfterDebugProbe?.Invoke(app);
app.UseEndpoints(mapEndpoints);
});
})
.StartAsync();
return new DebugProbeTestApp(host);
}
public async ValueTask DisposeAsync()
{
Client.Dispose();
await _host.StopAsync();
_host.Dispose();
}
}