From f5b2db0296e68fc9671fa61c3cf2a3abd9d8b241 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 16 Apr 2026 14:15:21 +0200 Subject: [PATCH] Update tests to expect ValidationException for BatchId dupes Refactored InvokeBatchDuplicateGuardTests to expect and assert FluentValidation's ValidationException instead of the custom BadRequestException when a duplicate BatchId is submitted. Assertions and comments were updated accordingly, and the DigitalData.Core.Exceptions import was removed. Test logic remains unchanged. --- .../RecActions/InvokeBatchDuplicateGuardTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/ReC.Tests/Application/RecActions/InvokeBatchDuplicateGuardTests.cs b/tests/ReC.Tests/Application/RecActions/InvokeBatchDuplicateGuardTests.cs index 27df0a7..f724ce6 100644 --- a/tests/ReC.Tests/Application/RecActions/InvokeBatchDuplicateGuardTests.cs +++ b/tests/ReC.Tests/Application/RecActions/InvokeBatchDuplicateGuardTests.cs @@ -1,6 +1,6 @@ using System.Linq; using System.Threading.Tasks; -using DigitalData.Core.Exceptions; +using FluentValidation; using MediatR; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; @@ -22,7 +22,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase } [Test] - public async Task Invoke_with_existing_batchId_throws_BadRequestException() + public async Task Invoke_with_existing_batchId_throws_ValidationException() { var (sender, scope) = CreateScopedSender(); using var _ = scope; @@ -39,8 +39,8 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase Assert.That(existingBatchId, Is.Not.Null.And.Not.Empty, $"No results with a BatchId found for ProfileId {ProfileId}. Ensure test data exists in the database."); - // Act & Assert: invoking with the same BatchId should throw - var ex = Assert.ThrowsAsync(async () => + // Act & Assert: invoking with the same BatchId should throw ValidationException + var ex = Assert.ThrowsAsync(async () => await sender.Send(new InvokeBatchRecActionViewsCommand { ProfileId = ProfileId, @@ -50,7 +50,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase } })); - Assert.That(ex!.Message, Does.Contain(existingBatchId!)); + Assert.That(ex!.Errors.Any(e => e.PropertyName.Contains("BatchId"))); } [Test] @@ -61,7 +61,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase var uniqueBatchId = $"test-{System.Guid.NewGuid():N}"; - // This should NOT throw BadRequestException for duplicate BatchId. + // This should NOT throw ValidationException for duplicate BatchId. // It may throw other exceptions (e.g., no actions found, endpoint errors), // but the duplicate guard should pass. try @@ -75,7 +75,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase } }).GetAwaiter().GetResult(); } - catch (BadRequestException badReq) when (badReq.Message.Contains("already results associated")) + catch (ValidationException valEx) when (valEx.Errors.Any(e => e.PropertyName.Contains("BatchId"))) { Assert.Fail("Duplicate guard should not trigger for a unique BatchId."); }