Refactor repeated test host setup

This commit is contained in:
2026-04-01 10:48:28 +02:00
parent 18d1de45cb
commit 517c42250d
10 changed files with 74 additions and 140 deletions
@@ -3,6 +3,7 @@ using JobTrackerApi.Controllers;
using JobTrackerApi.Data;
using JobTrackerApi.Models;
using JobTrackerApi.Services;
using JobTrackerApi.Tests.TestSupport;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@@ -53,26 +54,11 @@ public sealed class JobApplicationsMariaDraftTests
private static Mock<Microsoft.AspNetCore.Identity.UserManager<ApplicationUser>> CreateUserManager()
{
var store = new Mock<Microsoft.AspNetCore.Identity.IUserStore<ApplicationUser>>();
return new Mock<Microsoft.AspNetCore.Identity.UserManager<ApplicationUser>>(
store.Object,
null!,
null!,
null!,
null!,
null!,
null!,
null!,
null!);
return TestHostFactory.CreateUserManager();
}
private static JobTrackerContext CreateDb()
{
var options = new DbContextOptionsBuilder<JobTrackerContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.Options;
var currentUser = new Mock<ICurrentUserService>();
currentUser.SetupGet(x => x.UserId).Returns("user-1");
return new JobTrackerContext(options, currentUser.Object);
return TestHostFactory.CreateInMemoryDb();
}
}