mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CorsSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CorsSettingsDtoValidatorTests
|
||||
{
|
||||
private readonly CorsSettingsDtoValidator _validator = new();
|
||||
private readonly CorsSettingsDtoFixture _corsSettingsDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginsAreValidAbsoluteUrls_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["https://app.example.com", "http://localhost:4200"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginIsWildcard_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["*"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAllowedOriginsIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create([]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.CorsOriginsCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginHasTrailingSlash_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["https://app.example.com/"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.CorsOriginIsInvalid.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginHasNoScheme_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["app.example.com"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.CorsOriginIsInvalid.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginHasUnsupportedScheme_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["ftp://app.example.com"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.CorsOriginIsInvalid.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOneOriginIsInvalid_ShouldHaveValidationErrorForThatOrigin()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create(["https://valid.example.com", "invalid-origin"]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.CorsOriginIsInvalid.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginIsEmptyString_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CorsSettingsDto model = _corsSettingsDtoFixture.Create([""]);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, result.Count);
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.CorsOriginsCannotBeEmpty.Description);
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.CorsOriginIsInvalid.Description);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#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="DatabaseSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DatabaseSettingsDtoValidatorTests
|
||||
{
|
||||
private readonly DatabaseSettingsDtoValidator _validator = new();
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DatabaseSettingsDtoValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public DatabaseSettingsDtoValidatorTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDefaultConnectionProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DatabaseSettingsDto model = _fixture.Build<DatabaseSettingsDto>()
|
||||
.With(x => x.DefaultConnection, "dummy-connection-string")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDefaultConnectionNotProvided_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DatabaseSettingsDto model = _fixture.Build<DatabaseSettingsDto>()
|
||||
.With(x => x.DefaultConnection, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.DatabaseConnectionStringCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#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="JwtSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class JwtSettingsDtoValidatorTests
|
||||
{
|
||||
private readonly JwtSettingsDtoValidator _validator = new();
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JwtSettingsDtoValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public JwtSettingsDtoValidatorTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAllPropertiesValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, "this-is-a-very-long-secret-key-for-testing")
|
||||
.With(x => x.ExpiryMinutes, 30)
|
||||
.With(x => x.Issuer, "test-issuer")
|
||||
.With(x => x.Audience, "test-audience")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSecretKeyIsEmpty_ShouldHaveValidationErrors()
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, string.Empty)
|
||||
.With(x => x.ExpiryMinutes, 30)
|
||||
.With(x => x.Issuer, "test-issuer")
|
||||
.With(x => x.Audience, "test-audience")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, result.Count);
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.JwtSecretKeyCannotBeEmpty.Description);
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.JwtSecretKeyTooShort.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSecretKeyTooShort_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, "short-key")
|
||||
.With(x => x.ExpiryMinutes, 30)
|
||||
.With(x => x.Issuer, "test-issuer")
|
||||
.With(x => x.Audience, "test-audience")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.JwtSecretKeyTooShort.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-1)]
|
||||
[InlineData(-60)]
|
||||
public void Validate_WhenExpiryMinutesNotPositive_ShouldHaveValidationError(int minutes)
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, "this-is-a-very-long-secret-key-for-testing")
|
||||
.With(x => x.ExpiryMinutes, minutes)
|
||||
.With(x => x.Issuer, "test-issuer")
|
||||
.With(x => x.Audience, "test-audience")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.JwtExpiryMinutesMustBePositive.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenIssuerIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, "this-is-a-very-long-secret-key-for-testing")
|
||||
.With(x => x.ExpiryMinutes, 30)
|
||||
.With(x => x.Issuer, string.Empty)
|
||||
.With(x => x.Audience, "test-audience")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.JwtIssuerCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAudienceIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
JwtSettingsDto model = _fixture.Build<JwtSettingsDto>()
|
||||
.With(x => x.SecretKey, "this-is-a-very-long-secret-key-for-testing")
|
||||
.With(x => x.ExpiryMinutes, 30)
|
||||
.With(x => x.Issuer, "test-issuer")
|
||||
.With(x => x.Audience, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.JwtAudienceCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
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="MediaSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaSettingsDtoValidatorTests
|
||||
{
|
||||
private readonly MediaSettingsDtoValidator _validator = new();
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaSettingsDtoValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public MediaSettingsDtoValidatorTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRootDirectoryProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.RootDirectory, "/path/to/media")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRootDirectoryIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.RootDirectory, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRootDirectoryIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.RootDirectory, " ")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMediaLibrariesDirectoryIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.LibrariesDirectory, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMediaLibrariesDirectoryProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.LibrariesDirectory, "/path/to/media")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMediaLibrariesDirectoryIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
||||
.With(x => x.LibrariesDirectory, " ")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PluginsSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginsSettingsDtoValidatorTests
|
||||
{
|
||||
private readonly PluginsSettingsDtoValidator _validator = new();
|
||||
private readonly PluginsSettingsDtoFixture _pluginsSettingsDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDirectoryProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
PluginsSettingsDto model = _pluginsSettingsDtoFixture.Create(directory: "/path/to/plugins");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDirectoryIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
PluginsSettingsDto model = _pluginsSettingsDtoFixture.Create(directory: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.PluginsDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDirectoryIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
PluginsSettingsDto model = _pluginsSettingsDtoFixture.Create(directory: " ");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.PluginsDirectoryCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThemeEngineOptionsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeEngineOptionsDtoValidatorTests
|
||||
{
|
||||
private readonly ThemeEngineOptionsDtoValidator _validator = new();
|
||||
private readonly ThemeEngineOptionsDtoFixture _themeEngineOptionsDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAllPropertiesValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenStoragePathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(storagePath: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeStoragePathCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenBundledThemesPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(bundledThemesPath: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeBundledThemesPathCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDefaultThemeIdIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(defaultThemeId: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeDefaultThemeIdCannotBeEmpty.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0L)] // Zero, not positive.
|
||||
[InlineData(-1L)] // Negative.
|
||||
public void Validate_WhenMaxArchiveBytesIsNotPositive_ShouldHaveValidationError(long maxArchiveBytes)
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(maxArchiveBytes: maxArchiveBytes);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeMaxArchiveBytesMustBePositive.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0L)] // Zero, not positive.
|
||||
[InlineData(-1L)] // Negative.
|
||||
public void Validate_WhenMaxExpandedBytesIsNotPositive_ShouldHaveValidationError(long maxExpandedBytes)
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(maxExpandedBytes: maxExpandedBytes);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeMaxExpandedBytesMustBePositive.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0L)] // Zero, not positive.
|
||||
[InlineData(-1L)] // Negative.
|
||||
public void Validate_WhenMaxSingleFileBytesIsNotPositive_ShouldHaveValidationError(long maxSingleFileBytes)
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(maxSingleFileBytes: maxSingleFileBytes);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeMaxSingleFileBytesMustBePositive.Description, result[0].Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // Zero, not positive.
|
||||
[InlineData(-1)] // Negative.
|
||||
public void Validate_WhenMaxEntriesIsNotPositive_ShouldHaveValidationError(int maxEntries)
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(maxEntries: maxEntries);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(options);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
Assert.Equal(Errors.Configuration.ThemeMaxEntriesMustBePositive.Description, result[0].Description);
|
||||
}
|
||||
}
|
||||
+454
@@ -0,0 +1,454 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TranscodingSettingsDtoValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TranscodingSettingsDtoValidatorTests : IDisposable
|
||||
{
|
||||
private readonly TranscodingSettingsDtoValidator _validator;
|
||||
private readonly TranscodingSettingsDtoFixture _transcodingSettingsDtoFixture = new();
|
||||
private readonly MediaSettingsDtoFixture _mediaSettingsDtoFixture = new();
|
||||
private readonly PluginsSettingsDtoFixture _pluginsSettingsDtoFixture = new();
|
||||
private readonly string _sandboxRoot;
|
||||
private readonly string _mediaRoot;
|
||||
private readonly string _validCacheDirectory;
|
||||
private readonly string _pluginsDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TranscodingSettingsDtoValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public TranscodingSettingsDtoValidatorTests()
|
||||
{
|
||||
_sandboxRoot = Path.Combine(Path.GetTempPath(), "lumina-transcoding-validator-tests-" + Guid.NewGuid().ToString("N"));
|
||||
_mediaRoot = Path.Combine(_sandboxRoot, "media");
|
||||
_validCacheDirectory = Path.Combine(_sandboxRoot, "cache");
|
||||
_pluginsDirectory = Path.Combine(_sandboxRoot, "plugins");
|
||||
Directory.CreateDirectory(_mediaRoot);
|
||||
Directory.CreateDirectory(_validCacheDirectory);
|
||||
Directory.CreateDirectory(_pluginsDirectory);
|
||||
|
||||
// The real path service is used, with the real path strategy of the current platform, so containment follows the file system rules of the host.
|
||||
IPlatformContext platformContext = Substitute.For<IPlatformContext>();
|
||||
IPathStrategy pathStrategy = OperatingSystem.IsWindows()
|
||||
? new WindowsPathStrategy(new FileSystem())
|
||||
: new UnixPathStrategy(new FileSystem());
|
||||
platformContext.PathStrategy.Returns(pathStrategy);
|
||||
IPlatformContextManager platformContextManager = Substitute.For<IPlatformContextManager>();
|
||||
platformContextManager.GetCurrentContext().Returns(platformContext);
|
||||
IPathService pathService = new PathService(platformContextManager);
|
||||
|
||||
// An absolute root directory pins the media root that is served by the media route, because Path.Combine returns its second argument when it is rooted.
|
||||
MediaSettingsDto mediaSettings = _mediaSettingsDtoFixture.Create(rootDirectory: _mediaRoot);
|
||||
PluginsSettingsDto pluginsSettings = _pluginsSettingsDtoFixture.Create(directory: _pluginsDirectory);
|
||||
_validator = new TranscodingSettingsDtoValidator(Options.Create(mediaSettings), Options.Create(pluginsSettings), pathService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSettingsAreValid_ShouldNotHaveAnyValidationError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A missing ffmpeg path.
|
||||
[InlineData("")] // An empty ffmpeg path.
|
||||
[InlineData(" ")] // A whitespace ffmpeg path.
|
||||
public void Validate_WhenFfmpegPathIsEmpty_ShouldHaveFfmpegPathCannotBeEmptyError(string? ffmpegPath)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(ffmpegPath: ffmpegPath, includeFfmpegPath: ffmpegPath is not null);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingFfmpegPathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // A job count of zero disables normalization.
|
||||
[InlineData(-1)] // A negative job count disables normalization.
|
||||
public void Validate_WhenMaxConcurrentJobsIsNotPositive_ShouldHaveMaxConcurrentJobsMustBePositiveError(int maxConcurrentJobs)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: maxConcurrentJobs, maxConcurrentJobsPerUser: 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxConcurrentJobsIsTooLarge_ShouldHaveMaxConcurrentJobsIsTooLargeError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: 65, maxConcurrentJobsPerUser: 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsIsTooLarge.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxConcurrentJobsIsTheMaximum_ShouldNotHaveMaxConcurrentJobsErrors()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: 64, maxConcurrentJobsPerUser: 64);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsIsTooLarge.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // A per-user job count of zero never admits a normalization.
|
||||
[InlineData(-1)] // A negative per-user job count never admits a normalization.
|
||||
public void Validate_WhenMaxConcurrentJobsPerUserIsNotPositive_ShouldHaveMaxConcurrentJobsPerUserMustBePositiveError(int maxConcurrentJobsPerUser)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: 8, maxConcurrentJobsPerUser: maxConcurrentJobsPerUser);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsPerUserMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxConcurrentJobsPerUserIsTooLarge_ShouldHaveMaxConcurrentJobsPerUserIsTooLargeError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: 64, maxConcurrentJobsPerUser: 65);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsPerUserIsTooLarge.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxConcurrentJobsPerUserExceedsTheGlobalLimit_ShouldHaveMaxConcurrentJobsPerUserExceedsGlobalError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxConcurrentJobs: 8, maxConcurrentJobsPerUser: 16);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsPerUserExceedsGlobal.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingMaxConcurrentJobsPerUserIsTooLarge.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // A cache with no capacity cannot hold a normalized track.
|
||||
[InlineData(-1)] // A negative cache size is not a capacity.
|
||||
public void Validate_WhenMaxCacheBytesIsNotPositive_ShouldHaveMaxCacheBytesMustBePositiveError(long maxCacheBytes)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(maxCacheBytes: maxCacheBytes);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingMaxCacheBytesMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // A job timeout of zero stops every job immediately.
|
||||
[InlineData(-1)] // A negative job timeout stops every job immediately.
|
||||
public void Validate_WhenJobTimeoutSecondsIsNotPositive_ShouldHaveJobTimeoutMustBePositiveError(int jobTimeoutSeconds)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(jobTimeoutSeconds: jobTimeoutSeconds);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingJobTimeoutMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenJobTimeoutSecondsIsTooLong_ShouldHaveJobTimeoutIsTooLongError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(jobTimeoutSeconds: 86_401);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingJobTimeoutIsTooLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenJobTimeoutSecondsIsTheMaximum_ShouldNotHaveJobTimeoutErrors()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(jobTimeoutSeconds: 86_400);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingJobTimeoutIsTooLong.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingJobTimeoutMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // An eviction grace of zero protects nothing.
|
||||
[InlineData(-1)] // A negative eviction grace protects nothing.
|
||||
public void Validate_WhenEvictionGraceSecondsIsNotPositive_ShouldHaveEvictionGraceSecondsMustBePositiveError(int evictionGraceSeconds)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(evictionGraceSeconds: evictionGraceSeconds);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingEvictionGraceSecondsMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEvictionGraceSecondsIsTooLong_ShouldHaveEvictionGraceSecondsIsTooLongError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(evictionGraceSeconds: 86_401);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingEvictionGraceSecondsIsTooLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEvictionGraceSecondsIsTheMaximum_ShouldNotHaveEvictionGraceSecondsErrors()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(evictionGraceSeconds: 86_400);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingEvictionGraceSecondsIsTooLong.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingEvictionGraceSecondsMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsMalformed_ShouldHaveCacheDirectoryIsInvalidError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: "bad\0path");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsInvalid.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsInsideMediaRoot.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryContainsMediaRoot.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsUnsafeLocation.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsInsideTheMediaRoot_ShouldHaveCacheDirectoryIsInsideMediaRootError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: Path.Combine(_mediaRoot, "cache"));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsInsideMediaRoot.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryContainsMediaRoot.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryContainsTheMediaRoot_ShouldHaveCacheDirectoryContainsMediaRootError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: _sandboxRoot);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryContainsMediaRoot.Description);
|
||||
Assert.DoesNotContain(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsInsideMediaRoot.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsAFileSystemRoot_ShouldHaveCacheDirectoryIsUnsafeLocationError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: Path.GetPathRoot(_mediaRoot)!);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsUnsafeLocation.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsTheApplicationBaseDirectory_ShouldHaveCacheDirectoryIsUnsafeLocationError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: AppContext.BaseDirectory);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsUnsafeLocation.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsTheLogsDirectory_ShouldHaveCacheDirectoryIsUnsafeLocationError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: Path.Combine(AppContext.BaseDirectory, "logs"));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsUnsafeLocation.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsThePluginsDirectory_ShouldHaveCacheDirectoryIsUnsafeLocationError()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: _pluginsDirectory);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Contains(result, error => error.Description == Errors.Configuration.TranscodingCacheDirectoryIsUnsafeLocation.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCacheDirectoryIsAValidExternalDirectory_ShouldNotHaveCacheDirectoryErrors()
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: _validCacheDirectory);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // No configured directory, so the default temporary directory is used.
|
||||
[InlineData(" ")] // A whitespace directory, so the default temporary directory is used.
|
||||
public void Validate_WhenCacheDirectoryIsNotConfigured_ShouldOnlyValidateTheDefaultDirectory(string? cacheDirectory)
|
||||
{
|
||||
// Arrange
|
||||
TranscodingSettingsDto model = CreateSettings(cacheDirectory: cacheDirectory, includeCacheDirectory: cacheDirectory is not null);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the temporary directories the containment tests use.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(_sandboxRoot))
|
||||
Directory.Delete(_sandboxRoot, recursive: true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
// A temporary directory that cannot be removed does not fail the test.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates settings that are valid unless an argument overrides a single rule under test.
|
||||
/// </summary>
|
||||
/// <param name="ffmpegPath">The file name or path of the ffmpeg binary.</param>
|
||||
/// <param name="maxConcurrentJobs">The maximum number of normalization jobs that may run at the same time.</param>
|
||||
/// <param name="maxConcurrentJobsPerUser">The maximum number of normalization jobs a single user may have running at the same time.</param>
|
||||
/// <param name="maxCacheBytes">The maximum total size of the normalized audio cache, in bytes.</param>
|
||||
/// <param name="jobTimeoutSeconds">The maximum duration of a single normalization job, in seconds.</param>
|
||||
/// <param name="evictionGraceSeconds">The period during which a cache entry is protected from eviction, in seconds.</param>
|
||||
/// <param name="cacheDirectory">The directory where normalized audio is cached.</param>
|
||||
/// <param name="includeCacheDirectory">Whether the cache directory should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeFfmpegPath">Whether the ffmpeg path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created settings.</returns>
|
||||
private TranscodingSettingsDto CreateSettings(
|
||||
string? ffmpegPath = "ffmpeg",
|
||||
int? maxConcurrentJobs = 8,
|
||||
int? maxConcurrentJobsPerUser = 4,
|
||||
long? maxCacheBytes = 2L * 1024 * 1024 * 1024,
|
||||
int? jobTimeoutSeconds = 900,
|
||||
int? evictionGraceSeconds = 120,
|
||||
string? cacheDirectory = null,
|
||||
bool includeCacheDirectory = true,
|
||||
bool includeFfmpegPath = true)
|
||||
{
|
||||
return _transcodingSettingsDtoFixture.Create(
|
||||
ffmpegPath: ffmpegPath,
|
||||
maxConcurrentJobs: maxConcurrentJobs,
|
||||
maxConcurrentJobsPerUser: maxConcurrentJobsPerUser,
|
||||
maxCacheBytes: maxCacheBytes,
|
||||
jobTimeoutSeconds: jobTimeoutSeconds,
|
||||
evictionGraceSeconds: evictionGraceSeconds,
|
||||
cacheDirectory: cacheDirectory ?? _validCacheDirectory,
|
||||
includeCacheDirectory: includeCacheDirectory,
|
||||
includeFfmpegPath: includeFfmpegPath);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user