using System.Data.Common; using Hutopy.Application.Common.Interfaces; using Hutopy.Infrastructure.Data; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Hutopy.Application.FunctionalTests; using static Testing; public class CustomWebApplicationFactory : WebApplicationFactory { private readonly DbConnection _connection; public CustomWebApplicationFactory(DbConnection connection) { _connection = connection; } protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureTestServices(services => { services .RemoveAll() .AddTransient(provider => Mock.Of(s => s.Id == GetUserId())); services .RemoveAll>() .AddDbContext((sp, options) => { options.AddInterceptors(sp.GetServices()); options.UseSqlServer(_connection); }); }); } }