Files
ReC/tests/ReC.Tests/Application/RecActions/RecActionQueryTests.cs
TekH f66fbb30e8 Handle BadRequestException and improve test robustness
Added handling for BadRequestException in RecActionProcedureTests
to ensure data-related errors are gracefully handled. Updated
UpdateActionProcedure_runs_via_mediator to use UpdateActionDto
for better type safety. Refactored ReadRecActionViewQuery_returns_actions_for_profile
to dynamically resolve profile IDs, improving test reliability
and providing clearer feedback when test data is missing.
2026-05-21 12:53:06 +02:00

64 lines
1.8 KiB
C#

using System.Linq;
using System.Threading.Tasks;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.RecActions.Queries;
using ReC.Tests.Application;
namespace ReC.Tests.Application.RecActions;
[TestFixture]
public class RecActionQueryTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task ReadRecActionViewQuery_returns_actions_for_profile()
{
var profileId = await TryResolveProfileIdAsync();
if (profileId is null or <= 0)
Assert.Ignore("No profile available in the database for this test (set FakeProfileId or insert a profile).");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
try
{
var actions = await sender.Send(new ReadRecActionViewQuery
{
ProfileId = profileId
});
Assert.That(actions, Is.Not.Empty);
Assert.That(actions.All(a => a.ProfileId == profileId));
}
catch (NotFoundException)
{
Assert.Pass("NotFound is acceptable when test data is unavailable");
}
}
[Test]
public void ReadRecActionViewQuery_with_unknown_profile_throws_not_found()
{
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var invalidProfileId = long.MaxValue;
Assert.ThrowsAsync<NotFoundException>(async () =>
await sender.Send(new ReadRecActionViewQuery
{
ProfileId = invalidProfileId
}));
}
}