mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 22:01:10 +00:00
Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using AutoFixture;
|
|
using AutoFixture.AutoNSubstitute;
|
|
using Lumina.Domain.Common.Primitives;
|
|
using Lumina.Infrastructure.Common.Errors;
|
|
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
|
using Lumina.Infrastructure.Common.Validators;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
#endregion
|
|
|
|
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="EncryptionSettingsDtoValidator"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class EncryptionSettingsDtoValidatorTests
|
|
{
|
|
private readonly EncryptionSettingsDtoValidator _validator = new();
|
|
private readonly IFixture _fixture;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="EncryptionSettingsDtoValidatorTests"/> class.
|
|
/// </summary>
|
|
public EncryptionSettingsDtoValidatorTests()
|
|
{
|
|
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenValidBase64SecretKeyProvided_ShouldNotHaveValidationError()
|
|
{
|
|
// Arrange
|
|
EncryptionSettingsDto model = _fixture.Build<EncryptionSettingsDto>()
|
|
.With(x => x.SecretKey, "dGhpcyBpcyBhIHZhbGlkIGJhc2U2NCBzdHJpbmc=") // "this is a valid base64 string" in base64.
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenSecretKeyIsEmpty_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
EncryptionSettingsDto model = _fixture.Build<EncryptionSettingsDto>()
|
|
.With(x => x.SecretKey, string.Empty)
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.EncryptionSecretKeyCannotBeEmpty.Description, result[0].Description);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("not-a-base64-string")]
|
|
[InlineData("invalid!base64")]
|
|
[InlineData("123")]
|
|
public void Validate_WhenSecretKeyIsNotBase64_ShouldHaveValidationError(string invalidBase64)
|
|
{
|
|
// Arrange
|
|
EncryptionSettingsDto model = _fixture.Build<EncryptionSettingsDto>()
|
|
.With(x => x.SecretKey, invalidBase64)
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.EncryptionSecretKeyMustBeABase64String.Description, result[0].Description);
|
|
}
|
|
}
|