Adds the server-side theme repository and reworks the web theme engine onto it

This commit is contained in:
BinaryAlley committed 2026-08-19 22:50:07 -07:00
1 parent 85928f7c3c
commit bf8faba24d
136 files changed
+6942 -1197

No files matched your search

@@ -9,6 +9,7 @@ using Lumina.Presentation.Web.Common.Routes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
@@ -234,6 +235,24 @@ public class StubApiHttpClient : IApiHttpClient
throw new InvalidOperationException($"No PUT response is registered for the endpoint '{endpoint}'.");
}
/// <summary>
/// Sends a POST request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
/// </summary>
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
/// <param name="fileStream">The stream of the file to upload.</param>
/// <param name="fileName">The name of the file to upload.</param>
/// <param name="fieldName">The name of the form field carrying the file.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>The deserialized response containing the result of the POST request.</returns>
public Task<TResponse> PostMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default)
{
PostRequests.Add((endpoint, fileName));
if (_postResponseFactories.TryGetValue(endpoint, out Func<object, object>? responseFactory))
return Task.FromResult((TResponse)responseFactory(fileName));
throw new InvalidOperationException($"No POST response is registered for the endpoint '{endpoint}'.");
}
/// <summary>
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
/// </summary>
@@ -1,61 +0,0 @@
#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="CommonSettingsDtoValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CommonSettingsDtoValidatorTests
{
private readonly CommonSettingsDtoValidator _validator = new();
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="CommonSettingsDtoValidatorTests"/> class.
/// </summary>
public CommonSettingsDtoValidatorTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void Validate_WhenThemeProvided_ShouldNotHaveValidationError()
{
// Arrange
CommonSettingsDto model = _fixture.Build<CommonSettingsDto>()
.With(x => x.Theme, "Dark")
.Create();
// Act
List<Error> result = _validator.Validate(model);
// Assert
Assert.Empty(result);
}
[Fact]
public void Validate_WhenThemeNotProvided_ShouldNotHaveValidationError()
{
// Arrange
CommonSettingsDto model = _fixture.Build<CommonSettingsDto>()
.With(x => x.Theme, string.Empty)
.Create();
// Act
List<Error> result = _validator.Validate(model);
// Assert
Assert.Single(result);
Assert.Equal(Errors.Configuration.ApplicationThemeCannotBeEmpty.Description, result[0].Description);
}
}
@@ -12,7 +12,7 @@ using System.Diagnostics.CodeAnalysis;
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
/// <summary>
/// Contains unit tests for the <see cref="CommonSettingsDtoValidator"/> class.
/// Contains unit tests for the <see cref="DatabaseSettingsDtoValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DatabaseSettingsDtoValidatorTests
@@ -21,7 +21,7 @@ public class DatabaseSettingsDtoValidatorTests
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="CommonSettingsDtoValidatorTests"/> class.
/// Initializes a new instance of the <see cref="DatabaseSettingsDtoValidatorTests"/> class.
/// </summary>
public DatabaseSettingsDtoValidatorTests()
{
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.DTO.Configuration;
using Lumina.Presentation.Web.Common.Primitives;
using Lumina.Presentation.Web.Common.Validators;
using Lumina.Presentation.Web.UnitTests.Common.Setup;
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.Presentation.Web.UnitTests.Common.Validators;
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
/// <summary>
/// Contains unit tests for the <see cref="ThemeEngineOptionsDtoValidator"/> class.
@@ -17,6 +17,19 @@ public class ThemeEngineOptionsDtoValidatorTests
{
private readonly ThemeEngineOptionsDtoValidator _validator = new();
[Fact]
public void Validate_WhenAllPropertiesValid_ShouldNotHaveValidationError()
{
// Arrange
ThemeEngineOptionsDto options = new();
// Act
List<Error> result = _validator.Validate(options);
// Assert
Assert.Empty(result);
}
[Fact]
public void Validate_WhenStoragePathIsEmpty_ShouldHaveValidationError()
{
@@ -24,23 +37,25 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { StoragePath = string.Empty };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Theme storage path cannot be empty!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeStoragePathCannotBeEmpty.Description, result[0].Description);
}
[Fact]
public void Validate_WhenSettingsPathIsEmpty_ShouldHaveValidationError()
public void Validate_WhenBundledThemesPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
ThemeEngineOptionsDto options = new() { SettingsPath = string.Empty };
ThemeEngineOptionsDto options = new() { BundledThemesPath = string.Empty };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Theme settings path cannot be empty!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeBundledThemesPathCannotBeEmpty.Description, result[0].Description);
}
[Fact]
@@ -50,10 +65,11 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { DefaultThemeId = string.Empty };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Default theme Id cannot be empty!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeDefaultThemeIdCannotBeEmpty.Description, result[0].Description);
}
[Theory]
@@ -65,10 +81,11 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { MaxArchiveBytes = maxArchiveBytes };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Maximum archive size must be greater than 0!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeMaxArchiveBytesMustBePositive.Description, result[0].Description);
}
[Theory]
@@ -80,10 +97,11 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { MaxExpandedBytes = maxExpandedBytes };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Maximum expanded size must be greater than 0!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeMaxExpandedBytesMustBePositive.Description, result[0].Description);
}
[Theory]
@@ -95,10 +113,11 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { MaxSingleFileBytes = maxSingleFileBytes };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Maximum single file size must be greater than 0!"));
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeMaxSingleFileBytesMustBePositive.Description, result[0].Description);
}
[Theory]
@@ -110,22 +129,10 @@ public class ThemeEngineOptionsDtoValidatorTests
ThemeEngineOptionsDto options = new() { MaxEntries = maxEntries };
// Act
List<Error> result = _validator.TestValidate(options);
List<Error> result = _validator.Validate(options);
// Assert
result.ShouldHaveValidationError(Error.Validation(description: "Maximum entries count must be greater than 0!"));
}
[Fact]
public void Validate_WhenOptionsAreValid_ShouldNotHaveAnyValidationErrors()
{
// Arrange
ThemeEngineOptionsDto options = new();
// Act
List<Error> result = _validator.TestValidate(options);
// Assert
result.ShouldNotHaveAnyValidationErrors();
Assert.Single(result);
Assert.Equal(Errors.Configuration.ThemeMaxEntriesMustBePositive.Description, result[0].Description);
}
}