using System.Data.Common; using AutobusApi.Infrastructure.Identity; using AutoubsApi.Infrastructure.Data; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; namespace AutobusApi.IntegrationTests; public class CustomWebApplicationFactory : WebApplicationFactory where TProgram : class { protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureServices(services => { var dbContextDescriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions)); services.Remove(dbContextDescriptor); var identityDbContextDescriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions)); services.Remove(identityDbContextDescriptor); var dbConnectionDescriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbConnection)); services.Remove(dbConnectionDescriptor); services.AddDbContext((container, options) => { options.UseInMemoryDatabase("autobus"); }); services.AddDbContext((container, options) => { options.UseInMemoryDatabase("autobus"); }); }); builder.UseEnvironment("Development"); }}