mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Standardizes test conventions and documentation
This commit is contained in:
1 parent
7aeed04255
commit
f42dc709de
190 files changed
+2180
-2814
No files matched your search
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class ChangePasswordEndpointTests
|
||||
private readonly ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>> _mockHandler;
|
||||
private readonly ChangePasswordEndpoint _sut;
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||
private readonly ChangePasswordResponseFixture _changePasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class ChangePasswordEndpointTests
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ChangePasswordResponse expectedResponse = new(IsPasswordChanged: true);
|
||||
ChangePasswordResponse expectedResponse = _changePasswordResponseFixture.Create(isPasswordChanged: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class ChangePasswordEndpointTests
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ChangePasswordResponse(true)));
|
||||
.Returns(Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class ChangePasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new ChangePasswordResponse(true));
|
||||
return Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement.Users;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
|
||||
@@ -25,6 +26,7 @@ public class GetUsersEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>> _mockHandler;
|
||||
private readonly GetUsersEndpoint _sut;
|
||||
private readonly UserResponseFixture _userResponseFixture = new();
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUsersEndpointTests"/> class.
|
||||
/// </summary>
|
||||
@@ -41,7 +43,7 @@ public class GetUsersEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<UserResponse> expectedResponse =
|
||||
[
|
||||
new UserResponse(Guid.NewGuid(), "testUser", DateTime.UtcNow, null)
|
||||
_userResponseFixture.Create(username: "testUser", createdOnUtc: DateTime.UtcNow, updatedOnUtc: null)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class LoginEndpointTests
|
||||
private readonly IQueryHandler<LoginUserQuery, Result<LoginResponse>> _mockHandler;
|
||||
private readonly LoginEndpoint _sut;
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
private readonly LoginResponseFixture _loginResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class LoginEndpointTests
|
||||
// Arrange
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
LoginResponse expectedResponse = new(Guid.NewGuid(), "testUser", "jwt_token", true);
|
||||
LoginResponse expectedResponse = _loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class LoginEndpointTests
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
|
||||
.Returns(Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class LoginEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
|
||||
return Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RecoverPasswordEndpointTests
|
||||
private readonly ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>> _mockHandler;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly RecoverPasswordResponseFixture _recoverPasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RecoverPasswordEndpointTests
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RecoverPasswordResponse expectedResponse = new(IsPasswordReset: true);
|
||||
RecoverPasswordResponse expectedResponse = _recoverPasswordResponseFixture.Create(isPasswordReset: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class RecoverPasswordEndpointTests
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RecoverPasswordResponse(true)));
|
||||
.Returns(Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,7 +116,7 @@ public class RecoverPasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RecoverPasswordResponse(true));
|
||||
return Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RegisterEndpointTests
|
||||
private readonly ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
RegistrationResponse expectedResponse = _registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class RegisterEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -117,7 +119,7 @@ public class RegisterEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+8
-6
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -30,6 +31,7 @@ public class GetAuthorizationEndpointTests
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly GetAuthorizationEndpoint _sut;
|
||||
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAuthorizationEndpointTests"/> class.
|
||||
@@ -46,10 +48,10 @@ public class GetAuthorizationEndpointTests
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
request.UserId!.Value,
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
userId: request.UserId!.Value,
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -97,7 +99,7 @@ public class GetAuthorizationEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
@@ -128,7 +130,7 @@ public class GetAuthorizationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
|
||||
+10
-6
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>> _mockHandler;
|
||||
private readonly GetUserPermissionsEndpoint _sut;
|
||||
private readonly PermissionResponseFixture _permissionResponseFixture = new();
|
||||
private readonly GetUserPermissionsRequestFixture _getUserPermissionsRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserPermissionsEndpointTests"/> class.
|
||||
@@ -41,12 +45,12 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<PermissionResponse> expectedResponse =
|
||||
[
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -63,7 +67,7 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Permissions.NotFound", "User permissions not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -90,7 +94,7 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
|
||||
@@ -122,7 +126,7 @@ public class GetUserPermissionsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserPermissionsRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserPermissionsRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+11
-7
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -25,6 +27,8 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>> _mockHandler;
|
||||
private readonly GetUserRoleEndpoint _sut;
|
||||
private readonly RoleResponseFixture _roleResponseFixture = new();
|
||||
private readonly GetUserRoleRequestFixture _getUserRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserRoleEndpointTests"/> class.
|
||||
@@ -39,9 +43,9 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithRole()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RoleResponse expectedResponse = new(Guid.NewGuid(), "Admin");
|
||||
RoleResponse expectedResponse = _roleResponseFixture.Create(roleName: "Admin");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(expectedResponse));
|
||||
|
||||
@@ -57,7 +61,7 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Role.NotFound", "User role not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -84,10 +88,10 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserRoleRequest request = new(userId);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
|
||||
.Returns(Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -112,11 +116,11 @@ public class GetUserRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
|
||||
return Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin"));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserRoleRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserRoleRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+17
-28
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly UpdateUserRoleAndPermissionsEndpoint _sut;
|
||||
private readonly UpdateUserRoleAndPermissionsRequestFixture _updateUserRoleAndPermissionsRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserRoleAndPermissionsEndpointTests"/> class.
|
||||
@@ -41,16 +45,11 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithAuthorization()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -67,11 +66,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Authorization.Update.Failed", "Failed to update user role and permissions.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -97,17 +92,12 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateUserRoleAndPermissionsCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -136,16 +126,15 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(
|
||||
new UpdateUserRoleAndPermissionsRequest(Guid.NewGuid(), Guid.NewGuid(), [Guid.NewGuid()]),
|
||||
_updateUserRoleAndPermissionsRequestFixture.Create(),
|
||||
cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
|
||||
Reference in new issue
Block a user