Replaces ErrorOr library with a custom implementation.

This commit is contained in:
BinaryAlley committed 2026-08-14 03:04:28 -07:00
1 parent 8fe90a4dde
commit 3b772d68ca
436 files changed
+4234 -3922

No files matched your search

@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -68,7 +68,7 @@ public class ChangePasswordCommandHandlerTests
newPassword);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(currentPassword, "hashedCurrentPassword")
.Returns(true);
_mockHashService.HashString(newPassword)
@@ -77,10 +77,10 @@ public class ChangePasswordCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.IsPasswordChanged);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -97,13 +97,13 @@ public class ChangePasswordCommandHandlerTests
ChangePasswordCommand command = new("nonexistentUser", "oldPass", "newPass", "newPass");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -125,15 +125,15 @@ public class ChangePasswordCommandHandlerTests
"newPass");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(incorrectPassword, Uri.UnescapeDataString(user.Password))
.Returns(false);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidCurrentPassword, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -161,17 +161,17 @@ public class ChangePasswordCommandHandlerTests
newPassword);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(currentPassword, "hashedCurrentPassword")
.Returns(true);
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -198,10 +198,10 @@ public class ChangePasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -72,7 +72,7 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
@@ -83,10 +83,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.IsPasswordReset);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -103,13 +103,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new("nonexistentUser", "123456");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -128,13 +128,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, "123456");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.PasswordResetAlreadyRequested, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -152,13 +152,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, "123456");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -180,17 +180,17 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
.Returns(false);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -214,7 +214,7 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
@@ -223,10 +223,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -252,10 +252,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -275,13 +275,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, null);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -12,6 +11,7 @@ using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUs
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -76,7 +76,7 @@ public class RegisterUserCommandHandlerTests
string hashedPassword = "hashedPassword";
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockTotpTokenGenerator.GenerateSecret()
@@ -89,10 +89,10 @@ public class RegisterUserCommandHandlerTests
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
@@ -113,17 +113,17 @@ public class RegisterUserCommandHandlerTests
string hashedPassword = "hashedPassword";
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
@@ -144,13 +144,13 @@ public class RegisterUserCommandHandlerTests
UserEntity existingUser = UserEntityFixture.CreateUserEntity();
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(existingUser));
.Returns(Result.From<UserEntity?>(existingUser));
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameAlreadyExists, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -166,15 +166,15 @@ public class RegisterUserCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to insert user");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -193,10 +193,10 @@ public class RegisterUserCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.GetUsers.Fixtures;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -65,10 +65,10 @@ public class GetUsersQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -86,10 +86,10 @@ public class GetUsersQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -104,13 +104,13 @@ public class GetUsersQueryHandlerTests
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
.Returns(true);
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(users));
.Returns(Result.From(users));
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -11,6 +10,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -79,17 +79,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockJwtTokenGenerator.GenerateToken(user.Id.ToString(), user.Username)
.Returns(jwtToken);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -114,7 +114,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockJwtTokenGenerator.GenerateToken(user.Id.ToString(), user.Username)
@@ -125,10 +125,10 @@ public class LoginUserQueryHandlerTests
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -142,13 +142,13 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new("nonexistentUser", "password");
_mockUserRepository.GetByUsernameAsync(query.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
@@ -166,15 +166,15 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
@@ -194,17 +194,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false);
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.TempPasswordExpired, result.FirstError);
await _mockUserRepository.Received(1).UpdateAsync(Arg.Is<UserEntity>(u =>
@@ -232,7 +232,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false); // Regular password check fails
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
@@ -241,10 +241,10 @@ public class LoginUserQueryHandlerTests
.Returns(jwtToken);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -266,15 +266,15 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
@@ -295,7 +295,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockCryptographyService.Decrypt(encryptedTotpSecret)
@@ -304,10 +304,10 @@ public class LoginUserQueryHandlerTests
.Returns(false);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
@@ -322,10 +322,10 @@ public class LoginUserQueryHandlerTests
.Returns(error);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -345,17 +345,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false); // Regular password check fails
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
.Returns(false); // Temp password check also fails
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedPassword);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -12,6 +11,7 @@ using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserR
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -21,7 +21,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
@@ -80,10 +80,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(false);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
}
@@ -99,10 +99,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Users.UserDoesNotExist, result.FirstError);
}
@@ -121,10 +121,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.RoleNotFound, result.FirstError);
}
@@ -164,13 +164,13 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(newRole);
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(users));
.Returns(Result.From(users));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.CannotRemoveLastAdmin, result.FirstError);
}
@@ -192,15 +192,15 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(role);
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -216,7 +216,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
Username = "testUser",
Password = "hashedPassword",
Libraries = [],
UserPermissions = command.Permissions.Select((p, i) => new UserPermissionEntity
UserPermissions = [.. command.Permissions.Select((p, i) => new UserPermissionEntity
{
UserId = command.UserId,
PermissionId = p,
@@ -226,7 +226,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
Id = p,
PermissionName = (AuthorizationPermission)(i + 1)
}
}).ToList(),
})],
UserRole = null,
CreatedOnUtc = DateTime.UtcNow,
CreatedBy = command.UserId
@@ -242,15 +242,15 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(role);
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.UserId, result.Value.UserId);
Assert.Equal(role.RoleName, result.Value.Role);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Count);
@@ -291,10 +291,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -326,10 +326,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -8,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -50,13 +50,13 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(userId);
_mockAuthorizationService.GetUserAuthorizationAsync(userId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(authEntity));
.Returns(Result.From(authEntity));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(userId, result.Value.UserId);
Assert.Equal(authEntity.Role, result.Value.Role);
Assert.Equal(authEntity.Permissions, result.Value.Permissions);
@@ -74,15 +74,15 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(adminUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(adminUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(adminAuthEntity));
.Returns(Result.From(adminAuthEntity));
_mockAuthorizationService.GetUserAuthorizationAsync(targetUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(targetAuthEntity));
.Returns(Result.From(targetAuthEntity));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(targetUserId, result.Value.UserId);
Assert.Equal(targetAuthEntity.Role, result.Value.Role);
Assert.Equal(targetAuthEntity.Permissions, result.Value.Permissions);
@@ -99,13 +99,13 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(currentUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(currentUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(currentUserAuth));
.Returns(Result.From(currentUserAuth));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
}
@@ -123,10 +123,10 @@ public class GetAuthorizationQueryHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -142,15 +142,15 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(adminUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(adminUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(adminAuthEntity));
.Returns(Result.From(adminAuthEntity));
_mockAuthorizationService.GetUserAuthorizationAsync(targetUserId, Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserPermissions.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -70,10 +70,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -91,10 +91,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -110,10 +110,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
@@ -149,10 +149,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(user);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(AuthorizationPermission.CanViewUsers, result.Value.First().PermissionName);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -11,6 +10,7 @@ using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserRole.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -68,10 +68,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(false);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -89,10 +89,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(error);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -108,10 +108,10 @@ public class GetUserRoleQueryHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
@@ -128,10 +128,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(user);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -164,10 +164,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(user);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Contains("TestRole", result.Value!.RoleName);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;