-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathIntegrationTestBase.cs
More file actions
43 lines (35 loc) · 1.04 KB
/
IntegrationTestBase.cs
File metadata and controls
43 lines (35 loc) · 1.04 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
using System.Net.Sockets;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MaIN.Core.IntegrationTests;
public class IntegrationTestBase : IDisposable
{
protected readonly IHost _host;
protected readonly IServiceProvider _services;
protected IntegrationTestBase()
{
_host = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
services.AddMaIN(context.Configuration);
ConfigureServices(services);
})
.Build();
_host.Services.UseMaIN();
_host.Start();
_services = _host.Services;
}
// Allow derived classes to add additional services or override existing ones
protected virtual void ConfigureServices(IServiceCollection services)
{
}
protected T GetService<T>() where T : notnull
{
return _services.GetRequiredService<T>();
}
public void Dispose()
{
_host?.Dispose();
}
}