-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
TestStartup.cs
60 lines (51 loc) · 2.09 KB
/
TestStartup.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
50
51
52
53
54
55
56
57
58
59
60
using HappyCode.NetCoreBoilerplate.Api.BackgroundServices;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Filters;
using HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure.DataFeeders;
using HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure.Fakes;
using HappyCode.NetCoreBoilerplate.Core;
using HappyCode.NetCoreBoilerplate.Core.Registrations;
using Microsoft.EntityFrameworkCore;
using Microsoft.FeatureManagement;
namespace HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure
{
internal class TestStartup : Startup
{
public TestStartup(IConfiguration configuration)
: base(configuration)
{
}
public override void ConfigureServices(IServiceCollection services)
{
services
.AddHttpContextAccessor()
.AddMvcCore(options =>
{
options.Filters.Add<ValidateModelStateFilter>();
})
.AddDataAnnotations();
services.AddCoreComponents();
services.AddSingleton<IPingService, FakePingService>(); //override registration with own fakes
services.AddFeatureManagement();
services.AddDbContext<EmployeesContext>(options =>
{
options.UseInMemoryDatabase("employees");
});
services.AddDbContext<CarsContext>(options =>
{
options.UseInMemoryDatabase("cars");
});
}
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var employeesContext = app.ApplicationServices.GetService<EmployeesContext>();
EmployeesContextDataFeeder.Feed(employeesContext);
var carsContext = app.ApplicationServices.GetService<CarsContext>();
CarsContextDataFeeder.Feed(carsContext);
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}