test(infrastructure): resolve broadcaster through services
This commit is contained in:
1 parent
dac178930b
commit
6fc6aa1ff2
1 file changed
+6
-2
@@ -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<AppDbContext>()
|
||||
.UseNpgsql(source.Database.GetConnectionString()).Options;
|
||||
var broadcast = Substitute.For<IConfigBroadcastService>();
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton(broadcast);
|
||||
using var serviceProvider = services.BuildServiceProvider();
|
||||
string? observedName = null;
|
||||
broadcast.NotifyAllAgentsReload(Arg.Any<CancellationToken>()).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<CancellationToken>());
|
||||
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<DbUpdateException>(() => db.SaveChangesAsync());
|
||||
|
||||
Reference in new issue
Block a user