public void RunBeforeAnyTests() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddEnvironmentVariables(); var env = TestContext.Parameters["ASPNETCORE_ENVIRONMENT"]; if (env == "Production") { builder.AddJsonFile("appsettings.Testing.json", true, true); } else { builder.AddJsonFile("appsettings.Testing.Development.json", true, true); } _configuration = builder.Build(); var startup = new API.Startup(_configuration); var services = new ServiceCollection(); var identityStartUp = new Brimo.IDP.STS.Identity.Startup(_configuration); services.AddSingleton(Mock.Of <IWebHostEnvironment>(w => w.EnvironmentName == Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))); services.AddSingleton(Mock.Of <IHostingEnvironment>(w => w.EnvironmentName == Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))); services.AddLogging(); startup.ConfigureServices(services); identityStartUp.ConfigureServices(services); // Setup testing user (need to add a user to identity and use a real guid) var currentUserServiceDescriptor = services.FirstOrDefault(d => d.ServiceType == typeof(ICurrentUserService)); services.Remove(currentUserServiceDescriptor); services.AddSingleton <IConfiguration>(_configuration); services.AddTransient <ICurrentUserService, CurrentUserService>(); _scopeFactory = services.BuildServiceProvider().GetService <IServiceScopeFactory>(); _checkpoint = new Checkpoint { TablesToIgnore = new[] { "__EFMigrationsHistory" } }; EnsureDatabase(); }
public Startup(IConfiguration configuration) { Configuration = configuration; this._apiStartup = new API.Startup(configuration); }