diff --git a/tests/Heimdall.IntegrationTests/Notifications/NotificationDeliveryOutboxTests.cs b/tests/Heimdall.IntegrationTests/Notifications/NotificationDeliveryOutboxTests.cs index c728fe0..bc03d66 100644 --- a/tests/Heimdall.IntegrationTests/Notifications/NotificationDeliveryOutboxTests.cs +++ b/tests/Heimdall.IntegrationTests/Notifications/NotificationDeliveryOutboxTests.cs @@ -10,7 +10,6 @@ using Heimdall.Infrastructure.Services; using Heimdall.IntegrationTests.Controllers; using Heimdall.IntegrationTests.Factories; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; @@ -66,12 +65,14 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p { var (_, futureId) = await CreateDeliveryAsync(NotificationChannel.Email, "future@example.test", "Future"); var (_, leasedId) = await CreateDeliveryAsync(NotificationChannel.Email, "leased@example.test", "Leased"); - await UpdateDeliveryAsync(futureId, update => update - .SetProperty(d => d.NextAttemptAt, (DateTime?)DateTime.UtcNow.AddMinutes(10))); - await UpdateDeliveryAsync(leasedId, update => update - .SetProperty(d => d.Status, NotificationDeliveryStatus.Processing) - .SetProperty(d => d.Attempts, 1) - .SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(5))); + await UpdateDeliveryAsync(futureId, delivery => + delivery.NextAttemptAt = DateTime.UtcNow.AddMinutes(10)); + await UpdateDeliveryAsync(leasedId, delivery => + { + delivery.Status = NotificationDeliveryStatus.Processing; + delivery.Attempts = 1; + delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(5); + }); var email = new RecordingEmailService(); await ProcessDeliveryAsync(futureId, email: email); @@ -90,10 +91,12 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p public async Task ProcessAsync_ExpiredLease_ReclaimsAndCompletesDelivery() { var (_, deliveryId) = await CreateDeliveryAsync(NotificationChannel.Email, "retry@example.test", "Retry"); - await UpdateDeliveryAsync(deliveryId, update => update - .SetProperty(d => d.Status, NotificationDeliveryStatus.Processing) - .SetProperty(d => d.Attempts, 1) - .SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(-1))); + await UpdateDeliveryAsync(deliveryId, delivery => + { + delivery.Status = NotificationDeliveryStatus.Processing; + delivery.Attempts = 1; + delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(-1); + }); var email = new RecordingEmailService(); await ProcessDeliveryAsync(deliveryId, email: email); @@ -113,14 +116,18 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p var (_, futureId) = await CreateDeliveryAsync(NotificationChannel.Email, "future@example.test", "Future"); var (_, activeLeaseId) = await CreateDeliveryAsync(NotificationChannel.Ntfy, "active-topic", "Active"); var (_, expiredLeaseId) = await CreateDeliveryAsync(NotificationChannel.Email, "expired@example.test", "Expired"); - await UpdateDeliveryAsync(futureId, update => update - .SetProperty(d => d.NextAttemptAt, (DateTime?)DateTime.UtcNow.AddMinutes(10))); - await UpdateDeliveryAsync(activeLeaseId, update => update - .SetProperty(d => d.Status, NotificationDeliveryStatus.Processing) - .SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(5))); - await UpdateDeliveryAsync(expiredLeaseId, update => update - .SetProperty(d => d.Status, NotificationDeliveryStatus.Processing) - .SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(-1))); + await UpdateDeliveryAsync(futureId, delivery => + delivery.NextAttemptAt = DateTime.UtcNow.AddMinutes(10)); + await UpdateDeliveryAsync(activeLeaseId, delivery => + { + delivery.Status = NotificationDeliveryStatus.Processing; + delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(5); + }); + await UpdateDeliveryAsync(expiredLeaseId, delivery => + { + delivery.Status = NotificationDeliveryStatus.Processing; + delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(-1); + }); var backgroundJobs = Substitute.For(); backgroundJobs.Create(Arg.Any(), Arg.Any()).Returns("job-id"); @@ -158,13 +165,13 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p return (notification.Id, delivery.Id); } - private async Task UpdateDeliveryAsync(Guid deliveryId, - System.Linq.Expressions.Expression, - SetPropertyCalls>> update) + private async Task UpdateDeliveryAsync(Guid deliveryId, Action update) { await using var scope = Factory.Services.CreateAsyncScope(); var db = scope.ServiceProvider.GetRequiredService(); - await db.NotificationDeliveries.Where(d => d.Id == deliveryId).ExecuteUpdateAsync(update); + var delivery = await db.NotificationDeliveries.SingleAsync(d => d.Id == deliveryId); + update(delivery); + await db.SaveChangesAsync(); } private async Task ProcessDeliveryAsync(Guid deliveryId,