diff --git a/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs b/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs index b6d0579..110169f 100644 --- a/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs +++ b/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs @@ -5,6 +5,7 @@ using Heimdall.Infrastructure.Data; using Heimdall.Infrastructure.Data.Interceptors; using Heimdall.Infrastructure.Services; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NSubstitute; using Shouldly; @@ -175,13 +176,16 @@ public class CameraAssignmentServiceTests : IAsyncLifetime var options = new DbContextOptionsBuilder() .UseNpgsql(source.Database.GetConnectionString()).Options; var broadcast = Substitute.For(); + var services = new ServiceCollection(); + services.AddSingleton(broadcast); + using var serviceProvider = services.BuildServiceProvider(); string? observedName = null; broadcast.NotifyAllAgentsReload(Arg.Any()).Returns(async _ => { await using var verify = await _dbFactory.CreateDbContextAsync(); observedName = (await verify.Cameras.FindAsync(cameraId))!.Name; }); - await using (var db = new AppDbContext(options, new Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor(), broadcast)) + await using (var db = new AppDbContext(options, new Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor(), serviceProvider)) { (await db.Cameras.FindAsync(cameraId))!.Update("committed", null, null, null); await db.SaveChangesAsync(); @@ -189,7 +193,7 @@ public class CameraAssignmentServiceTests : IAsyncLifetime observedName.ShouldBe("committed"); await broadcast.Received(1).NotifyAllAgentsReload(Arg.Any()); broadcast.ClearReceivedCalls(); - await using (var db = new AppDbContext(options, new Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor(), broadcast)) + await using (var db = new AppDbContext(options, new Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor(), serviceProvider)) { db.Cameras.Add(new Camera(Guid.NewGuid(), "invalid-site", "rtsp://invalid")); await Should.ThrowAsync(() => db.SaveChangesAsync());