Files
ReC/tests/ReC.Tests/Application/Profile/ProfileQueryTests.cs
TekH 99269a51c4 Refactor tests and introduce UpdateProfileDto
Refactored `ProfileProcedureTests` to use `UpdateProfileDto` for the `Data` property in `UpdateProfileCommand`, improving code clarity.

Updated `ProfileQueryTests` to replace `FakeProfileId` retrieval with `TryResolveProfileIdAsync` and added a conditional check to ignore the test if no valid profile ID is available, enhancing test robustness and flexibility.
2026-05-21 12:52:48 +02:00

53 lines
1.6 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;
try
{
var profiles = await sender.Send(new ReadProfileViewQuery
{
Id = profileId,
IncludeActions = false
});
var profile = profiles.Single();
Assert.That(profile.Id, Is.EqualTo(profileId));
Assert.That(profile.ProfileName, Is.Not.Null.And.Not.Empty);
Assert.That(profile.Active, Is.True);
}
catch (NotFoundException)
{
Assert.Pass("NotFound is acceptable when profile does not exist");
}
}
}