-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathTestServerClientFixture.cs
49 lines (44 loc) · 1.93 KB
/
TestServerClientFixture.cs
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
using System.Data;
using HappyCode.NetCoreBoilerplate.BooksModule.IntegrationTests.Infrastructure.DataFeeders;
using Microsoft.AspNetCore.TestHost;
using Microsoft.FeatureManagement;
namespace HappyCode.NetCoreBoilerplate.BooksModule.IntegrationTests.Infrastructure
{
public class TestServerClientFixture
{
public HttpClient Client { get; }
public TestServerClientFixture()
{
var host = new HostBuilder()
.ConfigureWebHost(webBuilder =>
{
webBuilder
.UseEnvironment("Test")
.ConfigureServices(services =>
{
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>(1) { { "ConnectionStrings:SqliteDb", $"Data Source=tests_tempdb_{DateTimeOffset.Now.ToUnixTimeSeconds()}.db" } })
.Build();
services.AddRouting();
services.AddFeatureManagement();
services.AddBooksModule(config);
})
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapBooksModule());
app.InitBooksModule();
var db = app.ApplicationServices.GetService<IDbConnection>();
BooksDataFeeder.Feed(db);
})
.UseTestServer();
})
.Start();
Client = host.GetTestClient();
}
}
[CollectionDefinition(nameof(TestServerClientCollection))]
public class TestServerClientCollection : ICollectionFixture<TestServerClientFixture>
{
}
}