mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.ChangePassword;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.ChangePassword.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>> _mockHandler;
|
||||
private readonly ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>> _mockHandler;
|
||||
private readonly ChangePasswordEndpoint _sut;
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ChangePasswordEndpointTests
|
||||
/// </summary>
|
||||
public ChangePasswordEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<ICommandHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>>>();
|
||||
_mockHandler = Substitute.For<ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>>>();
|
||||
_sut = FastEndpoints.Factory.Create<ChangePasswordEndpoint>(_mockHandler);
|
||||
_changePasswordRequestFixture = new ChangePasswordRequestFixture();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class ChangePasswordEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ChangePasswordResponse expectedResponse = new(IsPasswordChanged: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -87,7 +87,7 @@ public class ChangePasswordEndpointTests
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new ChangePasswordResponse(true)));
|
||||
.Returns(Result.From(new ChangePasswordResponse(true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -117,7 +117,7 @@ public class ChangePasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new ChangePasswordResponse(true));
|
||||
return Result.From(new ChangePasswordResponse(true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -23,14 +23,14 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUsersEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>> _mockHandler;
|
||||
private readonly IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>> _mockHandler;
|
||||
private readonly GetUsersEndpoint _sut;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUsersEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetUsersEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>>>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>>>();
|
||||
_sut = Factory.Create<GetUsersEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GetUsersEndpointTests
|
||||
new UserResponse(Guid.NewGuid(), "testUser", DateTime.UtcNow, null)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
@@ -85,7 +85,7 @@ public class GetUsersEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>));
|
||||
.Returns(Result.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
@@ -110,7 +110,7 @@ public class GetUsersEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>);
|
||||
return Result.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>);
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Login;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.Login.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<LoginUserQuery, ErrorOr<LoginResponse>> _mockHandler;
|
||||
private readonly IQueryHandler<LoginUserQuery, Result<LoginResponse>> _mockHandler;
|
||||
private readonly LoginEndpoint _sut;
|
||||
private readonly LoginRequestFixture _loginRequestFixture;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class LoginEndpointTests
|
||||
/// </summary>
|
||||
public LoginEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<LoginUserQuery, ErrorOr<LoginResponse>>>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<LoginUserQuery, Result<LoginResponse>>>();
|
||||
_sut = Factory.Create<LoginEndpoint>(_mockHandler);
|
||||
_loginRequestFixture = new LoginRequestFixture();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class LoginEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
LoginResponse expectedResponse = new(Guid.NewGuid(), "testUser", "jwt_token", true);
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -88,7 +88,7 @@ public class LoginEndpointTests
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
|
||||
.Returns(Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -117,7 +117,7 @@ public class LoginEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
|
||||
return Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.RecoverPassword;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.RecoverPassword.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>> _mockHandler;
|
||||
private readonly ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>> _mockHandler;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RecoverPasswordEndpointTests
|
||||
/// </summary>
|
||||
public RecoverPasswordEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<ICommandHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>>>();
|
||||
_mockHandler = Substitute.For<ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>>>();
|
||||
_sut = FastEndpoints.Factory.Create<RecoverPasswordEndpoint>(_mockHandler);
|
||||
_recoverPasswordRequestFixture = new RecoverPasswordRequestFixture();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class RecoverPasswordEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RecoverPasswordResponse expectedResponse = new(IsPasswordReset: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -87,7 +87,7 @@ public class RecoverPasswordEndpointTests
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new RecoverPasswordResponse(true)));
|
||||
.Returns(Result.From(new RecoverPasswordResponse(true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -115,7 +115,7 @@ public class RecoverPasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new RecoverPasswordResponse(true));
|
||||
return Result.From(new RecoverPasswordResponse(true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Register;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegisterEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>> _mockHandler;
|
||||
private readonly ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RegisterEndpointTests
|
||||
/// </summary>
|
||||
public RegisterEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<ICommandHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>>>();
|
||||
_mockHandler = Substitute.For<ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>>>();
|
||||
_sut = FastEndpoints.Factory.Create<RegisterEndpoint>(_mockHandler);
|
||||
_registrationRequestFixture = new RegistrationRequestFixture();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class RegisterEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -88,7 +88,7 @@ public class RegisterEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -118,7 +118,7 @@ public class RegisterEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetAuthorization;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authorization.GetAuthorization.Fixtures;
|
||||
@@ -27,7 +27,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAuthorizationEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, ErrorOr<AuthorizationResponse>> _mockHandler;
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly GetAuthorizationEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +35,7 @@ public class GetAuthorizationEndpointTests
|
||||
/// </summary>
|
||||
public GetAuthorizationEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetAuthorizationQuery, ErrorOr<AuthorizationResponse>>>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>>>();
|
||||
_sut = Factory.Create<GetAuthorizationEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class GetAuthorizationEndpointTests
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -96,7 +96,7 @@ public class GetAuthorizationEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new AuthorizationResponse(
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
@@ -127,7 +127,7 @@ public class GetAuthorizationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new AuthorizationResponse(
|
||||
return Result.From(new AuthorizationResponse(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetUserPermissions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>> _mockHandler;
|
||||
private readonly IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>> _mockHandler;
|
||||
private readonly GetUserPermissionsEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ public class GetUserPermissionsEndpointTests
|
||||
/// </summary>
|
||||
public GetUserPermissionsEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUserPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>>>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>>>();
|
||||
_sut = Factory.Create<GetUserPermissionsEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class GetUserPermissionsEndpointTests
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -93,7 +93,7 @@ public class GetUserPermissionsEndpointTests
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
|
||||
.Returns(Result.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -118,7 +118,7 @@ public class GetUserPermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>);
|
||||
return Result.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>);
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetUserRole;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserRoleEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserRoleQuery, ErrorOr<RoleResponse?>> _mockHandler;
|
||||
private readonly IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>> _mockHandler;
|
||||
private readonly GetUserRoleEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +31,7 @@ public class GetUserRoleEndpointTests
|
||||
/// </summary>
|
||||
public GetUserRoleEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUserRoleQuery, ErrorOr<RoleResponse?>>>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>>>();
|
||||
_sut = Factory.Create<GetUserRoleEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class GetUserRoleEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RoleResponse expectedResponse = new(Guid.NewGuid(), "Admin");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From<RoleResponse?>(expectedResponse));
|
||||
.Returns(Result.From<RoleResponse?>(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -87,7 +87,7 @@ public class GetUserRoleEndpointTests
|
||||
GetUserRoleRequest request = new(userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
|
||||
.Returns(Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -112,7 +112,7 @@ public class GetUserRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
|
||||
return Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.UpdateUserRoleAndPermissions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, ErrorOr<AuthorizationResponse>> _mockHandler;
|
||||
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly UpdateUserRoleAndPermissionsEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
/// </summary>
|
||||
public UpdateUserRoleAndPermissionsEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<ICommandHandler<UpdateUserRoleAndPermissionsCommand, ErrorOr<AuthorizationResponse>>>();
|
||||
_mockHandler = Substitute.For<ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>>>();
|
||||
_sut = FastEndpoints.Factory.Create<UpdateUserRoleAndPermissionsEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -104,7 +104,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(new AuthorizationResponse(
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
@@ -136,7 +136,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new AuthorizationResponse(
|
||||
return Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
|
||||
Reference in new issue
Block a user