mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 01:11:10 +00:00
Implements tests for commit 2e9f7d8496
This commit is contained in:
1 parent
a75447062f
commit
468f1846f1
18 files changed
+1711
-48
No files matched your search
+29
-1
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSettings;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.UsersManagement.Settings;
|
||||
using Lumina.Contracts.Requests.UsersManagement.Settings;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -27,7 +28,19 @@ public class UpdateUserSettingsRequestMappingTests
|
||||
isThemeCachingEnabled: true,
|
||||
shouldAggregateMetadataWhenMissing: false,
|
||||
shouldRenderPdfAsImages: true,
|
||||
shouldPreserveBookStyles: true
|
||||
shouldPreserveBookStyles: true,
|
||||
shouldKeepDownloadingWhilePaused: false,
|
||||
shouldAutoplay: false,
|
||||
isGaplessPlaybackEnabled: false,
|
||||
vuMeterOrientation: VuMeterOrientation.Horizontal,
|
||||
vuMeterSegmentCount: 20,
|
||||
vuMeterSegmentGap: 4,
|
||||
vuMeterMediumThreshold: 0.35,
|
||||
vuMeterHighThreshold: 0.9,
|
||||
vuMeterShowPeak: false,
|
||||
vuMeterPeakHoldDurationInMilliseconds: 1200,
|
||||
vuMeterReleasePerSecond: 7.5,
|
||||
vuMeterPeakReleasePerSecond: 0.25
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -41,5 +54,20 @@ public class UpdateUserSettingsRequestMappingTests
|
||||
Assert.Equal(request.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
|
||||
Assert.Equal(request.ShouldRenderPdfAsImages, result.ShouldRenderPdfAsImages);
|
||||
Assert.Equal(request.ShouldPreserveBookStyles, result.ShouldPreserveBookStyles);
|
||||
Assert.Equal(request.ShouldKeepDownloadingWhilePaused, result.ShouldKeepDownloadingWhilePaused);
|
||||
Assert.False(result.ShouldKeepDownloadingWhilePaused);
|
||||
Assert.Equal(request.ShouldAutoplay, result.ShouldAutoplay);
|
||||
Assert.False(result.ShouldAutoplay);
|
||||
Assert.Equal(request.IsGaplessPlaybackEnabled, result.IsGaplessPlaybackEnabled);
|
||||
Assert.False(result.IsGaplessPlaybackEnabled);
|
||||
Assert.Equal(VuMeterOrientation.Horizontal, result.VuMeterOrientation);
|
||||
Assert.Equal(20, result.VuMeterSegmentCount);
|
||||
Assert.Equal(4, result.VuMeterSegmentGap);
|
||||
Assert.Equal(0.35, result.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.9, result.VuMeterHighThreshold);
|
||||
Assert.False(result.VuMeterShowPeak);
|
||||
Assert.Equal(1200, result.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(7.5, result.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.25, result.VuMeterPeakReleasePerSecond);
|
||||
}
|
||||
}
|
||||
+121
@@ -801,6 +801,123 @@ public class ValidatorUtilitiesTests
|
||||
result.ShouldNotHaveValidationError(s_equalValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDoubleValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(includeNullableDoubleValue: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDoubleComparisonValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(includeNullableDoubleComparisonValue: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDoubleValueIsGreaterThanComparison_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(
|
||||
nullableDoubleValue: 6.0,
|
||||
nullableDoubleComparisonValue: 5.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDoubleValueEqualsComparison_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(
|
||||
nullableDoubleValue: 5.0,
|
||||
nullableDoubleComparisonValue: 5.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDoubleValueIsSmallerThanComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(
|
||||
nullableDoubleValue: 4.0,
|
||||
nullableDoubleComparisonValue: 5.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveNullableDoubleValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(includeInclusiveNullableDoubleValue: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_inclusiveNullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.99)] // just below the minimum
|
||||
[InlineData(10.01)] // just above the maximum
|
||||
public void Validate_WhenInclusiveNullableDoubleValueIsOutsideRange_ShouldHaveValidationError(double inclusiveNullableDoubleValue)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(
|
||||
inclusiveNullableDoubleValue: inclusiveNullableDoubleValue);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_inclusiveNullableDoubleValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1.0)] // the minimum
|
||||
[InlineData(5.0)] // a middle value
|
||||
[InlineData(10.0)] // the maximum
|
||||
public void Validate_WhenInclusiveNullableDoubleValueIsWithinRange_ShouldNotHaveValidationError(double inclusiveNullableDoubleValue)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(
|
||||
inclusiveNullableDoubleValue: inclusiveNullableDoubleValue);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_inclusiveNullableDoubleValueError);
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
private sealed class ValidatorUtilitiesTestValidator : AbstractValidator<ValidatorUtilitiesTestRequest>
|
||||
{
|
||||
@@ -829,6 +946,8 @@ public class ValidatorUtilitiesTests
|
||||
RuleFor(request => request.SelectorMatchValue).Matches(instance => instance.PatternValue).WithError(s_selectorMatchValueError);
|
||||
RuleFor(request => request.InclusiveIntValue).InclusiveBetween(1, 10).WithError(s_inclusiveIntValueError);
|
||||
RuleFor(request => request.InclusiveNullableIntValue).InclusiveBetween(1, 10).WithError(s_inclusiveNullableIntValueError);
|
||||
RuleFor(request => request.NullableDoubleValue).GreaterThanOrEqualTo(instance => instance.NullableDoubleComparisonValue).WithError(s_nullableDoubleValueError);
|
||||
RuleFor(request => request.InclusiveNullableDoubleValue).InclusiveBetween(1d, 10d).WithError(s_inclusiveNullableDoubleValueError);
|
||||
RuleFor(request => request.EqualValue).Equal(instance => instance.EqualComparisonValue).WithError(s_equalValueError);
|
||||
}
|
||||
}
|
||||
@@ -856,5 +975,7 @@ public class ValidatorUtilitiesTests
|
||||
private static readonly Error s_selectorMatchValueError = Error.Validation(description: "SelectorMatchValueError");
|
||||
private static readonly Error s_inclusiveIntValueError = Error.Validation(description: "InclusiveIntValueError");
|
||||
private static readonly Error s_inclusiveNullableIntValueError = Error.Validation(description: "InclusiveNullableIntValueError");
|
||||
private static readonly Error s_nullableDoubleValueError = Error.Validation(description: "NullableDoubleValueError");
|
||||
private static readonly Error s_inclusiveNullableDoubleValueError = Error.Validation(description: "InclusiveNullableDoubleValueError");
|
||||
private static readonly Error s_equalValueError = Error.Validation(description: "EqualValueError");
|
||||
}
|
||||
+20
-2
@@ -77,7 +77,16 @@ public class UpdateUserSettingsCommandHandlerTests
|
||||
settings.ItemsPerPage == command.ItemsPerPage &&
|
||||
settings.ShouldIgnoreThePrefixForAlphaPicker == command.ShouldIgnoreThePrefixForAlphaPicker &&
|
||||
settings.ShouldRenderPdfAsImages == command.ShouldRenderPdfAsImages &&
|
||||
settings.ShouldPreserveBookStyles == command.ShouldPreserveBookStyles),
|
||||
settings.ShouldPreserveBookStyles == command.ShouldPreserveBookStyles &&
|
||||
settings.VuMeterOrientation == command.VuMeterOrientation &&
|
||||
settings.VuMeterSegmentCount == command.VuMeterSegmentCount &&
|
||||
settings.VuMeterSegmentGap == command.VuMeterSegmentGap &&
|
||||
settings.VuMeterMediumThreshold == command.VuMeterMediumThreshold &&
|
||||
settings.VuMeterHighThreshold == command.VuMeterHighThreshold &&
|
||||
settings.VuMeterShowPeak == command.VuMeterShowPeak &&
|
||||
settings.VuMeterPeakHoldDurationInMilliseconds == command.VuMeterPeakHoldDurationInMilliseconds &&
|
||||
settings.VuMeterReleasePerSecond == command.VuMeterReleasePerSecond &&
|
||||
settings.VuMeterPeakReleasePerSecond == command.VuMeterPeakReleasePerSecond),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockUserSettingsRepository.DidNotReceive().UpdateAsync(Arg.Any<UserSettingsEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -107,7 +116,16 @@ public class UpdateUserSettingsCommandHandlerTests
|
||||
settings.ItemsPerPage == command.ItemsPerPage &&
|
||||
settings.ShouldIgnoreThePrefixForAlphaPicker == command.ShouldIgnoreThePrefixForAlphaPicker &&
|
||||
settings.ShouldRenderPdfAsImages == command.ShouldRenderPdfAsImages &&
|
||||
settings.ShouldPreserveBookStyles == command.ShouldPreserveBookStyles),
|
||||
settings.ShouldPreserveBookStyles == command.ShouldPreserveBookStyles &&
|
||||
settings.VuMeterOrientation == command.VuMeterOrientation &&
|
||||
settings.VuMeterSegmentCount == command.VuMeterSegmentCount &&
|
||||
settings.VuMeterSegmentGap == command.VuMeterSegmentGap &&
|
||||
settings.VuMeterMediumThreshold == command.VuMeterMediumThreshold &&
|
||||
settings.VuMeterHighThreshold == command.VuMeterHighThreshold &&
|
||||
settings.VuMeterShowPeak == command.VuMeterShowPeak &&
|
||||
settings.VuMeterPeakHoldDurationInMilliseconds == command.VuMeterPeakHoldDurationInMilliseconds &&
|
||||
settings.VuMeterReleasePerSecond == command.VuMeterReleasePerSecond &&
|
||||
settings.VuMeterPeakReleasePerSecond == command.VuMeterPeakReleasePerSecond),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockUserSettingsRepository.DidNotReceive().InsertAsync(Arg.Any<UserSettingsEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
|
||||
+449
@@ -4,6 +4,7 @@ using Lumina.Application.Fixtures.Core.UsersManagement.Settings.Commands.UpdateU
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
@@ -51,6 +52,454 @@ public class UpdateUserSettingsCommandValidatorTests
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterOrientationIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterOrientation: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterOrientationCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterSegmentCountIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterSegmentCount: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterSegmentCountCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterSegmentGapIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterSegmentGap: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterSegmentGapCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterMediumThresholdIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterMediumThreshold: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterMediumThresholdCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterHighThresholdIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterHighThreshold: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterHighThresholdCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterShowPeakIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterShowPeak: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterShowPeakCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterPeakHoldDurationIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterPeakHoldDurationInMilliseconds: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterPeakHoldDurationCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterReleasePerSecondIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterReleasePerSecond: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterReleasePerSecondCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterPeakReleasePerSecondIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(includeVuMeterPeakReleasePerSecond: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterPeakReleasePerSecondCannotBeNull);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(999)] // a value that is not a defined member of the enumeration
|
||||
[InlineData(-1)] // a negative value that is not a defined member of the enumeration
|
||||
public void Validate_WhenVuMeterOrientationIsNotDefined_ShouldHaveValidationError(int vuMeterOrientationValue)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterOrientation: (VuMeterOrientation)vuMeterOrientationValue);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.InvalidVuMeterOrientation);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VuMeterOrientation.Vertical)]
|
||||
[InlineData(VuMeterOrientation.Horizontal)]
|
||||
public void Validate_WhenVuMeterOrientationIsDefined_ShouldNotHaveValidationError(VuMeterOrientation vuMeterOrientation)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterOrientation: vuMeterOrientation);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.InvalidVuMeterOrientation);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // below the minimum
|
||||
[InlineData(-1)] // negative
|
||||
[InlineData(129)] // above the maximum
|
||||
[InlineData(int.MaxValue)] // far above the maximum
|
||||
public void Validate_WhenVuMeterSegmentCountIsOutOfRange_ShouldHaveValidationError(int vuMeterSegmentCount)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterSegmentCount: vuMeterSegmentCount);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)] // the minimum
|
||||
[InlineData(64)] // a middle value
|
||||
[InlineData(128)] // the maximum
|
||||
public void Validate_WhenVuMeterSegmentCountIsInRange_ShouldNotHaveValidationError(int vuMeterSegmentCount)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterSegmentCount: vuMeterSegmentCount);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // below the minimum
|
||||
[InlineData(33)] // above the maximum
|
||||
[InlineData(int.MinValue)] // far below the minimum
|
||||
public void Validate_WhenVuMeterSegmentGapIsOutOfRange_ShouldHaveValidationError(int vuMeterSegmentGap)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterSegmentGap: vuMeterSegmentGap);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // the minimum
|
||||
[InlineData(16)] // a middle value
|
||||
[InlineData(32)] // the maximum
|
||||
public void Validate_WhenVuMeterSegmentGapIsInRange_ShouldNotHaveValidationError(int vuMeterSegmentGap)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterSegmentGap: vuMeterSegmentGap);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(1.01)] // just above the maximum
|
||||
[InlineData(double.MinValue)] // far below the minimum
|
||||
public void Validate_WhenVuMeterMediumThresholdIsOutOfRange_ShouldHaveValidationError(double vuMeterMediumThreshold)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: vuMeterMediumThreshold,
|
||||
vuMeterHighThreshold: 1.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterMediumThresholdMustBeBetweenZeroAndOne);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.0)] // the minimum
|
||||
[InlineData(0.5)] // a middle value
|
||||
[InlineData(1.0)] // the maximum
|
||||
public void Validate_WhenVuMeterMediumThresholdIsInRange_ShouldNotHaveValidationError(double vuMeterMediumThreshold)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: vuMeterMediumThreshold,
|
||||
vuMeterHighThreshold: 1.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterMediumThresholdMustBeBetweenZeroAndOne);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(1.01)] // just above the maximum
|
||||
[InlineData(double.MaxValue)] // far above the maximum
|
||||
public void Validate_WhenVuMeterHighThresholdIsOutOfRange_ShouldHaveValidationError(double vuMeterHighThreshold)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: 0.0,
|
||||
vuMeterHighThreshold: vuMeterHighThreshold);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterHighThresholdMustBeBetweenZeroAndOne);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterHighThresholdIsAtTheMinimum_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: 0.0,
|
||||
vuMeterHighThreshold: 0.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterHighThresholdMustBeBetweenZeroAndOne);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterHighThresholdIsAtTheMaximum_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: 0.5,
|
||||
vuMeterHighThreshold: 1.0);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterHighThresholdMustBeBetweenZeroAndOne);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenVuMeterHighThresholdIsLowerThanMediumThreshold_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: 0.9,
|
||||
vuMeterHighThreshold: 0.1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.5, 0.5)] // the thresholds are equal
|
||||
[InlineData(0.4, 0.9)] // the high threshold is greater than the medium one
|
||||
public void Validate_WhenVuMeterHighThresholdIsGreaterThanOrEqualToMediumThreshold_ShouldNotHaveValidationError(
|
||||
double vuMeterMediumThreshold,
|
||||
double vuMeterHighThreshold)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterMediumThreshold: vuMeterMediumThreshold,
|
||||
vuMeterHighThreshold: vuMeterHighThreshold);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Validate_WhenVuMeterShowPeakIsSpecified_ShouldNotHaveValidationError(bool vuMeterShowPeak)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(vuMeterShowPeak: vuMeterShowPeak);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterShowPeakCannotBeNull);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // below the minimum
|
||||
[InlineData(10001)] // above the maximum
|
||||
[InlineData(int.MinValue)] // far below the minimum
|
||||
public void Validate_WhenVuMeterPeakHoldDurationIsOutOfRange_ShouldHaveValidationError(int vuMeterPeakHoldDurationInMilliseconds)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterPeakHoldDurationInMilliseconds: vuMeterPeakHoldDurationInMilliseconds);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // the minimum
|
||||
[InlineData(650)] // a middle value
|
||||
[InlineData(10000)] // the maximum
|
||||
public void Validate_WhenVuMeterPeakHoldDurationIsInRange_ShouldNotHaveValidationError(int vuMeterPeakHoldDurationInMilliseconds)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterPeakHoldDurationInMilliseconds: vuMeterPeakHoldDurationInMilliseconds);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(100.01)] // just above the maximum
|
||||
[InlineData(double.MinValue)] // far below the minimum
|
||||
public void Validate_WhenVuMeterReleasePerSecondIsOutOfRange_ShouldHaveValidationError(double vuMeterReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterReleasePerSecond: vuMeterReleasePerSecond);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.0)] // the minimum
|
||||
[InlineData(3.0)] // a middle value
|
||||
[InlineData(100.0)] // the maximum
|
||||
public void Validate_WhenVuMeterReleasePerSecondIsInRange_ShouldNotHaveValidationError(double vuMeterReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterReleasePerSecond: vuMeterReleasePerSecond);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(100.01)] // just above the maximum
|
||||
[InlineData(double.MaxValue)] // far above the maximum
|
||||
public void Validate_WhenVuMeterPeakReleasePerSecondIsOutOfRange_ShouldHaveValidationError(double vuMeterPeakReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterPeakReleasePerSecond: vuMeterPeakReleasePerSecond);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.UserSettings.VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.0)] // the minimum
|
||||
[InlineData(0.65)] // a middle value
|
||||
[InlineData(100.0)] // the maximum
|
||||
public void Validate_WhenVuMeterPeakReleasePerSecondIsInRange_ShouldNotHaveValidationError(double vuMeterPeakReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserSettingsCommand command = _updateUserSettingsCommandFixture.Create(
|
||||
vuMeterPeakReleasePerSecond: vuMeterPeakReleasePerSecond);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.UserSettings.VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCommandIsValid_ShouldNotHaveAnyValidationError()
|
||||
{
|
||||
|
||||
+39
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -27,6 +28,11 @@ public class UserSettingsConfigurationTests
|
||||
_context = new LuminaDbContext(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite("Data Source=:memory:").Options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the design-time model, which retains configuration such as column order that the read-optimized runtime model omits.
|
||||
/// </summary>
|
||||
private IModel DesignTimeModel => _context.GetService<IDesignTimeModel>().Model;
|
||||
|
||||
[Fact]
|
||||
public void Configure_WhenApplied_ShouldSetTableNameAndKey()
|
||||
{
|
||||
@@ -122,4 +128,37 @@ public class UserSettingsConfigurationTests
|
||||
Assert.False(createdOnUtcProperty.IsNullable);
|
||||
Assert.Null(updatedOnUtcProperty.GetDefaultValue());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Configure_WhenApplied_ShouldConfigureVuMeterAndPlaybackStateColumnOrders()
|
||||
{
|
||||
// Arrange
|
||||
IEntityType entityType = DesignTimeModel.FindEntityType(typeof(UserSettingsEntity))!;
|
||||
|
||||
// Act
|
||||
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));
|
||||
IProperty volumeProperty = entityType.GetProperty(nameof(UserSettingsEntity.Volume));
|
||||
IProperty isMutedProperty = entityType.GetProperty(nameof(UserSettingsEntity.IsMuted));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(19, vuMeterOrientationProperty.GetColumnOrder());
|
||||
Assert.Equal(20, vuMeterSegmentCountProperty.GetColumnOrder());
|
||||
Assert.Equal(21, vuMeterSegmentGapProperty.GetColumnOrder());
|
||||
Assert.Equal(22, vuMeterMediumThresholdProperty.GetColumnOrder());
|
||||
Assert.Equal(23, vuMeterHighThresholdProperty.GetColumnOrder());
|
||||
Assert.Equal(24, vuMeterShowPeakProperty.GetColumnOrder());
|
||||
Assert.Equal(25, vuMeterPeakHoldDurationProperty.GetColumnOrder());
|
||||
Assert.Equal(26, vuMeterReleasePerSecondProperty.GetColumnOrder());
|
||||
Assert.Equal(27, vuMeterPeakReleasePerSecondProperty.GetColumnOrder());
|
||||
Assert.Equal(28, volumeProperty.GetColumnOrder());
|
||||
Assert.Equal(29, isMutedProperty.GetColumnOrder());
|
||||
}
|
||||
}
|
||||
+126
-3
@@ -40,6 +40,15 @@ public class UserSettingsTests
|
||||
Assert.False(result.Value.ShouldAggregateMetadataWhenMissing);
|
||||
Assert.False(result.Value.ShouldRenderPdfAsImages);
|
||||
Assert.True(result.Value.ShouldPreserveBookStyles);
|
||||
Assert.Equal(VuMeterOrientation.Vertical, result.Value.VuMeterOrientation);
|
||||
Assert.Equal(12, result.Value.VuMeterSegmentCount);
|
||||
Assert.Equal(1, result.Value.VuMeterSegmentGap);
|
||||
Assert.Equal(0.6, result.Value.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.8, result.Value.VuMeterHighThreshold);
|
||||
Assert.True(result.Value.VuMeterShowPeak);
|
||||
Assert.Equal(650, result.Value.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(3.0, result.Value.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.65, result.Value.VuMeterPeakReleasePerSecond);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -57,6 +66,15 @@ public class UserSettingsTests
|
||||
Assert.False(result.Value.ShouldAggregateMetadataWhenMissing);
|
||||
Assert.False(result.Value.ShouldRenderPdfAsImages);
|
||||
Assert.True(result.Value.ShouldPreserveBookStyles);
|
||||
Assert.Equal(VuMeterOrientation.Vertical, result.Value.VuMeterOrientation);
|
||||
Assert.Equal(12, result.Value.VuMeterSegmentCount);
|
||||
Assert.Equal(1, result.Value.VuMeterSegmentGap);
|
||||
Assert.Equal(0.6, result.Value.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.8, result.Value.VuMeterHighThreshold);
|
||||
Assert.True(result.Value.VuMeterShowPeak);
|
||||
Assert.Equal(650, result.Value.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(3.0, result.Value.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.65, result.Value.VuMeterPeakReleasePerSecond);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,7 +98,32 @@ 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, 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);
|
||||
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.Horizontal,
|
||||
vuMeterSegmentCount: 20,
|
||||
vuMeterSegmentGap: 4,
|
||||
vuMeterMediumThreshold: 0.35,
|
||||
vuMeterHighThreshold: 0.9,
|
||||
vuMeterShowPeak: false,
|
||||
vuMeterPeakHoldDurationInMilliseconds: 1200,
|
||||
vuMeterReleasePerSecond: 7.5,
|
||||
vuMeterPeakReleasePerSecond: 0.25,
|
||||
volume: 1.0,
|
||||
isMuted: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -92,6 +135,15 @@ public class UserSettingsTests
|
||||
Assert.True(result.Value.ShouldAggregateMetadataWhenMissing);
|
||||
Assert.True(result.Value.ShouldRenderPdfAsImages);
|
||||
Assert.True(result.Value.ShouldPreserveBookStyles);
|
||||
Assert.Equal(VuMeterOrientation.Horizontal, result.Value.VuMeterOrientation);
|
||||
Assert.Equal(20, result.Value.VuMeterSegmentCount);
|
||||
Assert.Equal(4, result.Value.VuMeterSegmentGap);
|
||||
Assert.Equal(0.35, result.Value.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.9, result.Value.VuMeterHighThreshold);
|
||||
Assert.False(result.Value.VuMeterShowPeak);
|
||||
Assert.Equal(1200, result.Value.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(7.5, result.Value.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.25, result.Value.VuMeterPeakReleasePerSecond);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -116,13 +168,48 @@ 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, 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);
|
||||
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.Horizontal,
|
||||
vuMeterSegmentCount: 24,
|
||||
vuMeterSegmentGap: 3,
|
||||
vuMeterMediumThreshold: 0.4,
|
||||
vuMeterHighThreshold: 0.95,
|
||||
vuMeterShowPeak: false,
|
||||
vuMeterPeakHoldDurationInMilliseconds: 800,
|
||||
vuMeterReleasePerSecond: 9.5,
|
||||
vuMeterPeakReleasePerSecond: 0.5,
|
||||
volume: 1.0,
|
||||
isMuted: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id);
|
||||
Assert.Equal(userId, result.Value.UserId);
|
||||
Assert.Equal(24, result.Value.ItemsPerPage);
|
||||
Assert.Equal(VuMeterOrientation.Horizontal, result.Value.VuMeterOrientation);
|
||||
Assert.Equal(24, result.Value.VuMeterSegmentCount);
|
||||
Assert.Equal(3, result.Value.VuMeterSegmentGap);
|
||||
Assert.Equal(0.4, result.Value.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.95, result.Value.VuMeterHighThreshold);
|
||||
Assert.False(result.Value.VuMeterShowPeak);
|
||||
Assert.Equal(800, result.Value.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(9.5, result.Value.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.5, result.Value.VuMeterPeakReleasePerSecond);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -130,9 +217,33 @@ public class UserSettingsTests
|
||||
{
|
||||
// Arrange
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
double previousVolume = userSettings.Volume;
|
||||
bool previousIsMuted = userSettings.IsMuted;
|
||||
|
||||
// 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, vuMeterOrientation: VuMeterOrientation.Vertical, vuMeterSegmentCount: 12, vuMeterSegmentGap: 1, vuMeterMediumThreshold: 0.6, vuMeterHighThreshold: 0.8, vuMeterShowPeak: true, vuMeterPeakHoldDurationInMilliseconds: 650, vuMeterReleasePerSecond: 1.5, vuMeterPeakReleasePerSecond: 0.65);
|
||||
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.Horizontal,
|
||||
vuMeterSegmentCount: 30,
|
||||
vuMeterSegmentGap: 5,
|
||||
vuMeterMediumThreshold: 0.3,
|
||||
vuMeterHighThreshold: 0.95,
|
||||
vuMeterShowPeak: false,
|
||||
vuMeterPeakHoldDurationInMilliseconds: 1500,
|
||||
vuMeterReleasePerSecond: 8.0,
|
||||
vuMeterPeakReleasePerSecond: 0.4);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -143,5 +254,17 @@ public class UserSettingsTests
|
||||
Assert.True(userSettings.ShouldAggregateMetadataWhenMissing);
|
||||
Assert.True(userSettings.ShouldRenderPdfAsImages);
|
||||
Assert.True(userSettings.ShouldPreserveBookStyles);
|
||||
Assert.Equal(VuMeterOrientation.Horizontal, userSettings.VuMeterOrientation);
|
||||
Assert.Equal(30, userSettings.VuMeterSegmentCount);
|
||||
Assert.Equal(5, userSettings.VuMeterSegmentGap);
|
||||
Assert.Equal(0.3, userSettings.VuMeterMediumThreshold);
|
||||
Assert.Equal(0.95, userSettings.VuMeterHighThreshold);
|
||||
Assert.False(userSettings.VuMeterShowPeak);
|
||||
Assert.Equal(1500, userSettings.VuMeterPeakHoldDurationInMilliseconds);
|
||||
Assert.Equal(8.0, userSettings.VuMeterReleasePerSecond);
|
||||
Assert.Equal(0.4, userSettings.VuMeterPeakReleasePerSecond);
|
||||
// The playback state the player reports automatically is not part of the settings the user edits.
|
||||
Assert.Equal(previousVolume, userSettings.Volume);
|
||||
Assert.Equal(previousIsMuted, userSettings.IsMuted);
|
||||
}
|
||||
}
|
||||
+38
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.UpdateUserSettings;
|
||||
@@ -70,4 +71,41 @@ public class UpdateUserSettingsEndpointTests
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("data").GetProperty("isUpdated").GetBoolean());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldForwardVuMeterSettingsToApi()
|
||||
{
|
||||
// Arrange
|
||||
UserSettingsDto request = _userSettingsDtoFixture.Create(
|
||||
vuMeterOrientation: VuMeterOrientation.Horizontal,
|
||||
vuMeterSegmentCount: 20,
|
||||
vuMeterSegmentGap: 4,
|
||||
vuMeterMediumThreshold: 0.35,
|
||||
vuMeterHighThreshold: 0.9,
|
||||
vuMeterShowPeak: false,
|
||||
vuMeterPeakHoldDurationInMilliseconds: 1200,
|
||||
vuMeterReleasePerSecond: 7.5,
|
||||
vuMeterPeakReleasePerSecond: 0.25);
|
||||
_mockApiHttpClient.PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(Arg.Any<string>(), Arg.Any<UserSettingsDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(
|
||||
ApiRoutes.Users.UPDATE_USER_SETTINGS,
|
||||
Arg.Is<UserSettingsDto>(settings =>
|
||||
settings.VuMeterOrientation == VuMeterOrientation.Horizontal &&
|
||||
settings.VuMeterSegmentCount == 20 &&
|
||||
settings.VuMeterSegmentGap == 4 &&
|
||||
settings.VuMeterMediumThreshold == 0.35 &&
|
||||
settings.VuMeterHighThreshold == 0.9 &&
|
||||
settings.VuMeterShowPeak == false &&
|
||||
settings.VuMeterPeakHoldDurationInMilliseconds == 1200 &&
|
||||
settings.VuMeterReleasePerSecond == 7.5 &&
|
||||
settings.VuMeterPeakReleasePerSecond == 0.25),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user