using System;
|
|
using Abp.AspNetCore;
|
|
using Abp.AspNetCore.TestBase;
|
|
using Abp.Dependency;
|
|
using BCS.BMC.Authentication.JwtBearer;
|
|
using BCS.BMC.Configuration;
|
|
using BCS.BMC.EntityFrameworkCore;
|
|
using BCS.BMC.Identity;
|
|
using BCS.BMC.Web.Resources;
|
|
using BCS.BMC.Web.Startup;
|
|
using Castle.MicroKernel.Registration;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace BCS.BMC.Web.Tests
|
|
{
|
|
public class Startup
|
|
{
|
|
private readonly IConfigurationRoot _appConfiguration;
|
|
|
|
public Startup(IWebHostEnvironment env)
|
|
{
|
|
_appConfiguration = env.GetAppConfiguration();
|
|
}
|
|
|
|
public IServiceProvider ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddEntityFrameworkInMemoryDatabase();
|
|
|
|
services.AddMvc();
|
|
|
|
IdentityRegistrar.Register(services);
|
|
AuthConfigurer.Configure(services, _appConfiguration);
|
|
|
|
services.AddScoped<IWebResourceManager, WebResourceManager>();
|
|
|
|
//Configure Abp and Dependency Injection
|
|
return services.AddAbp<BMCWebTestModule>(options =>
|
|
{
|
|
options.SetupTest();
|
|
});
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
UseInMemoryDb(app.ApplicationServices);
|
|
|
|
app.UseAbp(); //Initializes ABP framework.
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseJwtTokenMiddleware();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
|
|
});
|
|
}
|
|
|
|
private void UseInMemoryDb(IServiceProvider serviceProvider)
|
|
{
|
|
var builder = new DbContextOptionsBuilder<BMCDbContext>();
|
|
builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);
|
|
var options = builder.Options;
|
|
|
|
var iocManager = serviceProvider.GetRequiredService<IIocManager>();
|
|
iocManager.IocContainer
|
|
.Register(
|
|
Component.For<DbContextOptions<BMCDbContext>>()
|
|
.Instance(options)
|
|
.LifestyleSingleton()
|
|
);
|
|
}
|
|
}
|
|
}
|