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
+2 -8
View File
@@ -2,11 +2,10 @@ using JobTrackerApi.Controllers;
using JobTrackerApi.Data;
using JobTrackerApi.Models;
using JobTrackerApi.Services;
using JobTrackerApi.Tests.TestSupport;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace JobTrackerApi.Tests;
@@ -34,11 +33,6 @@ public sealed class BackupControllerTests
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();
}
}