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.
This commit is contained in:
@@ -30,23 +30,18 @@ public class ProfileQueryTests : RecApplicationTestBase
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
|
||||
try
|
||||
var profiles = await sender.Send(new ReadProfileViewQuery
|
||||
{
|
||||
var profiles = await sender.Send(new ReadProfileViewQuery
|
||||
{
|
||||
Id = profileId,
|
||||
IncludeActions = false
|
||||
});
|
||||
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)
|
||||
var profile = profiles.SingleOrDefault();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Pass("NotFound is acceptable when profile does not exist");
|
||||
}
|
||||
Assert.That(profile?.Id, Is.EqualTo(profileId));
|
||||
Assert.That(profile?.ProfileName, Is.Not.Null.And.Not.Empty);
|
||||
Assert.That(profile?.Active, Is.True);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user