First commit. Include junk from template to remove
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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<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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user