Implements tests for commit 2e9f7d8496

This commit is contained in:
BinaryAlley committed 2026-10-28 23:50:00 +02:00
1 parent a75447062f
commit 468f1846f1
18 files changed
+1711 -48

No files matched your search

@@ -36,4 +36,7 @@ public sealed record ValidatorUtilitiesTestRequest(
int? InclusiveNullableIntValue,
string? EqualValue,
string? EqualComparisonValue,
string? TextualEnumValue);
string? TextualEnumValue,
double? NullableDoubleValue,
double? NullableDoubleComparisonValue,
double? InclusiveNullableDoubleValue);
@@ -15,6 +15,9 @@ namespace Lumina.Application.Fixtures.Common.Utilities;
public class ValidatorUtilitiesTestRequestFixture
{
private const string ValidPattern = "^[a-z]{3}-\\d{3}$";
private const double VALID_NULLABLE_DOUBLE_VALUE = 7.5;
private const double VALID_NULLABLE_DOUBLE_COMPARISON_VALUE = 5.0;
private const double VALID_INCLUSIVE_NULLABLE_DOUBLE_VALUE = 5.0;
/// <summary>
/// Creates a new <see cref="ValidatorUtilitiesTestRequest"/> instance with randomized test data that satisfies all validation rules.
@@ -45,6 +48,12 @@ public class ValidatorUtilitiesTestRequestFixture
/// <param name="equalValue">Optional. The value that must equal the comparison value.</param>
/// <param name="equalComparisonValue">Optional. The comparison value.</param>
/// <param name="textualEnumValue">Optional. The textual enum value that must be a member name of the test enumeration.</param>
/// <param name="nullableDoubleValue">Optional. The nullable double value that must be greater than or equal to the selected comparison value.</param>
/// <param name="nullableDoubleComparisonValue">Optional. The nullable double comparison value selected from the request.</param>
/// <param name="inclusiveNullableDoubleValue">Optional. The nullable double value that must be between 1 and 10.</param>
/// <param name="includeNullableDoubleValue">Whether to generate the nullable double value, or leave it <see langword="null"/>.</param>
/// <param name="includeNullableDoubleComparisonValue">Whether to generate the nullable double comparison value, or leave it <see langword="null"/>.</param>
/// <param name="includeInclusiveNullableDoubleValue">Whether to generate the inclusive nullable double value, or leave it <see langword="null"/>.</param>
/// <returns>A configured <see cref="ValidatorUtilitiesTestRequest"/> instance.</returns>
public ValidatorUtilitiesTestRequest Create(
int? intValue = null,
@@ -72,7 +81,13 @@ public class ValidatorUtilitiesTestRequestFixture
int? inclusiveNullableIntValue = null,
string? equalValue = null,
string? equalComparisonValue = null,
string? textualEnumValue = null)
string? textualEnumValue = null,
double? nullableDoubleValue = null,
double? nullableDoubleComparisonValue = null,
double? inclusiveNullableDoubleValue = null,
bool includeNullableDoubleValue = true,
bool includeNullableDoubleComparisonValue = true,
bool includeInclusiveNullableDoubleValue = true)
{
string resolvedPattern = patternValue ?? ValidPattern;
return new Faker<ValidatorUtilitiesTestRequest>()
@@ -102,7 +117,10 @@ public class ValidatorUtilitiesTestRequestFixture
InclusiveNullableIntValue: inclusiveNullableIntValue ?? f.Random.Int(1, 10),
EqualValue: equalValue ?? "same",
EqualComparisonValue: equalComparisonValue ?? "same",
TextualEnumValue: textualEnumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>().ToString()))
TextualEnumValue: textualEnumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>().ToString(),
NullableDoubleValue: includeNullableDoubleValue ? nullableDoubleValue ?? VALID_NULLABLE_DOUBLE_VALUE : null,
NullableDoubleComparisonValue: includeNullableDoubleComparisonValue ? nullableDoubleComparisonValue ?? VALID_NULLABLE_DOUBLE_COMPARISON_VALUE : null,
InclusiveNullableDoubleValue: includeInclusiveNullableDoubleValue ? inclusiveNullableDoubleValue ?? VALID_INCLUSIVE_NULLABLE_DOUBLE_VALUE : null))
.Generate();
}
@@ -41,6 +41,15 @@ public class UpdateUserSettingsCommandFixture
/// <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="includeVuMeterOrientation">Whether to generate the VU meter orientation, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentCount">Whether to generate the VU meter segment count, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentGap">Whether to generate the VU meter segment gap, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterMediumThreshold">Whether to generate the VU meter medium threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterHighThreshold">Whether to generate the VU meter high threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterShowPeak">Whether to generate the VU meter peak marker setting, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakHoldDurationInMilliseconds">Whether to generate the VU meter peak hold duration, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterReleasePerSecond">Whether to generate the VU meter release rate, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakReleasePerSecond">Whether to generate the VU meter peak release rate, or leave it <see langword="null"/>.</param>
/// <returns>The created command.</returns>
public UpdateUserSettingsCommand Create(
bool? isPaginationEnabled = null,
@@ -64,11 +73,24 @@ public class UpdateUserSettingsCommandFixture
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null)
double? vuMeterPeakReleasePerSecond = null,
bool includeVuMeterOrientation = true,
bool includeVuMeterSegmentCount = true,
bool includeVuMeterSegmentGap = true,
bool includeVuMeterMediumThreshold = true,
bool includeVuMeterHighThreshold = true,
bool includeVuMeterShowPeak = true,
bool includeVuMeterPeakHoldDurationInMilliseconds = true,
bool includeVuMeterReleasePerSecond = true,
bool includeVuMeterPeakReleasePerSecond = true)
{
// 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));
double? mediumThreshold = includeVuMeterMediumThreshold
? vuMeterMediumThreshold ?? Random.Shared.NextDouble()
: null;
double? highThreshold = includeVuMeterHighThreshold
? vuMeterHighThreshold ?? (mediumThreshold is null ? Random.Shared.NextDouble() : mediumThreshold.Value + Random.Shared.NextDouble() * (1 - mediumThreshold.Value))
: null;
return new Faker<UpdateUserSettingsCommand>()
.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())
@@ -84,15 +106,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.VuMeterOrientation, f => includeVuMeterOrientation ? vuMeterOrientation ?? f.PickRandom<VuMeterOrientation>() : null)
.RuleFor(x => x.VuMeterSegmentCount, f => includeVuMeterSegmentCount ? vuMeterSegmentCount ?? f.Random.Int(1, 128) : null)
.RuleFor(x => x.VuMeterSegmentGap, f => includeVuMeterSegmentGap ? vuMeterSegmentGap ?? f.Random.Int(0, 32) : null)
.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))
.RuleFor(x => x.VuMeterShowPeak, f => includeVuMeterShowPeak ? vuMeterShowPeak ?? f.Random.Bool() : null)
.RuleFor(x => x.VuMeterPeakHoldDurationInMilliseconds, f => includeVuMeterPeakHoldDurationInMilliseconds ? vuMeterPeakHoldDurationInMilliseconds ?? f.Random.Int(0, 10000) : null)
.RuleFor(x => x.VuMeterReleasePerSecond, f => includeVuMeterReleasePerSecond ? vuMeterReleasePerSecond ?? f.Random.Double(0, 100) : null)
.RuleFor(x => x.VuMeterPeakReleasePerSecond, f => includeVuMeterPeakReleasePerSecond ? vuMeterPeakReleasePerSecond ?? f.Random.Double(0, 100) : null)
.Generate();
}
@@ -42,6 +42,15 @@ public class UpdateUserSettingsRequestFixture
/// <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="includeVuMeterOrientation">Whether to generate the VU meter orientation, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentCount">Whether to generate the VU meter segment count, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentGap">Whether to generate the VU meter segment gap, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterMediumThreshold">Whether to generate the VU meter medium threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterHighThreshold">Whether to generate the VU meter high threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterShowPeak">Whether to generate the VU meter peak marker setting, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakHoldDurationInMilliseconds">Whether to generate the VU meter peak hold duration, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterReleasePerSecond">Whether to generate the VU meter release rate, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakReleasePerSecond">Whether to generate the VU meter peak release rate, or leave it <see langword="null"/>.</param>
/// <returns>The created <see cref="UpdateUserSettingsRequest"/>.</returns>
public UpdateUserSettingsRequest Create(
bool? isPaginationEnabled = null,
@@ -65,11 +74,24 @@ public class UpdateUserSettingsRequestFixture
bool? vuMeterShowPeak = null,
int? vuMeterPeakHoldDurationInMilliseconds = null,
double? vuMeterReleasePerSecond = null,
double? vuMeterPeakReleasePerSecond = null)
double? vuMeterPeakReleasePerSecond = null,
bool includeVuMeterOrientation = true,
bool includeVuMeterSegmentCount = true,
bool includeVuMeterSegmentGap = true,
bool includeVuMeterMediumThreshold = true,
bool includeVuMeterHighThreshold = true,
bool includeVuMeterShowPeak = true,
bool includeVuMeterPeakHoldDurationInMilliseconds = true,
bool includeVuMeterReleasePerSecond = true,
bool includeVuMeterPeakReleasePerSecond = true)
{
// 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);
double? mediumThreshold = includeVuMeterMediumThreshold
? vuMeterMediumThreshold ?? _faker.Random.Double(0, 1)
: null;
double? highThreshold = includeVuMeterHighThreshold
? vuMeterHighThreshold ?? (mediumThreshold is null ? _faker.Random.Double(0, 1) : _faker.Random.Double(mediumThreshold.Value, 1))
: null;
return new UpdateUserSettingsRequest(
isPaginationEnabled ?? _faker.Random.Bool(),
itemsPerPage ?? _faker.Random.Int(1, 100),
@@ -84,15 +106,15 @@ public class UpdateUserSettingsRequestFixture
isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>(),
vuMeterOrientation ?? _faker.PickRandom<VuMeterOrientation>(),
vuMeterSegmentCount ?? _faker.Random.Int(1, 128),
vuMeterSegmentGap ?? _faker.Random.Int(0, 32),
includeVuMeterOrientation ? vuMeterOrientation ?? _faker.PickRandom<VuMeterOrientation>() : null,
includeVuMeterSegmentCount ? vuMeterSegmentCount ?? _faker.Random.Int(1, 128) : null,
includeVuMeterSegmentGap ? vuMeterSegmentGap ?? _faker.Random.Int(0, 32) : null,
mediumThreshold,
highThreshold,
vuMeterShowPeak ?? _faker.Random.Bool(),
vuMeterPeakHoldDurationInMilliseconds ?? _faker.Random.Int(0, 10000),
vuMeterReleasePerSecond ?? _faker.Random.Double(0, 100),
vuMeterPeakReleasePerSecond ?? _faker.Random.Double(0, 100));
includeVuMeterShowPeak ? vuMeterShowPeak ?? _faker.Random.Bool() : null,
includeVuMeterPeakHoldDurationInMilliseconds ? vuMeterPeakHoldDurationInMilliseconds ?? _faker.Random.Int(0, 10000) : null,
includeVuMeterReleasePerSecond ? vuMeterReleasePerSecond ?? _faker.Random.Double(0, 100) : null,
includeVuMeterPeakReleasePerSecond ? vuMeterPeakReleasePerSecond ?? _faker.Random.Double(0, 100) : null);
}
/// <summary>
@@ -34,6 +34,24 @@ public class UserSettingsDtoFixture
/// <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="includeVuMeterOrientation">Whether to generate the VU meter orientation, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentCount">Whether to generate the VU meter segment count, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterSegmentGap">Whether to generate the VU meter segment gap, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterMediumThreshold">Whether to generate the VU meter medium threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterHighThreshold">Whether to generate the VU meter high threshold, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterShowPeak">Whether to generate the VU meter peak marker setting, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakHoldDurationInMilliseconds">Whether to generate the VU meter peak hold duration, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterReleasePerSecond">Whether to generate the VU meter release rate, or leave it <see langword="null"/>.</param>
/// <param name="includeVuMeterPeakReleasePerSecond">Whether to generate the VU meter peak release rate, or leave it <see langword="null"/>.</param>
/// <returns>A configured <see cref="UserSettingsDto"/> instance.</returns>
public UserSettingsDto Create(
Guid? userId = null,
@@ -48,8 +66,33 @@ public class UserSettingsDtoFixture
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,
bool includeVuMeterOrientation = true,
bool includeVuMeterSegmentCount = true,
bool includeVuMeterSegmentGap = true,
bool includeVuMeterMediumThreshold = true,
bool includeVuMeterHighThreshold = true,
bool includeVuMeterShowPeak = true,
bool includeVuMeterPeakHoldDurationInMilliseconds = true,
bool includeVuMeterReleasePerSecond = true,
bool includeVuMeterPeakReleasePerSecond = true)
{
// The high threshold is generated from the medium one, so a randomized meter always describes a valid meter.
double? mediumThreshold = includeVuMeterMediumThreshold
? vuMeterMediumThreshold ?? _faker.Random.Double(0, 1)
: null;
double? highThreshold = includeVuMeterHighThreshold
? vuMeterHighThreshold ?? (mediumThreshold is null ? _faker.Random.Double(0, 1) : _faker.Random.Double(mediumThreshold.Value, 1))
: null;
return new UserSettingsDto
{
UserId = userId ?? Guid.NewGuid(),
@@ -64,7 +107,16 @@ public class UserSettingsDtoFixture
ShouldAutoplay = shouldAutoplay ?? _faker.Random.Bool(),
IsGaplessPlaybackEnabled = isGaplessPlaybackEnabled ?? _faker.Random.Bool(),
ReplayGainMode = replayGainMode ?? _faker.PickRandom<ReplayGainMode>(),
StreamingQuality = streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>()
StreamingQuality = streamingQuality ?? _faker.PickRandom<PlaybackStreamingQuality>(),
VuMeterOrientation = includeVuMeterOrientation ? vuMeterOrientation ?? _faker.PickRandom<VuMeterOrientation>() : null,
VuMeterSegmentCount = includeVuMeterSegmentCount ? vuMeterSegmentCount ?? _faker.Random.Int(1, 128) : null,
VuMeterSegmentGap = includeVuMeterSegmentGap ? vuMeterSegmentGap ?? _faker.Random.Int(0, 32) : null,
VuMeterMediumThreshold = mediumThreshold,
VuMeterHighThreshold = highThreshold,
VuMeterShowPeak = includeVuMeterShowPeak ? vuMeterShowPeak ?? _faker.Random.Bool() : null,
VuMeterPeakHoldDurationInMilliseconds = includeVuMeterPeakHoldDurationInMilliseconds ? vuMeterPeakHoldDurationInMilliseconds ?? _faker.Random.Int(0, 10000) : null,
VuMeterReleasePerSecond = includeVuMeterReleasePerSecond ? vuMeterReleasePerSecond ?? _faker.Random.Double(0, 100) : null,
VuMeterPeakReleasePerSecond = includeVuMeterPeakReleasePerSecond ? vuMeterPeakReleasePerSecond ?? _faker.Random.Double(0, 100) : null
};
}