0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-29 18:21:08 +00:00
CleanArchitecture/CleanArchitecture.Application.Tests/Queries/Users/GetUserByIdQueryHandlerTests.cs
2023-03-22 19:06:01 +01:00

64 lines
1.8 KiB
C#

using System;
using System.Threading.Tasks;
using CleanArchitecture.Application.Queries.Users.GetUserById;
using CleanArchitecture.Application.Tests.Fixtures.Queries.Users;
using CleanArchitecture.Domain.Errors;
using FluentAssertions;
using Xunit;
namespace CleanArchitecture.Application.Tests.Queries.Users;
public sealed class GetUserByIdQueryHandlerTests
{
private readonly GetUserByIdTestFixture _fixture = new();
[Fact]
public async Task Should_Get_Existing_User()
{
_fixture.SetupUserAsync();
var result = await _fixture.Handler.Handle(
new GetUserByIdQuery(_fixture.ExistingUserId, false),
default);
_fixture.VerifyNoDomainNotification();
result.Should().NotBeNull();
result!.Id.Should().Be(_fixture.ExistingUserId);
}
[Fact]
public async Task Should_Raise_Notification_For_No_User()
{
_fixture.SetupUserAsync();
var request = new GetUserByIdQuery(Guid.NewGuid(), false);
var result = await _fixture.Handler.Handle(
request,
default);
_fixture.VerifyExistingNotification(
nameof(GetUserByIdQuery),
ErrorCodes.ObjectNotFound,
$"User with id {request.UserId} could not be found");
result.Should().BeNull();
}
[Fact]
public async Task Should_Not_Get_Deleted_User()
{
_fixture.SetupDeletedUserAsync();
var result = await _fixture.Handler.Handle(
new GetUserByIdQuery(_fixture.ExistingUserId, false),
default);
_fixture.VerifyExistingNotification(
nameof(GetUserByIdQuery),
ErrorCodes.ObjectNotFound,
$"User with id {_fixture.ExistingUserId} could not be found");
result.Should().BeNull();
}
}