Adds VU meter to the audio player bar

Adds a segmented spectrum VU meter to the condensed player bar, fed by an analyser tapped after ReplayGain and before the volume, so the meter does not depend on the output volume.

Adds per-user VU meter settings (orientation, segment count and gap, thresholds, peak marker, hold and falloff rates) across the domain, persistence, API contracts, validation and the settings page, with a migration and localized resources.

Sizes the meter cells in whole pixels and keeps the frame clock steady on browsers that round timers.

Updates the theming guide, API documentation, request samples and the user manual.
This commit is contained in:
BinaryAlley committed 2026-10-21 20:30:51 +03:00
1 parent 9889c86c76
commit 2e9f7d8496
66 files changed
+7844 -81

No files matched your search

@@ -33,6 +33,15 @@ public class UserSettingsEntityFixture
/// <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="vuMeterOrientation">Optional. The direction in which each channel of the VU meter of the audio player grows.</param>
/// <param name="vuMeterSegmentCount">Optional. The number of segments each channel of the VU meter is divided into.</param>
/// <param name="vuMeterSegmentGap">Optional. The gap, in pixels, between the segments and the channels of the VU meter.</param>
/// <param name="vuMeterMediumThreshold">Optional. The level above which a segment of the VU meter is drawn with its medium state.</param>
/// <param name="vuMeterHighThreshold">Optional. The level above which a segment of the VU meter is drawn with its high state.</param>
/// <param name="vuMeterShowPeak">Optional. Whether the VU meter holds the peak level of each channel after it falls.</param>
/// <param name="vuMeterPeakHoldDurationInMilliseconds">Optional. The time a peak of the VU meter is held before it starts falling.</param>
/// <param name="vuMeterReleasePerSecond">Optional. The number of level units the display of the VU meter falls per second when the input level drops.</param>
/// <param name="vuMeterPeakReleasePerSecond">Optional. The number of level units the peak of the VU meter falls per second after its hold time elapsed.</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>
@@ -51,28 +60,51 @@ public class UserSettingsEntityFixture
bool? isGaplessPlaybackEnabled = null,
ReplayGainMode? replayGainMode = null,
PlaybackStreamingQuality? streamingQuality = null,
VuMeterOrientation? vuMeterOrientation = null,
int? vuMeterSegmentCount = null,
int? vuMeterSegmentGap = null,
double? vuMeterMediumThreshold = null,
double? vuMeterHighThreshold = null,
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null,
double? volume = null,
bool? isMuted = null)
{
return new Faker<UserSettingsEntity>()
.CustomInstantiator(f => new UserSettingsEntity
.CustomInstantiator(f =>
{
Id = id ?? Guid.NewGuid(),
UserId = userId ?? Guid.NewGuid(),
IsPaginationEnabled = isPaginationEnabled ?? f.Random.Bool(),
ItemsPerPage = itemsPerPage ?? f.Random.Int(1, 100),
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker ?? f.Random.Bool(),
IsThemeCachingEnabled = isThemeCachingEnabled ?? f.Random.Bool(),
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing ?? f.Random.Bool(),
ShouldRenderPdfAsImages = shouldRenderPdfAsImages ?? 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()
// The high threshold is generated from the medium one, so a randomized entity always describes a valid meter.
double mediumThreshold = vuMeterMediumThreshold ?? f.Random.Double(0, 1);
return new UserSettingsEntity
{
Id = id ?? Guid.NewGuid(),
UserId = userId ?? Guid.NewGuid(),
IsPaginationEnabled = isPaginationEnabled ?? f.Random.Bool(),
ItemsPerPage = itemsPerPage ?? f.Random.Int(1, 100),
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker ?? f.Random.Bool(),
IsThemeCachingEnabled = isThemeCachingEnabled ?? f.Random.Bool(),
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing ?? f.Random.Bool(),
ShouldRenderPdfAsImages = shouldRenderPdfAsImages ?? 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>(),
VuMeterOrientation = vuMeterOrientation ?? f.PickRandom<VuMeterOrientation>(),
VuMeterSegmentCount = vuMeterSegmentCount ?? f.Random.Int(1, 128),
VuMeterSegmentGap = vuMeterSegmentGap ?? f.Random.Int(0, 32),
VuMeterMediumThreshold = mediumThreshold,
VuMeterHighThreshold = vuMeterHighThreshold ?? f.Random.Double(mediumThreshold, 1),
VuMeterShowPeak = vuMeterShowPeak ?? f.Random.Bool(),
VuMeterPeakHoldDurationInMilliseconds = vuMeterPeakHoldDurationInMilliseconds ?? f.Random.Int(0, 10000),
VuMeterReleasePerSecond = vuMeterReleasePerSecond ?? f.Random.Double(0, 100),
VuMeterPeakReleasePerSecond = vuMeterPeakReleasePerSecond ?? f.Random.Double(0, 100),
Volume = volume ?? f.Random.Double(0.0, 1.0),
IsMuted = isMuted ?? f.Random.Bool()
};
})
.Generate();
}
@@ -2,6 +2,7 @@
using Bogus;
using Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSettings;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -31,6 +32,15 @@ public class UpdateUserSettingsCommandFixture
/// <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="vuMeterOrientation">Optional. The direction in which each channel of the VU meter of the audio player grows.</param>
/// <param name="vuMeterSegmentCount">Optional. The number of segments each channel of the VU meter is divided into.</param>
/// <param name="vuMeterSegmentGap">Optional. The gap, in pixels, between the segments and the channels of the VU meter.</param>
/// <param name="vuMeterMediumThreshold">Optional. The level above which a segment of the VU meter is drawn with its medium state.</param>
/// <param name="vuMeterHighThreshold">Optional. The level above which a segment of the VU meter is drawn with its high state.</param>
/// <param name="vuMeterShowPeak">Optional. Whether the VU meter holds the peak level of each channel after it falls.</param>
/// <param name="vuMeterPeakHoldDurationInMilliseconds">Optional. The time a peak of the VU meter is held before it starts falling.</param>
/// <param name="vuMeterReleasePerSecond">Optional. The number of level units the display of the VU meter falls per second when the input level drops.</param>
/// <param name="vuMeterPeakReleasePerSecond">Optional. The number of level units the peak of the VU meter falls per second after its hold time elapsed.</param>
/// <returns>The created command.</returns>
public UpdateUserSettingsCommand Create(
bool? isPaginationEnabled = null,
@@ -45,10 +55,22 @@ public class UpdateUserSettingsCommandFixture
bool? shouldAutoplay = null,
bool? isGaplessPlaybackEnabled = null,
ReplayGainMode? replayGainMode = null,
PlaybackStreamingQuality? streamingQuality = null)
PlaybackStreamingQuality? streamingQuality = null,
VuMeterOrientation? vuMeterOrientation = null,
int? vuMeterSegmentCount = null,
int? vuMeterSegmentGap = null,
double? vuMeterMediumThreshold = null,
double? vuMeterHighThreshold = null,
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null)
{
// The high threshold is generated from the medium one, so a randomized command always describes a valid meter.
double mediumThreshold = vuMeterMediumThreshold ?? Random.Shared.NextDouble();
double highThreshold = vuMeterHighThreshold ?? (mediumThreshold + Random.Shared.NextDouble() * (1 - mediumThreshold));
return new Faker<UpdateUserSettingsCommand>()
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default, default, 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, 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())
@@ -62,6 +84,15 @@ public class UpdateUserSettingsCommandFixture
.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>())
.RuleFor(x => x.VuMeterOrientation, f => vuMeterOrientation ?? f.PickRandom<VuMeterOrientation>())
.RuleFor(x => x.VuMeterSegmentCount, f => vuMeterSegmentCount ?? f.Random.Int(1, 128))
.RuleFor(x => x.VuMeterSegmentGap, f => vuMeterSegmentGap ?? f.Random.Int(0, 32))
.RuleFor(x => x.VuMeterMediumThreshold, f => mediumThreshold)
.RuleFor(x => x.VuMeterHighThreshold, f => highThreshold)
.RuleFor(x => x.VuMeterShowPeak, f => vuMeterShowPeak ?? f.Random.Bool())
.RuleFor(x => x.VuMeterPeakHoldDurationInMilliseconds, f => vuMeterPeakHoldDurationInMilliseconds ?? f.Random.Int(0, 10000))
.RuleFor(x => x.VuMeterReleasePerSecond, f => vuMeterReleasePerSecond ?? f.Random.Double(0, 100))
.RuleFor(x => x.VuMeterPeakReleasePerSecond, f => vuMeterPeakReleasePerSecond ?? f.Random.Double(0, 100))
.Generate();
}
@@ -33,6 +33,15 @@ public class UpdateUserSettingsRequestFixture
/// <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="vuMeterOrientation">The direction in which each channel of the VU meter of the audio player grows.</param>
/// <param name="vuMeterSegmentCount">The number of segments each channel of the VU meter is divided into.</param>
/// <param name="vuMeterSegmentGap">The gap, in pixels, between the segments and the channels of the VU meter.</param>
/// <param name="vuMeterMediumThreshold">The level above which a segment of the VU meter is drawn with its medium state.</param>
/// <param name="vuMeterHighThreshold">The level above which a segment of the VU meter is drawn with its high state.</param>
/// <param name="vuMeterShowPeak">Whether the VU meter holds the peak level of each channel after it falls.</param>
/// <param name="vuMeterPeakHoldDurationInMilliseconds">The time a peak of the VU meter is held before it starts falling.</param>
/// <param name="vuMeterReleasePerSecond">The number of level units the display of the VU meter falls per second when the input level drops.</param>
/// <param name="vuMeterPeakReleasePerSecond">The number of level units the peak of the VU meter falls per second after its hold time elapsed.</param>
/// <returns>The created <see cref="UpdateUserSettingsRequest"/>.</returns>
public UpdateUserSettingsRequest Create(
bool? isPaginationEnabled = null,
@@ -47,8 +56,20 @@ public class UpdateUserSettingsRequestFixture
bool? shouldAutoplay = null,
bool? isGaplessPlaybackEnabled = null,
ReplayGainMode? replayGainMode = null,
PlaybackStreamingQuality? streamingQuality = null)
PlaybackStreamingQuality? streamingQuality = null,
VuMeterOrientation? vuMeterOrientation = null,
int? vuMeterSegmentCount = null,
int? vuMeterSegmentGap = null,
double? vuMeterMediumThreshold = null,
double? vuMeterHighThreshold = null,
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null)
{
// The high threshold is generated from the medium one, so a randomized request always describes a valid meter.
double mediumThreshold = vuMeterMediumThreshold ?? _faker.Random.Double(0, 1);
double highThreshold = vuMeterHighThreshold ?? _faker.Random.Double(mediumThreshold, 1);
return new UpdateUserSettingsRequest(
isPaginationEnabled ?? _faker.Random.Bool(),
itemsPerPage ?? _faker.Random.Int(1, 100),
@@ -62,7 +83,16 @@ public class UpdateUserSettingsRequestFixture
shouldAutoplay ?? _faker.Random.Bool(),
isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>());
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>(),
vuMeterOrientation ?? _faker.PickRandom<VuMeterOrientation>(),
vuMeterSegmentCount ?? _faker.Random.Int(1, 128),
vuMeterSegmentGap ?? _faker.Random.Int(0, 32),
mediumThreshold,
highThreshold,
vuMeterShowPeak ?? _faker.Random.Bool(),
vuMeterPeakHoldDurationInMilliseconds ?? _faker.Random.Int(0, 10000),
vuMeterReleasePerSecond ?? _faker.Random.Double(0, 100),
vuMeterPeakReleasePerSecond ?? _faker.Random.Double(0, 100));
}
/// <summary>
@@ -35,6 +35,15 @@ public class UserSettingsResponseFixture
/// <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>
/// <param name="vuMeterOrientation">Optional. The direction in which each channel of the VU meter of the audio player grows.</param>
/// <param name="vuMeterSegmentCount">Optional. The number of segments each channel of the VU meter is divided into.</param>
/// <param name="vuMeterSegmentGap">Optional. The gap, in pixels, between the segments and the channels of the VU meter.</param>
/// <param name="vuMeterMediumThreshold">Optional. The level above which a segment of the VU meter is drawn with its medium state.</param>
/// <param name="vuMeterHighThreshold">Optional. The level above which a segment of the VU meter is drawn with its high state.</param>
/// <param name="vuMeterShowPeak">Optional. Whether the VU meter holds the peak level of each channel after it falls.</param>
/// <param name="vuMeterPeakHoldDurationInMilliseconds">Optional. The time a peak of the VU meter is held before it starts falling.</param>
/// <param name="vuMeterReleasePerSecond">Optional. The number of level units the display of the VU meter falls per second when the input level drops.</param>
/// <param name="vuMeterPeakReleasePerSecond">Optional. The number of level units the peak of the VU meter falls per second after its hold time elapsed.</param>
/// <returns>The created <see cref="UserSettingsResponse"/>.</returns>
public UserSettingsResponse Create(
Guid? userId = null,
@@ -50,8 +59,20 @@ public class UserSettingsResponseFixture
bool? shouldAutoplay = null,
bool? isGaplessPlaybackEnabled = null,
ReplayGainMode? replayGainMode = null,
PlaybackStreamingQuality? streamingQuality = null)
PlaybackStreamingQuality? streamingQuality = null,
VuMeterOrientation? vuMeterOrientation = null,
int? vuMeterSegmentCount = null,
int? vuMeterSegmentGap = null,
double? vuMeterMediumThreshold = null,
double? vuMeterHighThreshold = null,
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null)
{
// The high threshold is generated from the medium one, so a randomized response always describes a valid meter.
double mediumThreshold = vuMeterMediumThreshold ?? _faker.Random.Double(0, 1);
double highThreshold = vuMeterHighThreshold ?? _faker.Random.Double(mediumThreshold, 1);
return new UserSettingsResponse(
userId ?? Guid.NewGuid(),
isPaginationEnabled ?? _faker.Random.Bool(),
@@ -66,7 +87,16 @@ public class UserSettingsResponseFixture
shouldAutoplay ?? _faker.Random.Bool(),
isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>());
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>(),
vuMeterOrientation ?? _faker.PickRandom<VuMeterOrientation>(),
vuMeterSegmentCount ?? _faker.Random.Int(1, 128),
vuMeterSegmentGap ?? _faker.Random.Int(0, 32),
mediumThreshold,
highThreshold,
vuMeterShowPeak ?? _faker.Random.Bool(),
vuMeterPeakHoldDurationInMilliseconds ?? _faker.Random.Int(0, 10000),
vuMeterReleasePerSecond ?? _faker.Random.Double(0, 100),
vuMeterPeakReleasePerSecond ?? _faker.Random.Double(0, 100));
}
/// <summary>
@@ -34,6 +34,15 @@ public class UserSettingsFixture
/// <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="vuMeterOrientation">The direction in which each channel of the VU meter of the audio player grows.</param>
/// <param name="vuMeterSegmentCount">The number of segments each channel of the VU meter is divided into.</param>
/// <param name="vuMeterSegmentGap">The gap, in pixels, between the segments and the channels of the VU meter.</param>
/// <param name="vuMeterMediumThreshold">The level above which a segment of the VU meter is drawn with its medium state.</param>
/// <param name="vuMeterHighThreshold">The level above which a segment of the VU meter is drawn with its high state.</param>
/// <param name="vuMeterShowPeak">Whether the VU meter holds the peak level of each channel after it falls.</param>
/// <param name="vuMeterPeakHoldDurationInMilliseconds">The time a peak of the VU meter is held before it starts falling.</param>
/// <param name="vuMeterReleasePerSecond">The number of level units the display of the VU meter falls per second when the input level drops.</param>
/// <param name="vuMeterPeakReleasePerSecond">The number of level units the peak of the VU meter falls per second after its hold time elapsed.</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>
@@ -52,6 +61,15 @@ public class UserSettingsFixture
bool isGaplessPlaybackEnabled = true,
ReplayGainMode replayGainMode = ReplayGainMode.Off,
PlaybackStreamingQuality streamingQuality = PlaybackStreamingQuality.Auto,
VuMeterOrientation vuMeterOrientation = VuMeterOrientation.Vertical,
int vuMeterSegmentCount = 12,
int vuMeterSegmentGap = 1,
double vuMeterMediumThreshold = 0.6,
double vuMeterHighThreshold = 0.8,
bool vuMeterShowPeak = true,
int vuMeterPeakHoldDurationInMilliseconds = 650,
double vuMeterReleasePerSecond = 3.0,
double vuMeterPeakReleasePerSecond = 0.65,
double volume = 1.0,
bool isMuted = false)
{
@@ -70,6 +88,15 @@ public class UserSettingsFixture
isGaplessPlaybackEnabled,
replayGainMode,
streamingQuality,
vuMeterOrientation,
vuMeterSegmentCount,
vuMeterSegmentGap,
vuMeterMediumThreshold,
vuMeterHighThreshold,
vuMeterShowPeak,
vuMeterPeakHoldDurationInMilliseconds,
vuMeterReleasePerSecond,
vuMeterPeakReleasePerSecond,
volume,
isMuted);
return settings.Value;
@@ -5,6 +5,7 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement.Settings;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -22,7 +23,16 @@ public class UserSettingsEntityMappingTests
public void ToDomainEntity_WhenMappingValidRepositoryEntity_ShouldMapCorrectly()
{
// Arrange
UserSettingsEntity entity = _userSettingsEntityFixture.Create();
UserSettingsEntity entity = _userSettingsEntityFixture.Create(
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 24,
vuMeterSegmentGap: 2,
vuMeterMediumThreshold: 0.4,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 900,
vuMeterReleasePerSecond: 2.5,
vuMeterPeakReleasePerSecond: 0.9);
// Act
Result<UserSettings> result = entity.ToDomainEntity();
@@ -37,13 +47,31 @@ public class UserSettingsEntityMappingTests
Assert.Equal(entity.IsThemeCachingEnabled, result.Value.IsThemeCachingEnabled);
Assert.Equal(entity.ShouldRenderPdfAsImages, result.Value.ShouldRenderPdfAsImages);
Assert.Equal(entity.ShouldPreserveBookStyles, result.Value.ShouldPreserveBookStyles);
Assert.Equal(entity.VuMeterOrientation, result.Value.VuMeterOrientation);
Assert.Equal(entity.VuMeterSegmentCount, result.Value.VuMeterSegmentCount);
Assert.Equal(entity.VuMeterSegmentGap, result.Value.VuMeterSegmentGap);
Assert.Equal(entity.VuMeterMediumThreshold, result.Value.VuMeterMediumThreshold);
Assert.Equal(entity.VuMeterHighThreshold, result.Value.VuMeterHighThreshold);
Assert.Equal(entity.VuMeterShowPeak, result.Value.VuMeterShowPeak);
Assert.Equal(entity.VuMeterPeakHoldDurationInMilliseconds, result.Value.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(entity.VuMeterReleasePerSecond, result.Value.VuMeterReleasePerSecond);
Assert.Equal(entity.VuMeterPeakReleasePerSecond, result.Value.VuMeterPeakReleasePerSecond);
}
[Fact]
public void ToResponse_WhenMappingValidRepositoryEntity_ShouldMapCorrectly()
{
// Arrange
UserSettingsEntity entity = _userSettingsEntityFixture.Create();
UserSettingsEntity entity = _userSettingsEntityFixture.Create(
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 24,
vuMeterSegmentGap: 2,
vuMeterMediumThreshold: 0.4,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 900,
vuMeterReleasePerSecond: 2.5,
vuMeterPeakReleasePerSecond: 0.9);
// Act
UserSettingsResponse result = entity.ToResponse();
@@ -57,5 +85,14 @@ public class UserSettingsEntityMappingTests
Assert.Equal(entity.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
Assert.Equal(entity.ShouldRenderPdfAsImages, result.ShouldRenderPdfAsImages);
Assert.Equal(entity.ShouldPreserveBookStyles, result.ShouldPreserveBookStyles);
Assert.Equal(entity.VuMeterOrientation, result.VuMeterOrientation);
Assert.Equal(entity.VuMeterSegmentCount, result.VuMeterSegmentCount);
Assert.Equal(entity.VuMeterSegmentGap, result.VuMeterSegmentGap);
Assert.Equal(entity.VuMeterMediumThreshold, result.VuMeterMediumThreshold);
Assert.Equal(entity.VuMeterHighThreshold, result.VuMeterHighThreshold);
Assert.Equal(entity.VuMeterShowPeak, result.VuMeterShowPeak);
Assert.Equal(entity.VuMeterPeakHoldDurationInMilliseconds, result.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(entity.VuMeterReleasePerSecond, result.VuMeterReleasePerSecond);
Assert.Equal(entity.VuMeterPeakReleasePerSecond, result.VuMeterPeakReleasePerSecond);
}
}
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Mapping.UsersManagement.Users;
using Lumina.Contracts.Responses.UsersManagement.Settings;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -23,7 +24,17 @@ public class UserSettingsMappingTests
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettings domainEntity = _userSettingsFixture.Create(userId: userId);
UserSettings domainEntity = _userSettingsFixture.Create(
userId: userId,
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 24,
vuMeterSegmentGap: 2,
vuMeterMediumThreshold: 0.4,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 900,
vuMeterReleasePerSecond: 2.5,
vuMeterPeakReleasePerSecond: 0.9);
// Act
UserSettingsEntity result = domainEntity.ToRepositoryEntity();
@@ -37,6 +48,15 @@ public class UserSettingsMappingTests
Assert.Equal(domainEntity.ShouldIgnoreThePrefixForAlphaPicker, result.ShouldIgnoreThePrefixForAlphaPicker);
Assert.Equal(domainEntity.ShouldRenderPdfAsImages, result.ShouldRenderPdfAsImages);
Assert.Equal(domainEntity.ShouldPreserveBookStyles, result.ShouldPreserveBookStyles);
Assert.Equal(domainEntity.VuMeterOrientation, result.VuMeterOrientation);
Assert.Equal(domainEntity.VuMeterSegmentCount, result.VuMeterSegmentCount);
Assert.Equal(domainEntity.VuMeterSegmentGap, result.VuMeterSegmentGap);
Assert.Equal(domainEntity.VuMeterMediumThreshold, result.VuMeterMediumThreshold);
Assert.Equal(domainEntity.VuMeterHighThreshold, result.VuMeterHighThreshold);
Assert.Equal(domainEntity.VuMeterShowPeak, result.VuMeterShowPeak);
Assert.Equal(domainEntity.VuMeterPeakHoldDurationInMilliseconds, result.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(domainEntity.VuMeterReleasePerSecond, result.VuMeterReleasePerSecond);
Assert.Equal(domainEntity.VuMeterPeakReleasePerSecond, result.VuMeterPeakReleasePerSecond);
}
[Fact]
@@ -44,7 +64,17 @@ public class UserSettingsMappingTests
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettings domainEntity = _userSettingsFixture.Create(userId: userId);
UserSettings domainEntity = _userSettingsFixture.Create(
userId: userId,
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 24,
vuMeterSegmentGap: 2,
vuMeterMediumThreshold: 0.4,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 900,
vuMeterReleasePerSecond: 2.5,
vuMeterPeakReleasePerSecond: 0.9);
// Act
UserSettingsResponse result = domainEntity.ToResponse();
@@ -57,5 +87,14 @@ public class UserSettingsMappingTests
Assert.Equal(domainEntity.ShouldIgnoreThePrefixForAlphaPicker, result.ShouldIgnoreThePrefixForAlphaPicker);
Assert.Equal(domainEntity.ShouldRenderPdfAsImages, result.ShouldRenderPdfAsImages);
Assert.Equal(domainEntity.ShouldPreserveBookStyles, result.ShouldPreserveBookStyles);
Assert.Equal(domainEntity.VuMeterOrientation, result.VuMeterOrientation);
Assert.Equal(domainEntity.VuMeterSegmentCount, result.VuMeterSegmentCount);
Assert.Equal(domainEntity.VuMeterSegmentGap, result.VuMeterSegmentGap);
Assert.Equal(domainEntity.VuMeterMediumThreshold, result.VuMeterMediumThreshold);
Assert.Equal(domainEntity.VuMeterHighThreshold, result.VuMeterHighThreshold);
Assert.Equal(domainEntity.VuMeterShowPeak, result.VuMeterShowPeak);
Assert.Equal(domainEntity.VuMeterPeakHoldDurationInMilliseconds, result.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(domainEntity.VuMeterReleasePerSecond, result.VuMeterReleasePerSecond);
Assert.Equal(domainEntity.VuMeterPeakReleasePerSecond, result.VuMeterPeakReleasePerSecond);
}
}
@@ -53,12 +53,30 @@ public class UserSettingsConfigurationTests
IProperty isPaginationEnabledProperty = entityType.GetProperty(nameof(UserSettingsEntity.IsPaginationEnabled));
IProperty itemsPerPageProperty = entityType.GetProperty(nameof(UserSettingsEntity.ItemsPerPage));
IProperty ignoreThePrefixProperty = entityType.GetProperty(nameof(UserSettingsEntity.ShouldIgnoreThePrefixForAlphaPicker));
IProperty vuMeterOrientationProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterOrientation));
IProperty vuMeterSegmentCountProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterSegmentCount));
IProperty vuMeterSegmentGapProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterSegmentGap));
IProperty vuMeterMediumThresholdProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterMediumThreshold));
IProperty vuMeterHighThresholdProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterHighThreshold));
IProperty vuMeterShowPeakProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterShowPeak));
IProperty vuMeterPeakHoldDurationProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterPeakHoldDurationInMilliseconds));
IProperty vuMeterReleasePerSecondProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterReleasePerSecond));
IProperty vuMeterPeakReleasePerSecondProperty = entityType.GetProperty(nameof(UserSettingsEntity.VuMeterPeakReleasePerSecond));
// Assert
Assert.False(userIdProperty.IsNullable);
Assert.False(isPaginationEnabledProperty.IsNullable);
Assert.False(itemsPerPageProperty.IsNullable);
Assert.False(ignoreThePrefixProperty.IsNullable);
Assert.False(vuMeterOrientationProperty.IsNullable);
Assert.False(vuMeterSegmentCountProperty.IsNullable);
Assert.False(vuMeterSegmentGapProperty.IsNullable);
Assert.False(vuMeterMediumThresholdProperty.IsNullable);
Assert.False(vuMeterHighThresholdProperty.IsNullable);
Assert.False(vuMeterShowPeakProperty.IsNullable);
Assert.False(vuMeterPeakHoldDurationProperty.IsNullable);
Assert.False(vuMeterReleasePerSecondProperty.IsNullable);
Assert.False(vuMeterPeakReleasePerSecondProperty.IsNullable);
}
[Fact]
@@ -79,7 +79,7 @@ public class ErrorsTests
{
// Assert
// The count assertion fails when an error is added or removed, reminding to update the assertions below.
Assert.Equal(13, typeof(DomainErrors.UserSettings).GetProperties().Length);
Assert.Equal(31, typeof(DomainErrors.UserSettings).GetProperties().Length);
AssertError(DomainErrors.UserSettings.UserSettingsAlreadyExists, ErrorType.Conflict);
AssertError(DomainErrors.UserSettings.UserSettingsNotFound, ErrorType.NotFound);
AssertError(DomainErrors.UserSettings.ItemsPerPageMustBeGreaterThanZero, ErrorType.Validation);
@@ -93,6 +93,24 @@ public class ErrorsTests
AssertError(DomainErrors.UserSettings.StreamingQualityCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.InvalidReplayGainMode, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.InvalidStreamingQuality, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterOrientationCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.InvalidVuMeterOrientation, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterSegmentCountCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterSegmentGapCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterMediumThresholdCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterMediumThresholdMustBeBetweenZeroAndOne, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterHighThresholdCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterHighThresholdMustBeBetweenZeroAndOne, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterShowPeakCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterPeakHoldDurationCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterReleasePerSecondCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterPeakReleasePerSecondCannotBeNull, ErrorType.Validation);
AssertError(DomainErrors.UserSettings.VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred, ErrorType.Validation);
}
[Fact]
@@ -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, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto, volume: 1.0, isMuted: false);
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, vuMeterOrientation: VuMeterOrientation.Vertical, vuMeterSegmentCount: 12, vuMeterSegmentGap: 1, vuMeterMediumThreshold: 0.6, vuMeterHighThreshold: 0.8, vuMeterShowPeak: true, vuMeterPeakHoldDurationInMilliseconds: 650, vuMeterReleasePerSecond: 1.5, vuMeterPeakReleasePerSecond: 0.65, volume: 1.0, isMuted: false);
// Assert
Assert.False(result.IsFailure);
@@ -116,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, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto, volume: 1.0, isMuted: false);
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, vuMeterOrientation: VuMeterOrientation.Vertical, vuMeterSegmentCount: 12, vuMeterSegmentGap: 1, vuMeterMediumThreshold: 0.6, vuMeterHighThreshold: 0.8, vuMeterShowPeak: true, vuMeterPeakHoldDurationInMilliseconds: 650, vuMeterReleasePerSecond: 1.5, vuMeterPeakReleasePerSecond: 0.65, volume: 1.0, isMuted: false);
// Assert
Assert.False(result.IsFailure);
@@ -132,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, shouldKeepDownloadingWhilePaused: true, shouldAutoplay: true, isGaplessPlaybackEnabled: true, replayGainMode: ReplayGainMode.Off, streamingQuality: PlaybackStreamingQuality.Auto);
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, vuMeterOrientation: VuMeterOrientation.Vertical, vuMeterSegmentCount: 12, vuMeterSegmentGap: 1, vuMeterMediumThreshold: 0.6, vuMeterHighThreshold: 0.8, vuMeterShowPeak: true, vuMeterPeakHoldDurationInMilliseconds: 650, vuMeterReleasePerSecond: 1.5, vuMeterPeakReleasePerSecond: 0.65);
// Assert
Assert.False(result.IsFailure);