test: adds unit, integration and security test projects for the web project

This commit is contained in:
BinaryAlley committed 2026-08-17 11:52:28 -07:00
1 parent 7b56033a15
commit 7ad7ad308e
70 files changed
+4993

No files matched your search

@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using FluentValidation.Results;
using Lumina.Presentation.Web.Common.DTO.Configuration;
using Lumina.Presentation.Web.Common.Validators;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
/// <summary>
/// Contains unit tests for the <see cref="EncryptionSettingsModelValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class EncryptionSettingsModelValidatorTests
{
private const string VALID_BASE64_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
private readonly EncryptionSettingsModelValidator _validator = new();
[Fact]
public void Validate_WhenSecretKeyIsEmpty_ShouldHaveValidationError()
{
// Arrange
EncryptionSettingsDto settings = new() { SecretKey = string.Empty };
// Act
ValidationResult result = _validator.Validate(settings);
// Assert
Assert.False(result.IsValid);
Assert.Contains(result.Errors, error => error.PropertyName == nameof(EncryptionSettingsDto.SecretKey) && error.ErrorMessage == "Encryption secret key cannot be empty!");
}
[Fact]
public void Validate_WhenSecretKeyIsNotBase64_ShouldHaveValidationError()
{
// Arrange
EncryptionSettingsDto settings = new() { SecretKey = "not-base64-key!" };
// Act
ValidationResult result = _validator.Validate(settings);
// Assert
Assert.False(result.IsValid);
Assert.Contains(result.Errors, error => error.PropertyName == nameof(EncryptionSettingsDto.SecretKey) && error.ErrorMessage == "Encryption secret key must be a base64 string!");
}
[Fact]
public void Validate_WhenSecretKeyIsValidBase64_ShouldNotHaveValidationError()
{
// Arrange
EncryptionSettingsDto settings = new() { SecretKey = VALID_BASE64_KEY };
// Act
ValidationResult result = _validator.Validate(settings);
// Assert
Assert.True(result.IsValid);
}
}
@@ -0,0 +1,75 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using FluentValidation.Results;
using Lumina.Presentation.Web.Common.DTO.Configuration;
using Lumina.Presentation.Web.Common.Validators;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
/// <summary>
/// Contains unit tests for the <see cref="ServerConfigurationModelValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ServerConfigurationModelValidatorTests
{
private readonly ServerConfigurationModelValidator _validator = new();
[Fact]
public void Validate_WhenBaseAddressIsEmpty_ShouldHaveValidationError()
{
// Arrange
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = string.Empty, Port = 5214 };
// Act
ValidationResult result = _validator.Validate(configuration);
// Assert
Assert.False(result.IsValid);
Assert.Contains(result.Errors, error => error.PropertyName == nameof(ServerConfigurationDto.BaseAddress) && error.ErrorMessage == "Base address cannot be empty!");
}
[Theory]
[InlineData((ushort)0)] // minimum allowed value
[InlineData((ushort)65535)] // maximum allowed value
public void Validate_WhenPortIsAtBoundary_ShouldNotHaveValidationError(ushort port)
{
// Arrange
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = port };
// Act
ValidationResult result = _validator.Validate(configuration);
// Assert
Assert.True(result.IsValid);
}
[Theory]
[InlineData((char)0)] // minimum allowed API version
[InlineData((char)255)] // maximum allowed API version
public void Validate_WhenApiVersionIsAtBoundary_ShouldNotHaveValidationError(char apiVersion)
{
// Arrange
ServerConfigurationDto configuration = new() { ApiVersion = apiVersion, BaseAddress = "http://localhost", Port = 5214 };
// Act
ValidationResult result = _validator.Validate(configuration);
// Assert
Assert.True(result.IsValid);
}
[Fact]
public void Validate_WhenConfigurationIsValid_ShouldNotHaveValidationError()
{
// Arrange
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = 5214 };
// Act
ValidationResult result = _validator.Validate(configuration);
// Assert
Assert.True(result.IsValid);
}
}