using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Microsoft.eShopWeb.FunctionalTests.Web; public class TestApplication : WebApplicationFactory<IBasketViewModelService> { private readonly string _environment = "Development"; protected override IHost CreateHost(IHostBuilder builder) { builder.UseEnvironment(_environment); // Add mock/test services to the builder here builder.ConfigureServices(services => { services.AddScoped(sp => { // Replace SQLite with in-memory database for tests return new DbContextOptionsBuilder<CatalogContext>() .UseInMemoryDatabase("InMemoryDbForTesting") .UseApplicationServiceProvider(sp) .Options; }); services.AddScoped(sp => { // Replace SQLite with in-memory database for tests return new DbContextOptionsBuilder<AppIdentityDbContext>() .UseInMemoryDatabase("Identity") .UseApplicationServiceProvider(sp) .Options; }); }); return base.CreateHost(builder); } }