44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System.Data.Common;
|
|
using Hutopy.Application.Common.Interfaces;
|
|
using Hutopy.Infrastructure.Data;
|
|
using Hutopy.Web;
|
|
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<Program>
|
|
{
|
|
private readonly DbConnection _connection;
|
|
|
|
public CustomWebApplicationFactory(DbConnection connection)
|
|
{
|
|
_connection = connection;
|
|
}
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.ConfigureTestServices(services =>
|
|
{
|
|
services
|
|
.RemoveAll<IUser>()
|
|
.AddTransient(provider => Mock.Of<IUser>(s => s.Id == GetUserId()));
|
|
|
|
services
|
|
.RemoveAll<DbContextOptions<ApplicationDbContext>>()
|
|
.AddDbContext<ApplicationDbContext>((sp, options) =>
|
|
{
|
|
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
|
|
options.UseSqlServer(_connection);
|
|
});
|
|
});
|
|
}
|
|
}
|