1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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<IWebResourceManager, WebResourceManager>();
- //Configure Abp and Dependency Injection
- return services.AddAbp<ExamWebTestModule>(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<ExamDbContext>();
- builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);
- var options = builder.Options;
- var iocManager = serviceProvider.GetRequiredService<IIocManager>();
- iocManager.IocContainer
- .Register(
- Component.For<DbContextOptions<ExamDbContext>>()
- .Instance(options)
- .LifestyleSingleton()
- );
- }
- }
- }
|