Removes FluentAssertions library from test projects, due to licensing changes

This commit is contained in:
BinaryAlley committed 2025-02-03 00:31:15 +02:00
1 parent c1100e5398
commit d46bfae4fc
235 files changed
+4468 -4725

No files matched your search

@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -76,8 +75,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.IsPasswordChanged.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.IsPasswordChanged);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(currentPassword, "hashedCurrentPassword");
@@ -99,8 +98,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -129,8 +128,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidCurrentPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidCurrentPassword, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(incorrectPassword, Uri.UnescapeDataString(user.Password));
@@ -167,8 +166,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(currentPassword, "hashedCurrentPassword");
@@ -197,8 +196,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -82,8 +81,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.IsPasswordReset.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.IsPasswordReset);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -105,8 +104,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -130,8 +129,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.PasswordResetAlreadyRequested);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.PasswordResetAlreadyRequested, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -154,8 +153,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -186,8 +185,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -222,8 +221,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -251,8 +250,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -277,8 +276,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.DidNotReceive().ValidateToken(Arg.Any<byte[]>(), Arg.Any<string>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -88,9 +87,9 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().Be(qrCodeUri);
Assert.False(result.IsError);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
_mockHashService.Received(1).HashString(command.Password!);
@@ -119,9 +118,9 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().BeNull();
Assert.False(result.IsError);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
_mockHashService.Received(1).HashString(command.Password!);
@@ -146,8 +145,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameAlreadyExists);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameAlreadyExists, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -170,8 +169,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -192,8 +191,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -15,6 +14,7 @@ using NSubstitute;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -68,8 +68,8 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -89,8 +89,8 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -110,7 +110,7 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(2);
Assert.False(result.IsError);
Assert.Equal(2, result.Value.Count());
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -85,11 +84,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeFalse();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.False(result.Value.UsesTotp);
}
[Fact]
@@ -124,11 +123,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeTrue();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.True(result.Value.UsesTotp);
}
[Fact]
@@ -144,8 +143,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
[Fact]
@@ -170,8 +169,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
[Fact]
@@ -200,8 +199,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.TempPasswordExpired);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.TempPasswordExpired, result.FirstError);
await _mockUserRepository.Received(1).UpdateAsync(Arg.Is<UserEntity>(u =>
u.TempPassword == null && u.TempPasswordCreated == null),
@@ -240,11 +239,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeFalse();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.False(result.Value.UsesTotp);
}
[Fact]
@@ -270,8 +269,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
[Fact]
@@ -303,8 +302,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
[Fact]
@@ -321,8 +320,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -351,8 +350,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedPassword);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedTempPassword);
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -79,8 +78,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
}
@@ -98,8 +97,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(DomainErrors.Users.UserDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(DomainErrors.Users.UserDoesNotExist, result.FirstError);
}
[Fact]
@@ -120,8 +119,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -166,8 +165,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.CannotRemoveLastAdmin);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.CannotRemoveLastAdmin, result.FirstError);
}
[Fact]
@@ -196,8 +195,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -246,10 +245,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(command.UserId);
result.Value.Role.Should().Be(role.RoleName);
result.Value.Permissions.Should().HaveCount(command.Permissions.Count);
Assert.False(result.IsError);
Assert.Equal(command.UserId, result.Value.UserId);
Assert.Equal(role.RoleName, result.Value.Role);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Count);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -290,8 +289,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -325,7 +324,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -53,10 +52,10 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(userId);
result.Value.Role.Should().BeEquivalentTo(authEntity.Role);
result.Value.Permissions.Should().BeEquivalentTo(authEntity.Permissions);
Assert.False(result.IsError);
Assert.Equal(userId, result.Value.UserId);
Assert.Equal(authEntity.Role, result.Value.Role);
Assert.Equal(authEntity.Permissions, result.Value.Permissions);
}
[Fact]
@@ -79,10 +78,10 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(targetUserId);
result.Value.Role.Should().BeEquivalentTo(targetAuthEntity.Role);
result.Value.Permissions.Should().BeEquivalentTo(targetAuthEntity.Permissions);
Assert.False(result.IsError);
Assert.Equal(targetUserId, result.Value.UserId);
Assert.Equal(targetAuthEntity.Role, result.Value.Role);
Assert.Equal(targetAuthEntity.Permissions, result.Value.Permissions);
}
[Fact]
@@ -102,8 +101,8 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
}
[Fact]
@@ -123,8 +122,8 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -147,7 +146,7 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -70,8 +68,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -91,8 +89,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -110,8 +108,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
[Fact]
@@ -149,8 +147,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(1);
result.Value.First().PermissionName.Should().Be(AuthorizationPermission.CanViewUsers);
Assert.False(result.IsError);
Assert.Single(result.Value);
Assert.Equal(AuthorizationPermission.CanViewUsers, result.Value.First().PermissionName);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -67,8 +66,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -88,8 +87,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -107,8 +106,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
[Fact]
@@ -127,8 +126,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -163,8 +162,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value!.RoleName.Should().Be("TestRole");
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Contains("TestRole", result.Value!.RoleName);
}
}