Files
ReC/tests/ReC.Tests/Application/Profile/ProfileQueryTests.cs
TekH cb12cfcbc2 Refactor query handlers to remove NotFoundException
Refactored query handlers (`ReadProfileViewQueryHandler`,
`ReadRecActionViewQueryHandler`, and `ReadResultViewQueryHandler`)
to return empty results instead of throwing `NotFoundException`
when no data is found. Simplified the logic by removing null
or empty result checks and directly returning mapped results.

Updated corresponding test cases to align with the new behavior:
- Removed `try-catch` blocks for `NotFoundException`.
- Adjusted assertions to handle empty results.
- Removed the test case for `ReadRecActionViewQuery` that
  expected `NotFoundException`.

This change reflects a design shift to let the calling code
handle empty results instead of relying on exceptions.
2026-08-03 16:29:35 +02:00

48 lines
1.4 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.Profile.Queries;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Profile;
[TestFixture]
public class ProfileQueryTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task ReadProfileViewQuery_returns_profile_from_database()
{
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;
var profiles = await sender.Send(new ReadProfileViewQuery
{
Id = profileId,
IncludeActions = false
});
var profile = profiles.SingleOrDefault();
Assert.Multiple(() =>
{
Assert.That(profile?.Id, Is.EqualTo(profileId));
Assert.That(profile?.ProfileName, Is.Not.Null.And.Not.Empty);
Assert.That(profile?.Active, Is.True);
});
}
}