using System; using Abp.AspNetCore; using Abp.AspNetCore.TestBase; using Abp.Dependency; using YGNT.Exam.Authentication.JwtBearer; using YGNT.Exam.Configuration; using YGNT.Exam.EntityFrameworkCore; using YGNT.Exam.Identity; using YGNT.Exam.Web.Resources; using YGNT.Exam.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 YGNT.Exam.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(); //Configure Abp and Dependency Injection return services.AddAbp(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(); builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider); var options = builder.Options; var iocManager = serviceProvider.GetRequiredService(); iocManager.IocContainer .Register( Component.For>() .Instance(options) .LifestyleSingleton() ); } } }