mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Adds authentication unit tests
This commit is contained in:
1 parent
a6dcf65d1c
commit
4f91f29b62
101 files changed
+5549
-135
No files matched your search
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ChangePasswordRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestMappingTests
|
||||
{
|
||||
private readonly ChangePasswordRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public ChangePasswordRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _fixture.CreateChangePasswordRequest();
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.CurrentPassword.Should().Be(request.CurrentPassword);
|
||||
result.NewPassword.Should().Be(request.NewPassword);
|
||||
result.NewPasswordConfirm.Should().Be(request.NewPasswordConfirm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(null, null, null, null);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.CurrentPassword.Should().BeNull();
|
||||
result.NewPassword.Should().BeNull();
|
||||
result.NewPasswordConfirm.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "oldPass", "newPass", "newPass")]
|
||||
[InlineData("", "", "", "")]
|
||||
[InlineData("testUser", null, "pass123", "pass123")]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? currentPassword,
|
||||
string? newPassword,
|
||||
string? newPasswordConfirm)
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(username, currentPassword, newPassword, newPasswordConfirm);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.CurrentPassword.Should().Be(currentPassword);
|
||||
result.NewPassword.Should().Be(newPassword);
|
||||
result.NewPasswordConfirm.Should().Be(newPasswordConfirm);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LoginRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestMappingTests
|
||||
{
|
||||
private readonly LoginRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public LoginRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = _fixture.CreateLoginRequest();
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.TotpCode.Should().Be(request.TotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(null, null);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.TotpCode.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "123456")]
|
||||
[InlineData("", "", "")]
|
||||
[InlineData("testUser", null, null)]
|
||||
[InlineData("admin", "admin123", null)]
|
||||
public void ToQuery_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(username, password, totpCode);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.TotpCode.Should().Be(totpCode);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RecoverPasswordRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestMappingTests
|
||||
{
|
||||
private readonly RecoverPasswordRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public RecoverPasswordRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _fixture.CreateRecoverPasswordRequest();
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.TotpCode.Should().Be(request.TotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(null, null);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.TotpCode.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "123456")]
|
||||
[InlineData("", "")]
|
||||
[InlineData("testUser", null)]
|
||||
[InlineData(null, "654321")]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(username, totpCode);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.TotpCode.Should().Be(totpCode);
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RegistrationRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegistrationRequestMappingTests
|
||||
{
|
||||
private readonly RegistrationRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegistrationRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public RegistrationRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToSetupCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.CreateRegistrationRequest();
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
|
||||
result.Use2fa.Should().Be(request.Use2fa);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.CreateRegistrationRequest();
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
|
||||
result.Use2fa.Should().Be(request.Use2fa);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToSetupCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.PasswordConfirm.Should().BeNull();
|
||||
result.Use2fa.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.PasswordConfirm.Should().BeNull();
|
||||
result.Use2fa.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "pass123", true)]
|
||||
[InlineData("", "", "", false)]
|
||||
[InlineData("testUser", null, null, true)]
|
||||
[InlineData(null, "pass123", "pass123", false)]
|
||||
public void ToSetupCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? passwordConfirm,
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.PasswordConfirm.Should().Be(passwordConfirm);
|
||||
result.Use2fa.Should().Be(use2fa);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "pass123", true)]
|
||||
[InlineData("", "", "", false)]
|
||||
[InlineData("testUser", null, null, true)]
|
||||
[InlineData(null, "pass123", "pass123", false)]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? passwordConfirm,
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.PasswordConfirm.Should().Be(passwordConfirm);
|
||||
result.Use2fa.Should().Be(use2fa);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user