mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 00:11:10 +00:00
Adds playback preferences and auto-persisted playback state to user settings
This commit is contained in:
1 parent
aab36dcd29
commit
dd76309ded
81 files changed
+6102
-173
No files matched your search
+24
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -27,6 +28,13 @@ public class UserSettingsEntityFixture
|
||||
/// <param name="shouldAggregateMetadataWhenMissing">Optional. Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Optional. Whether PDF books are rendered as page images for the user, or not.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Optional. Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Optional. Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Optional. Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Optional. Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">Optional. The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">Optional. The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <param name="volume">Optional. The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">Optional. The last mute state the player reported for the user.</param>
|
||||
/// <returns>The created user settings entity.</returns>
|
||||
public UserSettingsEntity Create(
|
||||
Guid? id = null,
|
||||
@@ -37,7 +45,14 @@ public class UserSettingsEntityFixture
|
||||
bool? isThemeCachingEnabled = null,
|
||||
bool? shouldAggregateMetadataWhenMissing = null,
|
||||
bool? shouldRenderPdfAsImages = null,
|
||||
bool? shouldPreserveBookStyles = null)
|
||||
bool? shouldPreserveBookStyles = null,
|
||||
bool? shouldKeepDownloadingWhilePaused = null,
|
||||
bool? shouldAutoplay = null,
|
||||
bool? isGaplessPlaybackEnabled = null,
|
||||
ReplayGainMode? replayGainMode = null,
|
||||
PlaybackStreamingQuality? streamingQuality = null,
|
||||
double? volume = null,
|
||||
bool? isMuted = null)
|
||||
{
|
||||
return new Faker<UserSettingsEntity>()
|
||||
.CustomInstantiator(f => new UserSettingsEntity
|
||||
@@ -50,7 +65,14 @@ public class UserSettingsEntityFixture
|
||||
IsThemeCachingEnabled = isThemeCachingEnabled ?? f.Random.Bool(),
|
||||
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing ?? f.Random.Bool(),
|
||||
ShouldRenderPdfAsImages = shouldRenderPdfAsImages ?? f.Random.Bool(),
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles ?? f.Random.Bool()
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles ?? f.Random.Bool(),
|
||||
ShouldKeepDownloadingWhilePaused = shouldKeepDownloadingWhilePaused ?? f.Random.Bool(),
|
||||
ShouldAutoplay = shouldAutoplay ?? f.Random.Bool(),
|
||||
IsGaplessPlaybackEnabled = isGaplessPlaybackEnabled ?? f.Random.Bool(),
|
||||
ReplayGainMode = replayGainMode ?? f.PickRandom<ReplayGainMode>(),
|
||||
StreamingQuality = streamingQuality ?? f.PickRandom<PlaybackStreamingQuality>(),
|
||||
Volume = volume ?? f.Random.Double(0.0, 1.0),
|
||||
IsMuted = isMuted ?? f.Random.Bool()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
+18
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSettings;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -25,6 +26,11 @@ public class UpdateUserSettingsCommandFixture
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Optional. Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Optional. Whether PDF books are rendered as page images for the user.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Optional. Whether the styles of the book content are preserved when it is rendered for the user.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Optional. Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Optional. Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Optional. Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">Optional. The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">Optional. The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public UpdateUserSettingsCommand Create(
|
||||
bool? isPaginationEnabled = null,
|
||||
@@ -34,10 +40,15 @@ public class UpdateUserSettingsCommandFixture
|
||||
bool? shouldAggregateMetadataWhenMissing = null,
|
||||
bool? shouldAggregateArtworkWhenMissing = null,
|
||||
bool? shouldRenderPdfAsImages = null,
|
||||
bool? shouldPreserveBookStyles = null)
|
||||
bool? shouldPreserveBookStyles = null,
|
||||
bool? shouldKeepDownloadingWhilePaused = null,
|
||||
bool? shouldAutoplay = null,
|
||||
bool? isGaplessPlaybackEnabled = null,
|
||||
ReplayGainMode? replayGainMode = null,
|
||||
PlaybackStreamingQuality? streamingQuality = null)
|
||||
{
|
||||
return new Faker<UpdateUserSettingsCommand>()
|
||||
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default, default, default, default, default))
|
||||
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default, default, default, default, default, default, default, default, default, default))
|
||||
.RuleFor(x => x.IsPaginationEnabled, f => isPaginationEnabled ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ItemsPerPage, f => itemsPerPage ?? f.Random.Int(1, 100))
|
||||
.RuleFor(x => x.ShouldIgnoreThePrefixForAlphaPicker, f => shouldIgnoreThePrefixForAlphaPicker ?? f.Random.Bool())
|
||||
@@ -46,6 +57,11 @@ public class UpdateUserSettingsCommandFixture
|
||||
.RuleFor(x => x.ShouldAggregateArtworkWhenMissing, f => shouldAggregateArtworkWhenMissing ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ShouldRenderPdfAsImages, f => shouldRenderPdfAsImages ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ShouldPreserveBookStyles, f => shouldPreserveBookStyles ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ShouldKeepDownloadingWhilePaused, f => shouldKeepDownloadingWhilePaused ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ShouldAutoplay, f => shouldAutoplay ?? f.Random.Bool())
|
||||
.RuleFor(x => x.IsGaplessPlaybackEnabled, f => isGaplessPlaybackEnabled ?? f.Random.Bool())
|
||||
.RuleFor(x => x.ReplayGainMode, f => replayGainMode ?? f.PickRandom<ReplayGainMode>())
|
||||
.RuleFor(x => x.StreamingQuality, f => streamingQuality ?? f.PickRandom<PlaybackStreamingQuality>())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
|
||||
+18
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.UsersManagement.Settings;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -27,6 +28,11 @@ public class UpdateUserSettingsRequestFixture
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <returns>The created <see cref="UpdateUserSettingsRequest"/>.</returns>
|
||||
public UpdateUserSettingsRequest Create(
|
||||
bool? isPaginationEnabled = null,
|
||||
@@ -36,7 +42,12 @@ public class UpdateUserSettingsRequestFixture
|
||||
bool? shouldAggregateMetadataWhenMissing = null,
|
||||
bool? shouldAggregateArtworkWhenMissing = null,
|
||||
bool? shouldRenderPdfAsImages = null,
|
||||
bool? shouldPreserveBookStyles = null)
|
||||
bool? shouldPreserveBookStyles = null,
|
||||
bool? shouldKeepDownloadingWhilePaused = null,
|
||||
bool? shouldAutoplay = null,
|
||||
bool? isGaplessPlaybackEnabled = null,
|
||||
ReplayGainMode? replayGainMode = null,
|
||||
PlaybackStreamingQuality? streamingQuality = null)
|
||||
{
|
||||
return new UpdateUserSettingsRequest(
|
||||
isPaginationEnabled ?? _faker.Random.Bool(),
|
||||
@@ -46,7 +57,12 @@ public class UpdateUserSettingsRequestFixture
|
||||
shouldAggregateMetadataWhenMissing ?? _faker.Random.Bool(),
|
||||
shouldAggregateArtworkWhenMissing ?? _faker.Random.Bool(),
|
||||
shouldRenderPdfAsImages ?? _faker.Random.Bool(),
|
||||
shouldPreserveBookStyles ?? _faker.Random.Bool());
|
||||
shouldPreserveBookStyles ?? _faker.Random.Bool(),
|
||||
shouldKeepDownloadingWhilePaused ?? _faker.Random.Bool(),
|
||||
shouldAutoplay ?? _faker.Random.Bool(),
|
||||
isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
|
||||
replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
|
||||
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+18
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Settings;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -29,6 +30,11 @@ public class UserSettingsResponseFixture
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Optional. Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Optional. Whether PDF books are rendered as page images for the user.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Optional. Whether the styles of the book content are preserved when it is rendered for the user.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Optional. Whether the player keeps downloading a track while playback is paused.</param>
|
||||
/// <param name="shouldAutoplay">Optional. Whether the player continues playback at the end of an album or artist.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Optional. Whether the player transitions between consecutive tracks without a gap.</param>
|
||||
/// <param name="replayGainMode">Optional. The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">Optional. The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <returns>The created <see cref="UserSettingsResponse"/>.</returns>
|
||||
public UserSettingsResponse Create(
|
||||
Guid? userId = null,
|
||||
@@ -39,7 +45,12 @@ public class UserSettingsResponseFixture
|
||||
bool? shouldAggregateMetadataWhenMissing = null,
|
||||
bool? shouldAggregateArtworkWhenMissing = null,
|
||||
bool? shouldRenderPdfAsImages = null,
|
||||
bool? shouldPreserveBookStyles = null)
|
||||
bool? shouldPreserveBookStyles = null,
|
||||
bool? shouldKeepDownloadingWhilePaused = null,
|
||||
bool? shouldAutoplay = null,
|
||||
bool? isGaplessPlaybackEnabled = null,
|
||||
ReplayGainMode? replayGainMode = null,
|
||||
PlaybackStreamingQuality? streamingQuality = null)
|
||||
{
|
||||
return new UserSettingsResponse(
|
||||
userId ?? Guid.NewGuid(),
|
||||
@@ -50,7 +61,12 @@ public class UserSettingsResponseFixture
|
||||
shouldAggregateMetadataWhenMissing ?? _faker.Random.Bool(),
|
||||
shouldAggregateArtworkWhenMissing ?? _faker.Random.Bool(),
|
||||
shouldRenderPdfAsImages ?? _faker.Random.Bool(),
|
||||
shouldPreserveBookStyles ?? _faker.Random.Bool());
|
||||
shouldPreserveBookStyles ?? _faker.Random.Bool(),
|
||||
shouldKeepDownloadingWhilePaused ?? _faker.Random.Bool(),
|
||||
shouldAutoplay ?? _faker.Random.Bool(),
|
||||
isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
|
||||
replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
|
||||
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+24
-2
@@ -2,6 +2,7 @@
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -28,6 +29,13 @@ public class UserSettingsFixture
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <param name="volume">The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">The last mute state the player reported for the user.</param>
|
||||
/// <returns>The created <see cref="UserSettings"/>.</returns>
|
||||
public UserSettings Create(
|
||||
Guid? userId = null,
|
||||
@@ -38,7 +46,14 @@ public class UserSettingsFixture
|
||||
bool shouldAggregateMetadataWhenMissing = false,
|
||||
bool shouldAggregateArtworkWhenMissing = false,
|
||||
bool shouldRenderPdfAsImages = false,
|
||||
bool shouldPreserveBookStyles = true)
|
||||
bool shouldPreserveBookStyles = true,
|
||||
bool shouldKeepDownloadingWhilePaused = true,
|
||||
bool shouldAutoplay = true,
|
||||
bool isGaplessPlaybackEnabled = true,
|
||||
ReplayGainMode replayGainMode = ReplayGainMode.Off,
|
||||
PlaybackStreamingQuality streamingQuality = PlaybackStreamingQuality.Auto,
|
||||
double volume = 1.0,
|
||||
bool isMuted = false)
|
||||
{
|
||||
Result<UserSettings> settings = UserSettings.Create(
|
||||
userId is null ? UserId.CreateUnique() : UserId.Create(userId.Value),
|
||||
@@ -49,7 +64,14 @@ public class UserSettingsFixture
|
||||
shouldAggregateMetadataWhenMissing,
|
||||
shouldAggregateArtworkWhenMissing,
|
||||
shouldRenderPdfAsImages,
|
||||
shouldPreserveBookStyles);
|
||||
shouldPreserveBookStyles,
|
||||
shouldKeepDownloadingWhilePaused,
|
||||
shouldAutoplay,
|
||||
isGaplessPlaybackEnabled,
|
||||
replayGainMode,
|
||||
streamingQuality,
|
||||
volume,
|
||||
isMuted);
|
||||
return settings.Value;
|
||||
}
|
||||
|
||||
|
||||
+18
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -28,6 +29,11 @@ public class UserSettingsDtoFixture
|
||||
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <returns>A configured <see cref="UserSettingsDto"/> instance.</returns>
|
||||
public UserSettingsDto Create(
|
||||
Guid? userId = null,
|
||||
@@ -37,7 +43,12 @@ public class UserSettingsDtoFixture
|
||||
bool? isThemeCachingEnabled = null,
|
||||
bool? shouldAggregateMetadataWhenMissing = null,
|
||||
bool? shouldRenderPdfAsImages = null,
|
||||
bool? shouldPreserveBookStyles = null)
|
||||
bool? shouldPreserveBookStyles = null,
|
||||
bool? shouldKeepDownloadingWhilePaused = null,
|
||||
bool? shouldAutoplay = null,
|
||||
bool? isGaplessPlaybackEnabled = null,
|
||||
ReplayGainMode? replayGainMode = null,
|
||||
PlaybackStreamingQuality? streamingQuality = null)
|
||||
{
|
||||
return new UserSettingsDto
|
||||
{
|
||||
@@ -48,7 +59,12 @@ public class UserSettingsDtoFixture
|
||||
IsThemeCachingEnabled = isThemeCachingEnabled ?? _faker.Random.Bool(),
|
||||
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing ?? _faker.Random.Bool(),
|
||||
ShouldRenderPdfAsImages = shouldRenderPdfAsImages ?? _faker.Random.Bool(),
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles ?? _faker.Random.Bool()
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles ?? _faker.Random.Bool(),
|
||||
ShouldKeepDownloadingWhilePaused = shouldKeepDownloadingWhilePaused ?? _faker.Random.Bool(),
|
||||
ShouldAutoplay = shouldAutoplay ?? _faker.Random.Bool(),
|
||||
IsGaplessPlaybackEnabled = isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
|
||||
ReplayGainMode = replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
|
||||
StreamingQuality = streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
-37
@@ -192,43 +192,6 @@ public class UpdateUserSettingsCommandHandlerTests
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenToDomainEntityFails_ShouldReturnErrorAndNotUpdate()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create();
|
||||
// An entity carrying an invalid items-per-page value fails to convert to its domain aggregate.
|
||||
UserSettingsEntity existingSettings = _userSettingsEntityFixture.Create(userId: _userId, itemsPerPage: 0);
|
||||
_mockUserSettingsRepository.GetByUserIdAsync(_userId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserSettingsEntity?>(existingSettings));
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockUserSettingsRepository.DidNotReceive().UpdateAsync(Arg.Any<UserSettingsEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenUpdateSettingsFails_ShouldReturnErrorAndNotPersist()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(itemsPerPage: 0);
|
||||
UserSettingsEntity existingSettings = _userSettingsEntityFixture.Create(userId: _userId);
|
||||
_mockUserSettingsRepository.GetByUserIdAsync(_userId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserSettingsEntity?>(existingSettings));
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockUserSettingsRepository.DidNotReceive().UpdateAsync(Arg.Any<UserSettingsEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenUpdateFails_ShouldReturnErrorAndNotSaveChanges()
|
||||
{
|
||||
|
||||
@@ -79,10 +79,20 @@ public class ErrorsTests
|
||||
{
|
||||
// Assert
|
||||
// The count assertion fails when an error is added or removed, reminding to update the assertions below.
|
||||
Assert.Equal(3, typeof(DomainErrors.UserSettings).GetProperties().Length);
|
||||
Assert.Equal(13, typeof(DomainErrors.UserSettings).GetProperties().Length);
|
||||
AssertError(DomainErrors.UserSettings.UserSettingsAlreadyExists, ErrorType.Conflict);
|
||||
AssertError(DomainErrors.UserSettings.UserSettingsNotFound, ErrorType.NotFound);
|
||||
AssertError(DomainErrors.UserSettings.ItemsPerPageMustBeGreaterThanZero, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.VolumeCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.VolumeMustBeBetweenZeroAndOne, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.IsMutedCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.ShouldKeepDownloadingWhilePausedCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.ShouldAutoplayCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.IsGaplessPlaybackEnabledCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.ReplayGainModeCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.StreamingQualityCannotBeNull, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.InvalidReplayGainMode, ErrorType.Validation);
|
||||
AssertError(DomainErrors.UserSettings.InvalidStreamingQuality, ErrorType.Validation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+4
-51
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
@@ -7,6 +6,7 @@ using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettin
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -80,7 +80,7 @@ public class UserSettingsTests
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto, volume: 1.0, isMuted: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -108,22 +108,6 @@ public class UserSettingsTests
|
||||
Assert.NotEqual(result.Value.Id.Value, result.Value.UserId.Value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-1)]
|
||||
public void Create_WhenItemsPerPageIsNotPositive_ShouldReturnError(int itemsPerPage)
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndValidValues_ShouldCreateSettingsWithThatId()
|
||||
{
|
||||
@@ -132,7 +116,7 @@ public class UserSettingsTests
|
||||
UserSettingsId id = _userSettingsIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: true);
|
||||
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: true, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto, volume: 1.0, isMuted: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -141,21 +125,6 @@ public class UserSettingsTests
|
||||
Assert.Equal(24, result.Value.ItemsPerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndNonPositiveItemsPerPage_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = _userIdFixture.Create();
|
||||
UserSettingsId id = _userSettingsIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 0, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateSettings_WhenCalledWithValidValues_ShouldUpdateSettings()
|
||||
{
|
||||
@@ -163,7 +132,7 @@ public class UserSettingsTests
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -175,20 +144,4 @@ public class UserSettingsTests
|
||||
Assert.True(userSettings.ShouldRenderPdfAsImages);
|
||||
Assert.True(userSettings.ShouldPreserveBookStyles);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-5)]
|
||||
public void UpdateSettings_WhenItemsPerPageIsNotPositive_ShouldReturnError(int itemsPerPage)
|
||||
{
|
||||
// Arrange
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero, result.FirstError);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user