using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using MongoDB.Driver; using Retroactiune.Core.Interfaces; using Retroactiune.Core.Services; using Retroactiune.Infrastructure; namespace Retroactiune { public class TestingStartup { public TestingStartup() { var configurationBuilder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile("appsettings.Testing.json"); Configuration = configurationBuilder.Build(); } private IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Database Configuration services.Configure(Configuration.GetSection(nameof(DatabaseSettings))); services.AddSingleton(sp => sp.GetRequiredService>().Value); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); // Services services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(i => { var settings = i.GetService>(); return new MongoClient(settings.Value.ConnectionString); }); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = "Bearer"; }).AddScheme ("Bearer", o => { }); // WebAPI services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }