From 6fc6aa1ff29359e7e498ee9948f8a4c7278f9ee4 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Tue, 20 Oct 2026 21:10:59 +0200 Subject: [PATCH] test(infrastructure): resolve broadcaster through services --- .../CameraAssignmentServiceTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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()); -- 2.54.1