mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Standardizes test conventions and documentation
This commit is contained in:
1 parent
7aeed04255
commit
f42dc709de
190 files changed
+2180
-2814
No files matched your search
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Api;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
@@ -26,7 +27,7 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Api;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ApiHttpClientTests
|
||||
{
|
||||
private const string TEST_ENCRYPTION_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly ServerConfigurationDtoFixture _serverConfigurationDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync_WhenApiReturnsSuccess_ShouldDeserializeResponseContent()
|
||||
@@ -36,7 +37,7 @@ public class ApiHttpClientTests
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
Lumina.Presentation.Web.Common.DTO.Libraries.LibraryDto[] result = await sut.GetAsync<Lumina.Presentation.Web.Common.DTO.Libraries.LibraryDto[]>("libraries", CancellationToken.None);
|
||||
Web.Common.DTO.Libraries.LibraryDto[] result = await sut.GetAsync<Web.Common.DTO.Libraries.LibraryDto[]>("libraries", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
@@ -152,21 +153,35 @@ public class ApiHttpClientTests
|
||||
Assert.Equal("image/png", blob.ContentType);
|
||||
}
|
||||
|
||||
private static ApiHttpClient CreateSut(TestApiHttpMessageHandler messageHandler, string? token = null)
|
||||
/// <summary>
|
||||
/// Creates the system under test configured with the provided message handler.
|
||||
/// </summary>
|
||||
/// <param name="messageHandler">The message handler backing the inner <see cref="HttpClient"/>.</param>
|
||||
/// <param name="token">Optional token claim to place on the current HTTP context user.</param>
|
||||
/// <returns>The created <see cref="ApiHttpClient"/>.</returns>
|
||||
private ApiHttpClient CreateSut(TestApiHttpMessageHandler messageHandler, string? token = null)
|
||||
{
|
||||
HttpClient httpClient = new(messageHandler);
|
||||
IHttpContextAccessor httpContextAccessor = Substitute.For<IHttpContextAccessor>();
|
||||
if (token is not null)
|
||||
{
|
||||
DefaultHttpContext httpContext = new();
|
||||
httpContext.User = new ClaimsPrincipal(new ClaimsIdentity([new Claim("Token", token)], "TestAuthentication"));
|
||||
DefaultHttpContext httpContext = new()
|
||||
{
|
||||
User = new ClaimsPrincipal(new ClaimsIdentity([new Claim("Token", token)], "TestAuthentication"))
|
||||
};
|
||||
httpContextAccessor.HttpContext.Returns(httpContext);
|
||||
}
|
||||
IOptionsSnapshot<ServerConfigurationDto> serverConfigurationOptions = Substitute.For<IOptionsSnapshot<ServerConfigurationDto>>();
|
||||
serverConfigurationOptions.Value.Returns(new ServerConfigurationDto { ApiVersion = '1', BaseAddress = "http://localhost", Port = 5214 });
|
||||
serverConfigurationOptions.Value.Returns(_serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: 5214));
|
||||
return new ApiHttpClient(httpClient, httpContextAccessor, serverConfigurationOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="HttpResponseMessage"/> with the given status code and JSON body.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP status code of the response.</param>
|
||||
/// <param name="json">The JSON payload of the response body.</param>
|
||||
/// <returns>The created <see cref="HttpResponseMessage"/>.</returns>
|
||||
private static HttpResponseMessage CreateJsonResponse(HttpStatusCode statusCode, string json)
|
||||
{
|
||||
return new HttpResponseMessage(statusCode)
|
||||
|
||||
+7
-5
@@ -3,6 +3,7 @@ using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Responses.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -23,6 +24,7 @@ public class AuthorizationServiceTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly AuthorizationService _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly GetAuthorizationResponseFixture _getAuthorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthorizationServiceTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", [AuthorizationPermission.CanCreateLibraries]));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: [AuthorizationPermission.CanCreateLibraries]));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None);
|
||||
@@ -57,7 +59,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", [AuthorizationPermission.CanViewUsers]));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: [AuthorizationPermission.CanViewUsers]));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None);
|
||||
@@ -71,7 +73,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: []));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.IsInRoleAsync("Admin", CancellationToken.None);
|
||||
@@ -85,7 +87,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "User", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "User", permissions: []));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.IsInRoleAsync("Admin", CancellationToken.None);
|
||||
@@ -99,7 +101,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: []));
|
||||
|
||||
// Act
|
||||
await _sut.HasPermissionAsync(AuthorizationPermission.CanViewUsers, CancellationToken.None);
|
||||
|
||||
+10
-8
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Security;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -15,6 +16,7 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Security;
|
||||
public class CryptographyServiceTests
|
||||
{
|
||||
private const string TEST_ENCRYPTION_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
private readonly CryptographyService _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,7 +24,7 @@ public class CryptographyServiceTests
|
||||
/// </summary>
|
||||
public CryptographyServiceTests()
|
||||
{
|
||||
EncryptionSettingsDto settings = new() { SecretKey = TEST_ENCRYPTION_KEY };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: TEST_ENCRYPTION_KEY);
|
||||
_sut = new CryptographyService(Options.Create(settings));
|
||||
}
|
||||
|
||||
@@ -30,25 +32,25 @@ public class CryptographyServiceTests
|
||||
public void Encrypt_WhenCalled_ShouldReturnCiphertextThatDecryptsToPlaintext()
|
||||
{
|
||||
// Arrange
|
||||
const string plaintext = "sensitive-data";
|
||||
const string PLAINTEXT = "sensitive-data";
|
||||
|
||||
// Act
|
||||
string ciphertext = _sut.Encrypt(plaintext);
|
||||
string ciphertext = _sut.Encrypt(PLAINTEXT);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(plaintext, ciphertext);
|
||||
Assert.Equal(plaintext, _sut.Decrypt(ciphertext));
|
||||
Assert.NotEqual(PLAINTEXT, ciphertext);
|
||||
Assert.Equal(PLAINTEXT, _sut.Decrypt(ciphertext));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Encrypt_WhenCalledTwice_ShouldReturnDifferentCiphertexts()
|
||||
{
|
||||
// Arrange
|
||||
const string plaintext = "sensitive-data";
|
||||
const string PLAINTEXT = "sensitive-data";
|
||||
|
||||
// Act
|
||||
string firstCiphertext = _sut.Encrypt(plaintext);
|
||||
string secondCiphertext = _sut.Encrypt(plaintext);
|
||||
string firstCiphertext = _sut.Encrypt(PLAINTEXT);
|
||||
string secondCiphertext = _sut.Encrypt(PLAINTEXT);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstCiphertext, secondCiphertext);
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Validators;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.UnitTests.Common.Setup;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -16,13 +17,14 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
|
||||
public class EncryptionSettingsModelValidatorTests
|
||||
{
|
||||
private const string VALID_BASE64_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
private readonly EncryptionSettingsDtoValidator _validator = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSecretKeyIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = string.Empty };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
@@ -35,7 +37,7 @@ public class EncryptionSettingsModelValidatorTests
|
||||
public void Validate_WhenSecretKeyIsNotBase64_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = "not-base64-key!" };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: "not-base64-key!");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
@@ -48,7 +50,7 @@ public class EncryptionSettingsModelValidatorTests
|
||||
public void Validate_WhenSecretKeyIsValidBase64_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = VALID_BASE64_KEY };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: VALID_BASE64_KEY);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
|
||||
+6
-4
@@ -2,6 +2,7 @@
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Validators;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.UnitTests.Common.Setup;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -15,13 +16,14 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ServerConfigurationModelValidatorTests
|
||||
{
|
||||
private readonly ServerConfigurationDtoFixture _serverConfigurationDtoFixture = new();
|
||||
private readonly ServerConfigurationDtoValidator _validator = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenBaseAddressIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = string.Empty, Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: string.Empty, port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -36,7 +38,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenPortIsAtBoundary_ShouldNotHaveValidationError(ushort port)
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = port };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: port);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -51,7 +53,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenApiVersionIsAtBoundary_ShouldNotHaveValidationError(char apiVersion)
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = apiVersion, BaseAddress = "http://localhost", Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: apiVersion, baseAddress: "http://localhost", port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -64,7 +66,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenConfigurationIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Requests.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Authorization.Roles.AddRole;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -29,6 +30,9 @@ public class AddRoleEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly AddRoleEndpoint _sut;
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
private readonly RolePermissionsDtoFixture _rolePermissionsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpointTests"/> class.
|
||||
@@ -44,7 +48,7 @@ public class AddRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create();
|
||||
RolePermissionsDto expectedResponse = new(new RoleDto(Guid.NewGuid(), request.RoleName!), [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]);
|
||||
RolePermissionsDto expectedResponse = _rolePermissionsDtoFixture.Create(role: _roleDtoFixture.Create(id: Guid.NewGuid(), roleName: request.RoleName!), permissions: [_permissionDtoFixture.Create(id: Guid.NewGuid(), permission: AuthorizationPermission.CanViewUsers)]);
|
||||
_mockApiHttpClient.PostAsync<RolePermissionsDto, AddRoleRequest>(Arg.Any<string>(), Arg.Any<AddRoleRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+5
-7
@@ -1,15 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DeleteTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -25,6 +24,7 @@ public class DeleteThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly DeleteThemeEndpoint _sut;
|
||||
private readonly DeleteThemeRequestFixture _deleteThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpointTests"/> class.
|
||||
@@ -43,14 +43,12 @@ public class DeleteThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
using (System.Text.Json.JsonDocument jsonDocument = System.Text.Json.JsonDocument.Parse(body))
|
||||
{
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +59,7 @@ public class DeleteThemeEndpointTests
|
||||
string expectedEndpoint = ApiRoutes.Themes.DELETE_THEME.Replace("{themeId}", themeId);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).DeleteAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
@@ -74,7 +72,7 @@ public class DeleteThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+9
-8
@@ -2,16 +2,15 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DownloadTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -26,6 +25,8 @@ public class DownloadThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly DownloadThemeEndpoint _sut;
|
||||
private readonly GetThemeArchiveRequestFixture _getThemeArchiveRequestFixture = new();
|
||||
private readonly BlobDataDtoFixture _blobDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DownloadThemeEndpointTests"/> class.
|
||||
@@ -43,10 +44,10 @@ public class DownloadThemeEndpointTests
|
||||
// Arrange
|
||||
string themeId = "editorial-paper";
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [0x50, 0x4B, 0x03, 0x04], ContentType = "application/zip" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [0x50, 0x4B, 0x03, 0x04], contentType: "application/zip"));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
FileStreamHttpResult fileResult = Assert.IsType<FileStreamHttpResult>(result);
|
||||
@@ -61,10 +62,10 @@ public class DownloadThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
string expectedEndpoint = ApiRoutes.Themes.GET_THEME_ARCHIVE.Replace("{themeId}", themeId);
|
||||
_mockApiHttpClient.GetBlobAsync(expectedEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [1, 2, 3], ContentType = "application/zip" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [1, 2, 3], contentType: "application/zip"));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetBlobAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
@@ -77,7 +78,7 @@ public class DownloadThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+5
-5
@@ -2,15 +2,14 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.RestoreTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -26,6 +25,7 @@ public class RestoreThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RestoreThemeEndpoint _sut;
|
||||
private readonly RestoreThemeRequestFixture _restoreThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreThemeEndpointTests"/> class.
|
||||
@@ -44,7 +44,7 @@ public class RestoreThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
@@ -62,7 +62,7 @@ public class RestoreThemeEndpointTests
|
||||
string expectedEndpoint = ApiRoutes.Themes.RESTORE_THEME.Replace("{themeId}", themeId);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ThemeResponseDto, object>(expectedEndpoint, Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
@@ -75,7 +75,7 @@ public class RestoreThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+4
-4
@@ -2,16 +2,15 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -28,6 +27,7 @@ public class SetCurrentThemeEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly SetCurrentThemeEndpoint _sut;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
||||
@@ -48,7 +48,7 @@ public class SetCurrentThemeEndpointTests
|
||||
.Returns(_themeResponseDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetCurrentThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
@@ -68,7 +68,7 @@ public class SetCurrentThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetCurrentThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.FileSystemManagement.Directories.GetDirectories;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -27,6 +28,7 @@ public class GetDirectoriesEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly GetDirectoriesEndpoint _sut;
|
||||
private readonly GetDirectoriesRequestFixture _getDirectoriesRequestFixture = new();
|
||||
private readonly DirectoryDtoFixture _directoryDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class GetDirectoriesEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create(path: "/media", includeHiddenElements: true);
|
||||
DirectoryDto[] expectedDirectories = [new DirectoryDto { Path = "/media/books", Name = "books" }];
|
||||
DirectoryDto[] expectedDirectories = [_directoryDtoFixture.Create(path: "/media/books", name: "books")];
|
||||
_mockApiHttpClient.GetAsync<DirectoryDto[]>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedDirectories);
|
||||
|
||||
|
||||
+4
-2
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.FileSystemManagement.Path.ValidatePath;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -27,6 +28,7 @@ public class ValidatePathEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly ValidatePathEndpoint _sut;
|
||||
private readonly ValidatePathRequestFixture _validatePathRequestFixture = new();
|
||||
private readonly PathValidDtoFixture _pathValidDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(path: "/media/books");
|
||||
_mockApiHttpClient.GetAsync<PathValidDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidDto(true));
|
||||
.Returns(_pathValidDtoFixture.Create(isValid: true));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -63,7 +65,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(path: "C:/invalid|path");
|
||||
_mockApiHttpClient.GetAsync<PathValidDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidDto(false));
|
||||
.Returns(_pathValidDtoFixture.Create(isValid: false));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
+14
-13
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Enums.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Libraries;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetLibraryItems;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -29,6 +30,8 @@ public class GetLibraryItemsEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly GetLibraryItemsEndpoint _sut;
|
||||
private readonly GetBooksLiteRequestFixture _getBooksLiteRequestFixture = new();
|
||||
private readonly PaginatedBookLiteDtoFixture _paginatedBookLiteDtoFixture = new();
|
||||
private readonly BookLiteDtoFixture _bookLiteDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryItemsEndpointTests"/> class.
|
||||
@@ -48,11 +51,11 @@ public class GetLibraryItemsEndpointTests
|
||||
perPage: 48,
|
||||
searchTerm: "the hobbit",
|
||||
filterAlphaKey: "H",
|
||||
ignoreThePrefixForAlphaPicker: true,
|
||||
shouldIgnoreThePrefixForAlphaPicker: true,
|
||||
sortBy: "title",
|
||||
sortOrder: SortOrder.Ascending);
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedBookLiteDto());
|
||||
.Returns(_paginatedBookLiteDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -66,7 +69,7 @@ public class GetLibraryItemsEndpointTests
|
||||
endpoint.Contains("perPage=48") &&
|
||||
endpoint.Contains("searchTerm=the%20hobbit") &&
|
||||
endpoint.Contains("filterAlphaKey=H") &&
|
||||
endpoint.Contains("ignoreThePrefixForAlphaPicker=True") &&
|
||||
endpoint.Contains("shouldIgnoreThePrefixForAlphaPicker=True") &&
|
||||
endpoint.Contains("sortBy=title") &&
|
||||
endpoint.Contains("sortOrder=Ascending")),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -78,7 +81,7 @@ public class GetLibraryItemsEndpointTests
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedBookLiteDto());
|
||||
.Returns(_paginatedBookLiteDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -87,7 +90,7 @@ public class GetLibraryItemsEndpointTests
|
||||
await _mockApiHttpClient.Received(1).GetAsync<PaginatedBookLiteDto>(
|
||||
Arg.Is<string>(endpoint =>
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE, StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith($"libraryId={request.LibraryId}&ignoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith($"libraryId={request.LibraryId}&shouldIgnoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
!endpoint.Contains("currentPage=") &&
|
||||
!endpoint.Contains("searchTerm=") &&
|
||||
!endpoint.Contains("sortBy=")),
|
||||
@@ -99,14 +102,12 @@ public class GetLibraryItemsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
PaginatedBookLiteDto expectedResponse = new()
|
||||
{
|
||||
CurrentPage = 1,
|
||||
PerPage = 48,
|
||||
Count = 1,
|
||||
NumberOfPages = 1,
|
||||
Data = [new BookLiteDto { Id = Guid.NewGuid(), Title = "Test Book" }]
|
||||
};
|
||||
PaginatedBookLiteDto expectedResponse = _paginatedBookLiteDtoFixture.Create(
|
||||
data: [_bookLiteDtoFixture.Create(title: "Test Book")],
|
||||
currentPage: 1,
|
||||
perPage: 48,
|
||||
count: 1,
|
||||
numberOfPages: 1);
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+8
-6
@@ -5,19 +5,19 @@ using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Index;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,6 +38,8 @@ public class BooksIndexViewEndpointTests
|
||||
private readonly IStringLocalizer _mockStringLocalizer;
|
||||
private readonly BooksIndexViewEndpoint _sut;
|
||||
private readonly LibraryDtoFixture _libraryDtoFixture = new();
|
||||
private readonly GetBooksViewRequestFixture _getBooksViewRequestFixture = new();
|
||||
private readonly ThemePageRenderResultDtoFixture _themePageRenderResultDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksIndexViewEndpointTests"/> class.
|
||||
@@ -63,7 +65,7 @@ public class BooksIndexViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED).Returns("http://localhost/en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: null), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -82,10 +84,10 @@ public class BooksIndexViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Books.GET_LIBRARY_ITEMS).Returns("http://localhost/en-us/library/written-content-library/books-library/books/api-get-library-items");
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Settings.GET_USER_SETTINGS).Returns("http://localhost/en-us/tools/settings/api-get-user-settings");
|
||||
_mockThemePageRenderer.RenderAsync(Arg.Any<ThemePageDto>(), Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ThemePageRenderResultDto("<section>content</section>", "<script>script</script>")));
|
||||
.Returns(Result.From(_themePageRenderResultDtoFixture.Create(content: "<section>content</section>", script: "<script>script</script>")));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(expectedLibrary.Id), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: expectedLibrary.Id), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
@@ -115,7 +117,7 @@ public class BooksIndexViewEndpointTests
|
||||
.Returns(Result<ThemePageRenderResultDto>.Failure(Error.Failure("Theme.Render", "The page could not be rendered.")));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(expectedLibrary.Id), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: expectedLibrary.Id), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
|
||||
+7
-6
@@ -1,14 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Themes.ThemeAssets;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,6 +23,8 @@ public class ThemeAssetsEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly ThemeAssetsEndpoint _sut;
|
||||
private readonly GetThemeAssetRequestFixture _getThemeAssetRequestFixture = new();
|
||||
private readonly BlobDataDtoFixture _blobDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeAssetsEndpointTests"/> class.
|
||||
@@ -39,10 +40,10 @@ public class ThemeAssetsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [1, 2, 3], ContentType = "text/css" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [1, 2, 3], contentType: "text/css"));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeAssetRequest(ThemeId: "editorial-paper", Path: "assets/style.css"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeAssetRequestFixture.Create(themeId: "editorial-paper", path: "assets/style.css"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
FileContentHttpResult fileResult = Assert.IsType<FileContentHttpResult>(result);
|
||||
@@ -57,7 +58,7 @@ public class ThemeAssetsEndpointTests
|
||||
public async Task ExecuteAsync_WhenAssetPathMissing_ShouldReturnProblem()
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeAssetRequest(ThemeId: "editorial-paper", Path: null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeAssetRequestFixture.Create(themeId: "editorial-paper", path: null), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+5
-4
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Tools;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Language.SetLanguage;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Tools;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -20,6 +20,7 @@ namespace Lumina.Presentation.Web.UnitTests.Core.Endpoints.Tools.Language.SetLan
|
||||
public class SetLanguageEndpointTests
|
||||
{
|
||||
private readonly SetLanguageEndpoint _sut;
|
||||
private readonly SetLanguageRequestFixture _setLanguageRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLanguageEndpointTests"/> class.
|
||||
@@ -36,7 +37,7 @@ public class SetLanguageEndpointTests
|
||||
TestHttpContextFactory.ConfigureCulture(_sut.HttpContext, "en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("de-DE", null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "de-DE"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -54,7 +55,7 @@ public class SetLanguageEndpointTests
|
||||
TestHttpContextFactory.ConfigureCulture(_sut.HttpContext, "en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("de-DE", "/en-us/tools/settings"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "de-DE", returnUrl: "/en-us/tools/settings"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -69,7 +70,7 @@ public class SetLanguageEndpointTests
|
||||
_sut.HttpContext.Request.PathBase = "/lumina";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("fr-FR", "/en-us/tools/settings"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "fr-FR", returnUrl: "/en-us/tools/settings"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
|
||||
+6
-6
@@ -1,15 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Requests.UsersManagement.Authentication;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.Login;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement.Authentication;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -26,6 +25,7 @@ public class LoginViewEndpointTests
|
||||
{
|
||||
private readonly IUrlService _mockUrlService;
|
||||
private readonly LoginViewEndpoint _sut;
|
||||
private readonly LoginViewRequestFixture _loginViewRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginViewEndpointTests"/> class.
|
||||
@@ -45,7 +45,7 @@ public class LoginViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED).Returns("http://localhost/en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -57,7 +57,7 @@ public class LoginViewEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuperAdminSetupPending_ShouldRedirectToRegisterView()
|
||||
{
|
||||
// Arrange
|
||||
Microsoft.AspNetCore.Http.ISession session = Substitute.For<Microsoft.AspNetCore.Http.ISession>();
|
||||
ISession session = Substitute.For<ISession>();
|
||||
byte[] pendingBytes = Encoding.UTF8.GetBytes("true");
|
||||
#pragma warning disable CS8601 // possible null reference assignment in the NSubstitute out-argument stub
|
||||
session.TryGetValue(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, out Arg.Any<byte[]>()).Returns(callInfo =>
|
||||
@@ -70,7 +70,7 @@ public class LoginViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Authentication.REGISTER_VIEW).Returns("http://localhost/en-us/auth/register");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -85,7 +85,7 @@ public class LoginViewEndpointTests
|
||||
TestHttpContextFactory.ConfigureSession(_sut.HttpContext, TestHttpContextFactory.CreateSession());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
|
||||
+3
-1
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.RecoverPassword;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
@@ -26,6 +27,7 @@ public class RecoverPasswordEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly RecoverPasswordResponseFixture _recoverPasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordEndpointTests"/> class.
|
||||
@@ -41,7 +43,7 @@ public class RecoverPasswordEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
RecoverPasswordResponse expectedResponse = new(true);
|
||||
RecoverPasswordResponse expectedResponse = _recoverPasswordResponseFixture.Create(isPasswordReset: true);
|
||||
_mockApiHttpClient.PostAsync<RecoverPasswordResponse, RecoverPasswordRequest>(Arg.Any<string>(), Arg.Any<RecoverPasswordRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+4
-2
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.Register;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
@@ -26,6 +27,7 @@ public class RegisterEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegisterRequestFixture _registerRequestFixture = new();
|
||||
private readonly RegisterResponseFixture _registerResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegisterRequest request = _registerRequestFixture.Create(registrationType: "Admin");
|
||||
_mockApiHttpClient.PostAsync<RegisterResponse, RegisterRequest>(Arg.Any<string>(), Arg.Any<RegisterRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new RegisterResponse(request.Username, null));
|
||||
.Returns(_registerResponseFixture.Create(username: request.Username));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -63,7 +65,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegisterRequest request = _registerRequestFixture.Create(registrationType: "User");
|
||||
_mockApiHttpClient.PostAsync<RegisterResponse, RegisterRequest>(Arg.Any<string>(), Arg.Any<RegisterRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new RegisterResponse(request.Username, null));
|
||||
.Returns(_registerResponseFixture.Create(username: request.Username));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
+28
-11
@@ -11,7 +11,6 @@ using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
@@ -46,6 +45,9 @@ public class ThemeLayoutRendererTests
|
||||
private readonly IView _mockAudioPlayerView;
|
||||
private readonly IView _mockScriptsView;
|
||||
private readonly IView _mockNavMenuView;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly ThemeTemplateResponseDtoFixture _themeTemplateResponseDtoFixture = new();
|
||||
private readonly ThemeLayoutPageDtoFixture _themeLayoutPageDtoFixture = new();
|
||||
private readonly ThemeLayoutRenderer _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -90,9 +92,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: TestHttpContextFactory.CreateAuthenticatedUser()));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{assetBase}}|{{{appHead}}}|{{{nav}}}|{{{content}}}|{{{audioPlayer}}}|{{{appScripts}}}|{{{scripts}}}|{{mainStyle}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", "<page-script>");
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: "<page-script>");
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -107,9 +109,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{assetBase}}|{{{appHead}}}|{{{nav}}}|{{{content}}}|{{{audioPlayer}}}|{{{appScripts}}}|{{{scripts}}}|{{mainStyle}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", "<page-script>");
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: "<page-script>");
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -124,9 +126,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{{nav}}}", navTemplate: "{{#unclosed}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", string.Empty);
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: string.Empty);
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -142,9 +144,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", string.Empty);
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: string.Empty);
|
||||
string layoutEndpoint = ApiRoutes.Themes.GET_THEME_TEMPLATE
|
||||
.Replace("{themeId}", "editorial")
|
||||
.Replace("{*pageKey}", "shared/layout");
|
||||
@@ -160,6 +162,12 @@ public class ThemeLayoutRendererTests
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ThemeTemplateResponseDto>(navEndpoint, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stubs the API responses that return the layout and navigation menu templates of the given theme.
|
||||
/// </summary>
|
||||
/// <param name="theme">The theme whose layout and navigation menu templates are stubbed.</param>
|
||||
/// <param name="layoutTemplate">The template returned for the layout document.</param>
|
||||
/// <param name="navTemplate">The template returned for the navigation menu document.</param>
|
||||
private void SetupRenderDocuments(ThemeResponseDto theme, string layoutTemplate, string navTemplate)
|
||||
{
|
||||
string layoutEndpoint = ApiRoutes.Themes.GET_THEME_TEMPLATE
|
||||
@@ -169,11 +177,16 @@ public class ThemeLayoutRendererTests
|
||||
.Replace("{themeId}", theme.ThemeId)
|
||||
.Replace("{*pageKey}", "shared/nav-menu");
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(layoutEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, layoutTemplate));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: layoutTemplate));
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(navEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, navTemplate));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: navTemplate));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a substitute view that renders the given markup.
|
||||
/// </summary>
|
||||
/// <param name="markup">The markup rendered by the view.</param>
|
||||
/// <returns>The created substitute view.</returns>
|
||||
private static IView CreateView(string markup)
|
||||
{
|
||||
IView view = Substitute.For<IView>();
|
||||
@@ -186,6 +199,10 @@ public class ThemeLayoutRendererTests
|
||||
return view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a substitute string localizer that returns a string prefixed with "Localized-".
|
||||
/// </summary>
|
||||
/// <returns>The created substitute string localizer.</returns>
|
||||
private static IStringLocalizer CreateLocalizer()
|
||||
{
|
||||
IStringLocalizer localizer = Substitute.For<IStringLocalizer>();
|
||||
|
||||
+4
-4
@@ -6,7 +6,6 @@ using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,6 +23,7 @@ public class ThemePageRendererTests
|
||||
private readonly ThemePageRenderer _sut;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly ThemePageDtoFixture _themePageDtoFixture = new();
|
||||
private readonly ThemeTemplateResponseDtoFixture _themeTemplateResponseDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemePageRendererTests"/> class.
|
||||
@@ -46,7 +46,7 @@ public class ThemePageRendererTests
|
||||
.Replace("{themeId}", "editorial-paper")
|
||||
.Replace("{*pageKey}", pageKey);
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(expectedEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, template));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: template));
|
||||
ThemePageDto model = _themePageDtoFixture.Create(pageKey: pageKey, title: "Home");
|
||||
|
||||
// Act
|
||||
@@ -74,7 +74,7 @@ public class ThemePageRendererTests
|
||||
_mockApiHttpClient.GetAsync<ThemeResponseDto>(ApiRoutes.Themes.GET_CURRENT_THEME, Arg.Any<CancellationToken>())
|
||||
.Returns(currentTheme);
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(expectedEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(currentTheme, "{{title}}"));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: currentTheme, template: "{{title}}"));
|
||||
ThemePageDto model = _themePageDtoFixture.Create(pageKey: pageKey, title: "Home");
|
||||
|
||||
// Act
|
||||
@@ -97,7 +97,7 @@ public class ThemePageRendererTests
|
||||
.Replace("{themeId}", "editorial-paper")
|
||||
.Replace("{*pageKey}", pageKey);
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(expectedEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, "{{#unclosed}}"));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: "{{#unclosed}}"));
|
||||
ThemePageDto model = _themePageDtoFixture.Create(pageKey: pageKey, title: "Home");
|
||||
|
||||
// Act
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Enums.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
@@ -28,6 +27,7 @@ public class ThemeServiceTests
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly ThemeSettingsResponseDtoFixture _themeSettingsResponseDtoFixture = new();
|
||||
private readonly ThemeTemplateResponseDtoFixture _themeTemplateResponseDtoFixture = new();
|
||||
private readonly BlobDataDtoFixture _blobDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeServiceTests"/> class.
|
||||
@@ -226,7 +226,7 @@ public class ThemeServiceTests
|
||||
string themeId = "editorial-paper";
|
||||
byte[] data = [0x50, 0x4B, 0x03, 0x04];
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = data, ContentType = "application/zip" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: data, contentType: "application/zip"));
|
||||
string expectedEndpoint = ApiRoutes.Themes.GET_THEME_ARCHIVE.Replace("{themeId}", themeId);
|
||||
|
||||
// Act
|
||||
|
||||
Reference in new issue
Block a user