forked from lkurzyniec/netcore-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStartup.cs
68 lines (58 loc) · 2.23 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
61
62
63
64
65
66
67
68
using Autofac;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Filters;
using HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure.DataFeeders;
using HappyCode.NetCoreBoilerplate.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
namespace HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure
{
public class TestStartup : Startup
{
public TestStartup(IConfiguration configuration)
: base(configuration)
{
}
public override void ConfigureServices(IServiceCollection services)
{
services
.AddHttpContextAccessor()
.AddMvcCore(options =>
{
options.Filters.Add<ValidateModelStateFilter>();
})
.AddDataAnnotations()
.SetCompatibilityVersion(CompatibilityVersion.Latest);
services.AddFeatureManagement();
services.AddDbContext<EmployeesContext>(options =>
{
options.UseInMemoryDatabase("employees");
});
services.AddDbContext<CarsContext>(options =>
{
options.UseInMemoryDatabase("cars");
});
}
public override void ConfigureContainer(ContainerBuilder builder)
{
base.ConfigureContainer(builder);
// builder.RegisterType<SomeService>().As<ISomeService>(); //if needed override registration with own test fakes
}
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();
});
}
}
}