mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Adds a theme caching toggle to the user settings
This commit is contained in:
1 parent
60b551558f
commit
3da7167538
43 files changed
+1611
-56
No files matched your search
+2
-1
@@ -17,7 +17,7 @@ public class UpdateUserSettingsRequestMappingTests
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest request = new(IsPaginationEnabled: true, ItemsPerPage: 48, IgnoreThePrefixForAlphaPicker: false);
|
||||
UpdateUserSettingsRequest request = new(IsPaginationEnabled: true, ItemsPerPage: 48, IgnoreThePrefixForAlphaPicker: false, IsThemeCachingEnabled: true);
|
||||
|
||||
// Act
|
||||
UpdateUserSettingsCommand result = request.ToCommand();
|
||||
@@ -27,5 +27,6 @@ public class UpdateUserSettingsRequestMappingTests
|
||||
Assert.Equal(request.IsPaginationEnabled, result.IsPaginationEnabled);
|
||||
Assert.Equal(request.ItemsPerPage, result.ItemsPerPage);
|
||||
Assert.Equal(request.IgnoreThePrefixForAlphaPicker, result.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(request.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
|
||||
}
|
||||
}
|
||||
+2
@@ -34,6 +34,7 @@ public class UserSettingsEntityMappingTests
|
||||
Assert.Equal(entity.IsPaginationEnabled, result.Value.IsPaginationEnabled);
|
||||
Assert.Equal(entity.ItemsPerPage, result.Value.ItemsPerPage);
|
||||
Assert.Equal(entity.IgnoreThePrefixForAlphaPicker, result.Value.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(entity.IsThemeCachingEnabled, result.Value.IsThemeCachingEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,5 +52,6 @@ public class UserSettingsEntityMappingTests
|
||||
Assert.Equal(entity.IsPaginationEnabled, result.IsPaginationEnabled);
|
||||
Assert.Equal(entity.ItemsPerPage, result.ItemsPerPage);
|
||||
Assert.Equal(entity.IgnoreThePrefixForAlphaPicker, result.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(entity.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -21,7 +21,7 @@ public class UpdateUserSettingsRequestTests
|
||||
public void RoundTrip_WhenSerializingUpdateUserSettingsRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest expected = new(true, 50, true);
|
||||
UpdateUserSettingsRequest expected = new(true, 50, true, true);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
@@ -36,14 +36,15 @@ public class UpdateUserSettingsRequestTests
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest sut = new(false, 25, false);
|
||||
UpdateUserSettingsRequest sut = new(false, 25, false, false);
|
||||
|
||||
// Act
|
||||
(bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker) = sut;
|
||||
(bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker, bool isThemeCachingEnabled) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.IsPaginationEnabled, isPaginationEnabled);
|
||||
Assert.Equal(sut.ItemsPerPage, itemsPerPage);
|
||||
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(sut.IsThemeCachingEnabled, isThemeCachingEnabled);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -23,7 +23,7 @@ public class UserSettingsResponseTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
UserSettingsResponse expected = new(userId, true, 50, true);
|
||||
UserSettingsResponse expected = new(userId, true, 50, true, true);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
@@ -39,15 +39,16 @@ public class UserSettingsResponseTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
UserSettingsResponse sut = new(userId, false, 25, false);
|
||||
UserSettingsResponse sut = new(userId, false, 25, false, false);
|
||||
|
||||
// Act
|
||||
(Guid sutUserId, bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker) = sut;
|
||||
(Guid sutUserId, bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker, bool isThemeCachingEnabled) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.UserId, sutUserId);
|
||||
Assert.Equal(sut.IsPaginationEnabled, isPaginationEnabled);
|
||||
Assert.Equal(sut.ItemsPerPage, itemsPerPage);
|
||||
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(sut.IsThemeCachingEnabled, isThemeCachingEnabled);
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -72,7 +72,7 @@ public class UserSettingsTests
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, ignoreThePrefixForAlphaPicker: true);
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, ignoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -80,6 +80,7 @@ public class UserSettingsTests
|
||||
Assert.False(result.Value.IsPaginationEnabled);
|
||||
Assert.Equal(24, result.Value.ItemsPerPage);
|
||||
Assert.True(result.Value.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.True(result.Value.IsThemeCachingEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,7 +106,7 @@ public class UserSettingsTests
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -119,13 +120,14 @@ public class UserSettingsTests
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true);
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(userSettings.IsPaginationEnabled);
|
||||
Assert.Equal(12, userSettings.ItemsPerPage);
|
||||
Assert.True(userSettings.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.False(userSettings.IsThemeCachingEnabled);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -137,7 +139,7 @@ public class UserSettingsTests
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+3
-3
@@ -39,7 +39,7 @@ public class GetUserSettingsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
UserSettingsResponse expectedResponse = new(Guid.NewGuid(), true, 48, false);
|
||||
UserSettingsResponse expectedResponse = new(Guid.NewGuid(), true, 48, false, true);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserSettingsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -79,7 +79,7 @@ public class GetUserSettingsEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserSettingsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false)));
|
||||
.Returns(Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false, true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
@@ -104,7 +104,7 @@ public class GetUserSettingsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false));
|
||||
return Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false, true));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-5
@@ -37,7 +37,7 @@ public class UpdateUserSettingsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithUpdatedMarker()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest request = new(true, 48, false);
|
||||
UpdateUserSettingsRequest request = new(true, 48, false, true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
@@ -54,7 +54,7 @@ public class UpdateUserSettingsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest request = new(true, 0, false);
|
||||
UpdateUserSettingsRequest request = new(true, 0, false, true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("UserSettings.ItemsPerPageMustBeGreaterThanZero", "ItemsPerPage must be greater than zero.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -76,7 +76,7 @@ public class UpdateUserSettingsEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateUserSettingsCommandToHandler()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsRequest request = new(true, 24, true);
|
||||
UpdateUserSettingsRequest request = new(true, 24, true, true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
@@ -89,7 +89,8 @@ public class UpdateUserSettingsEndpointTests
|
||||
Arg.Is<UpdateUserSettingsCommand>(command =>
|
||||
command.IsPaginationEnabled == request.IsPaginationEnabled &&
|
||||
command.ItemsPerPage == request.ItemsPerPage &&
|
||||
command.IgnoreThePrefixForAlphaPicker == request.IgnoreThePrefixForAlphaPicker),
|
||||
command.IgnoreThePrefixForAlphaPicker == request.IgnoreThePrefixForAlphaPicker &&
|
||||
command.IsThemeCachingEnabled == request.IsThemeCachingEnabled),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ public class UpdateUserSettingsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new UpdateUserSettingsRequest(true, 48, false), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new UpdateUserSettingsRequest(true, 48, false, true), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+11
-1
@@ -3,10 +3,13 @@ using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.GetUserSettings;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Caching.Hybrid;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
@@ -32,7 +35,14 @@ public class GetUserSettingsEndpointTests
|
||||
public GetUserSettingsEndpointTests()
|
||||
{
|
||||
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
|
||||
_sut = Factory.Create<GetUserSettingsEndpoint>(_mockApiHttpClient);
|
||||
_sut = Factory.Create<GetUserSettingsEndpoint>(_mockApiHttpClient, CreateThemeCachePreferenceService());
|
||||
}
|
||||
|
||||
private static ThemeCachePreferenceService CreateThemeCachePreferenceService()
|
||||
{
|
||||
ServiceCollection services = new();
|
||||
services.AddHybridCache();
|
||||
return new ThemeCachePreferenceService(services.BuildServiceProvider().GetRequiredService<HybridCache>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+11
-1
@@ -3,10 +3,13 @@ using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.UpdateUserSettings;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Caching.Hybrid;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
@@ -32,7 +35,14 @@ public class UpdateUserSettingsEndpointTests
|
||||
public UpdateUserSettingsEndpointTests()
|
||||
{
|
||||
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
|
||||
_sut = Factory.Create<UpdateUserSettingsEndpoint>(_mockApiHttpClient);
|
||||
_sut = Factory.Create<UpdateUserSettingsEndpoint>(_mockApiHttpClient, CreateThemeCachePreferenceService());
|
||||
}
|
||||
|
||||
private static ThemeCachePreferenceService CreateThemeCachePreferenceService()
|
||||
{
|
||||
ServiceCollection services = new();
|
||||
services.AddHybridCache();
|
||||
return new ThemeCachePreferenceService(services.BuildServiceProvider().GetRequiredService<HybridCache>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in new issue
Block a user