mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+91
@@ -0,0 +1,91 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AudioFileFormatUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AudioFileFormatUtilitiesTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("track.mp3", AudioFileFormat.MP3)] // MP3 audio file.
|
||||
[InlineData("track.flac", AudioFileFormat.FLAC)] // FLAC audio file.
|
||||
[InlineData("track.m4a", AudioFileFormat.M4A)] // M4A audio file.
|
||||
[InlineData("track.aac", AudioFileFormat.AAC)] // AAC audio file.
|
||||
[InlineData("track.ogg", AudioFileFormat.OGG)] // OGG audio file.
|
||||
[InlineData("track.opus", AudioFileFormat.OPUS)] // Opus audio file.
|
||||
[InlineData("track.wav", AudioFileFormat.WAV)] // WAV audio file.
|
||||
[InlineData("track.wma", AudioFileFormat.WMA)] // WMA audio file.
|
||||
[InlineData("track.aiff", AudioFileFormat.AIFF)] // AIFF audio file.
|
||||
[InlineData("track.aif", AudioFileFormat.AIFF)] // AIF audio file.
|
||||
[InlineData("track.ape", AudioFileFormat.APE)] // APE audio file.
|
||||
[InlineData("track.wv", AudioFileFormat.WAVPACK)] // WavPack audio file.
|
||||
[InlineData("track.dsf", AudioFileFormat.DSF)] // DSF audio file.
|
||||
[InlineData("track.dff", AudioFileFormat.DFF)] // DFF audio file.
|
||||
[InlineData("track.mka", AudioFileFormat.MATROSKA)] // Matroska audio file.
|
||||
public void ToAudioFileFormat_WhenExtensionIsKnown_ShouldReturnMappedFormat(string filePath, AudioFileFormat expectedFormat)
|
||||
{
|
||||
// Act
|
||||
AudioFileFormat result = filePath.ToAudioFileFormat();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedFormat, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToAudioFileFormat_WhenExtensionIsUnknown_ShouldReturnNone()
|
||||
{
|
||||
// Arrange
|
||||
string filePath = "track.unknown";
|
||||
|
||||
// Act
|
||||
AudioFileFormat result = filePath.ToAudioFileFormat();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(AudioFileFormat.None, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToAudioFileFormat_WhenFileHasNoExtension_ShouldReturnNone()
|
||||
{
|
||||
// Arrange
|
||||
string filePath = "track";
|
||||
|
||||
// Act
|
||||
AudioFileFormat result = filePath.ToAudioFileFormat();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(AudioFileFormat.None, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToAudioFileFormat_WhenExtensionIsMixedCase_ShouldResolveCaseInsensitively()
|
||||
{
|
||||
// Arrange
|
||||
string filePath = "Track.MP3";
|
||||
|
||||
// Act
|
||||
AudioFileFormat result = filePath.ToAudioFileFormat();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(AudioFileFormat.MP3, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToAudioFileFormat_WhenFilePathContainsDirectoriesAndMixedCaseExtension_ShouldReturnMappedFormat()
|
||||
{
|
||||
// Arrange
|
||||
string filePath = "library/music/Queen/A Night at the Opera (1975).Remastered/01 - Bohemian Rhapsody.FLAC";
|
||||
|
||||
// Act
|
||||
AudioFileFormat result = filePath.ToAudioFileFormat();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(AudioFileFormat.FLAC, result);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DurationUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DurationUtilitiesTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsZero_ShouldReturnTimeSpanZero()
|
||||
{
|
||||
// Act
|
||||
TimeSpan result = 0L.ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(TimeSpan.Zero, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 0.001)] // A single millisecond is preserved.
|
||||
[InlineData(1_500, 1.5)] // Whole milliseconds convert to fractional seconds.
|
||||
[InlineData(60_000, 60)] // A full minute converts exactly.
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsWithinTheRepresentableRange_ShouldConvertToTheEquivalentSeconds(long milliseconds, double expectedTotalSeconds)
|
||||
{
|
||||
// Act
|
||||
TimeSpan result = milliseconds.ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedTotalSeconds, result.TotalSeconds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // A single negative millisecond.
|
||||
[InlineData(-1_500)] // Negative fractional seconds.
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsNegative_ShouldReturnTheEquivalentNegativeDuration(long milliseconds)
|
||||
{
|
||||
// Act
|
||||
TimeSpan result = milliseconds.ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(TimeSpan.FromMilliseconds(milliseconds), result);
|
||||
Assert.True(result < TimeSpan.Zero);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsTheMaximumRepresentableValue_ShouldReturnTheEquivalentDuration()
|
||||
{
|
||||
// Arrange
|
||||
long maximumMilliseconds = TimeSpan.MaxValue.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
|
||||
// Act
|
||||
TimeSpan result = maximumMilliseconds.ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(TimeSpan.FromMilliseconds(maximumMilliseconds), result);
|
||||
Assert.True(result <= TimeSpan.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsLongMaxValue_ShouldClampToTheMaximumRepresentableDuration()
|
||||
{
|
||||
// Arrange
|
||||
long maximumMilliseconds = TimeSpan.MaxValue.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
TimeSpan expectedClampedDuration = TimeSpan.FromMilliseconds(maximumMilliseconds);
|
||||
|
||||
// Act
|
||||
TimeSpan result = long.MaxValue.ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedClampedDuration, result);
|
||||
Assert.Equal(expectedClampedDuration.TotalSeconds, result.TotalSeconds);
|
||||
Assert.True(double.IsFinite(result.TotalSeconds));
|
||||
Assert.True(result <= TimeSpan.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToClampedTimeSpan_WhenMillisecondsIsOneAboveTheMaximumRepresentableValue_ShouldClampToTheMaximumRepresentableDuration()
|
||||
{
|
||||
// Arrange
|
||||
long maximumMilliseconds = TimeSpan.MaxValue.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
TimeSpan expectedClampedDuration = TimeSpan.FromMilliseconds(maximumMilliseconds);
|
||||
|
||||
// Act
|
||||
TimeSpan result = (maximumMilliseconds + 1).ToClampedTimeSpan();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedClampedDuration, result);
|
||||
Assert.True(result <= TimeSpan.MaxValue);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FavoriteMediaKindExtensions"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteMediaKindExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(FavoriteMediaKind.MusicArtist, nameof(DomainErrors.Music.ArtistNotFound))] // An artist has no library of its own.
|
||||
[InlineData(FavoriteMediaKind.MusicAlbum, nameof(DomainErrors.Music.AlbumNotFound))] // An album is not a media item that can be favorited.
|
||||
[InlineData(FavoriteMediaKind.MusicTrack, nameof(DomainErrors.Music.TrackNotFound))] // A track is resolved through the music catalogue.
|
||||
[InlineData(FavoriteMediaKind.Book, nameof(DomainErrors.WrittenContent.BookNotFound))] // A book is resolved through the written content catalogue.
|
||||
public void ToMediaItemNotFoundError_WhenTheMediaKindIsCatalogued_ShouldReturnTheMediaSpecificNotFoundError(FavoriteMediaKind mediaKind, string expectedDescription)
|
||||
{
|
||||
// Act
|
||||
Error error = mediaKind.ToMediaItemNotFoundError();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedDescription, error.Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(FavoriteMediaKind.None)] // The default value, which is not a kind that can be favorited.
|
||||
[InlineData(FavoriteMediaKind.Video)] // Video libraries are not catalogued yet.
|
||||
[InlineData(FavoriteMediaKind.Photo)] // Photo libraries are not catalogued yet.
|
||||
public void ToMediaItemNotFoundError_WhenTheMediaKindIsNotCatalogued_ShouldReturnTheNotSupportedError(FavoriteMediaKind mediaKind)
|
||||
{
|
||||
// Act
|
||||
Error error = mediaKind.ToMediaItemNotFoundError();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(DomainErrors.Favorites.FavoriteMediaKindIsNotSupported, error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMediaItemNotFoundError_WhenTheMediaKindIsUndefined_ShouldReturnTheNotSupportedError()
|
||||
{
|
||||
// Arrange
|
||||
FavoriteMediaKind mediaKind = (FavoriteMediaKind)int.MaxValue;
|
||||
|
||||
// Act
|
||||
Error error = mediaKind.ToMediaItemNotFoundError();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(DomainErrors.Favorites.FavoriteMediaKindIsNotSupported, error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TaskUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TaskUtilitiesTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task FireAndForgetSafeAsync_WhenTaskCompletesSuccessfully_ShouldInvokeOnComplete()
|
||||
{
|
||||
// Arrange
|
||||
TaskCompletionSource<bool> completionSource = new();
|
||||
bool onCompleteInvoked = false;
|
||||
|
||||
// Act
|
||||
Task.CompletedTask.FireAndForgetSafeAsync(() =>
|
||||
{
|
||||
onCompleteInvoked = true;
|
||||
completionSource.SetResult(true);
|
||||
});
|
||||
|
||||
// Assert
|
||||
await completionSource.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.True(onCompleteInvoked);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FireAndForgetSafeAsync_WhenTaskFaults_ShouldSwallowExceptionAndInvokeOnComplete()
|
||||
{
|
||||
// Arrange
|
||||
TaskCompletionSource<bool> completionSource = new();
|
||||
bool onCompleteInvoked = false;
|
||||
Task faultedTask = Task.FromException(new InvalidOperationException("Expected failure"));
|
||||
|
||||
// Act
|
||||
faultedTask.FireAndForgetSafeAsync(() =>
|
||||
{
|
||||
onCompleteInvoked = true;
|
||||
completionSource.SetResult(true);
|
||||
});
|
||||
|
||||
// Assert
|
||||
await completionSource.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.True(onCompleteInvoked);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FireAndForgetSafeAsync_WhenTaskIsCanceled_ShouldSwallowExceptionAndInvokeOnComplete()
|
||||
{
|
||||
// Arrange
|
||||
TaskCompletionSource<bool> completionSource = new();
|
||||
bool onCompleteInvoked = false;
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
Task canceledTask = Task.FromCanceled(cancellationTokenSource.Token);
|
||||
|
||||
// Act
|
||||
canceledTask.FireAndForgetSafeAsync(() =>
|
||||
{
|
||||
onCompleteInvoked = true;
|
||||
completionSource.SetResult(true);
|
||||
});
|
||||
|
||||
// Assert
|
||||
await completionSource.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.True(onCompleteInvoked);
|
||||
}
|
||||
}
|
||||
+981
@@ -0,0 +1,981 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Application.Fixtures.Common.Utilities;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatorUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatorUtilitiesTests
|
||||
{
|
||||
private readonly ValidatorUtilitiesTestValidator _validator = new();
|
||||
private readonly ValidatorUtilitiesTestRequestFixture _validatorUtilitiesTestRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRequestIsFullyValid_ShouldNotHaveAnyValidationErrors()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(4)] // Value is greater than the comparison value.
|
||||
[InlineData(100)] // Value is much greater than the comparison value.
|
||||
public void Validate_WhenIntValueIsGreaterThanComparison_ShouldNotHaveValidationError(int value)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { IntValue = value };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_intValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(3)] // Value equals the comparison value.
|
||||
[InlineData(1)] // Value is smaller than the comparison value.
|
||||
[InlineData(-5)] // Value is negative and smaller than the comparison value.
|
||||
public void Validate_WhenIntValueIsNotGreaterThanComparison_ShouldHaveValidationError(int value)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { IntValue = value };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_intValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableIntValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableIntValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableIntValueIsNotGreaterThanComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableIntValue = 2 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenDecimalValueIsNotGreaterThanComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { DecimalValue = 3m };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_decimalValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDecimalValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableDecimalValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDecimalValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDecimalValueIsNotGreaterThanComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableDecimalValue = 2m };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableDecimalValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenTimeSpanValueIsNotGreaterThanComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { TimeSpanValue = TimeSpan.FromHours(3) };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_timeSpanValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenIntValue2IsEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { IntValue2 = 5 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_intValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenIntValue2IsSmaller_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { IntValue2 = 4 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_intValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableIntValue2IsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableIntValue2 = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableIntValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableIntValue2IsSmaller_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableIntValue2 = 4 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableIntValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDecimalValue2IsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableDecimalValue2 = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableDecimalValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableDecimalValue2IsSmaller_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableDecimalValue2 = 4m };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableDecimalValue2Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotNullValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotNullValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_notNullValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotNullValueIsNotNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_notNullValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // Null string.
|
||||
[InlineData("")] // Empty string.
|
||||
[InlineData(" ")] // White-space only string.
|
||||
public void Validate_WhenNotEmptyValueIsEmpty_ShouldHaveValidationError(string? value)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyValue = value };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_notEmptyValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotEmptyValueIsNotBlank_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyValue = "value" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_notEmptyValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotEmptyGuidValueIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyGuidValue = Guid.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_notEmptyGuidValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotEmptyCollectionValueIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyCollectionValue = [] };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_notEmptyCollectionValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotEmptyCollectionValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyCollectionValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_notEmptyCollectionValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNotEmptyCollectionValueHasItems_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NotEmptyCollectionValue = ["item"] };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_notEmptyCollectionValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEnumValueIsNotDefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { EnumValue = (ValidatorUtilitiesTestEnum)99 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_enumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEnumValueIsDefined_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { EnumValue = ValidatorUtilitiesTestEnum.First };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_enumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableEnumValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableEnumValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableEnumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableEnumValueIsNotDefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableEnumValue = (ValidatorUtilitiesTestEnum)99 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_nullableEnumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullableEnumValueIsDefined_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { NullableEnumValue = ValidatorUtilitiesTestEnum.First };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_nullableEnumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenTextualEnumValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: null);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_textualEnumValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(nameof(ValidatorUtilitiesTestEnum.First))] // The exact member name.
|
||||
[InlineData("first")] // The member name in lower case.
|
||||
[InlineData("SECOND")] // The member name in upper case.
|
||||
public void Validate_WhenTextualEnumValueIsAMemberName_ShouldNotHaveValidationError(string textualEnumValue)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: textualEnumValue);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_textualEnumValueError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // An empty value.
|
||||
[InlineData(" ")] // A whitespace only value.
|
||||
[InlineData("Unknown")] // A name that is not a member of the enumeration.
|
||||
[InlineData("0")] // A number that is a defined member value, which must still be rejected.
|
||||
[InlineData("1")] // Another number that is a defined member value.
|
||||
[InlineData("99")] // A number that is not a member value.
|
||||
public void Validate_WhenTextualEnumValueIsNotAMemberName_ShouldHaveValidationError(string textualEnumValue)
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: textualEnumValue);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_textualEnumValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxLengthValueExceedsMaximumLength_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MaxLengthValue = "abcdef" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_maxLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxLengthValueIsAtMaximumLength_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MaxLengthValue = "abcde" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_maxLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMaxLengthValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MaxLengthValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_maxLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMinLengthValueIsBelowMinimumLength_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MinLengthValue = "ab" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_minLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMinLengthValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MinLengthValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_minLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMinLengthValueIsAtMinimumLength_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MinLengthValue = "abc" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_minLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenExactLengthValueDoesNotMatchExactLength_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { ExactLengthValue = "ab" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_exactLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenExactLengthValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { ExactLengthValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_exactLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenExactLengthValueMatchesExactLength_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { ExactLengthValue = "abc" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_exactLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRangeLengthValueIsOutsideRange_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { RangeLengthValue = "abcdef" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_rangeLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRangeLengthValueIsNull_ShouldHaveValidationErrorForRange()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { RangeLengthValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_rangeLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenRangeLengthValueIsWithinRange_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { RangeLengthValue = "abcd" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_rangeLengthValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMatchValueDoesNotMatchPattern_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MatchValue = "not-a-match" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_matchValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMatchValueIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MatchValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_matchValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMatchValueMatchesPattern_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { MatchValue = "abc-123" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_matchValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSelectorMatchValueDoesNotMatchSelectedPattern_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { SelectorMatchValue = "invalid" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_selectorMatchValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSelectorMatchValueMatchesSelectedPattern_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { SelectorMatchValue = "xyz-999" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_selectorMatchValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveIntValueIsBelowMinimum_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { InclusiveIntValue = 0 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_inclusiveIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveIntValueIsAboveMaximum_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { InclusiveIntValue = 11 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_inclusiveIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveIntValueIsWithinRange_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { InclusiveIntValue = 1 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_inclusiveIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveNullableIntValueIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { InclusiveNullableIntValue = null };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(s_inclusiveNullableIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInclusiveNullableIntValueIsOutsideRange_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { InclusiveNullableIntValue = 12 };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_inclusiveNullableIntValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEqualValueDiffersFromComparison_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
request = request with { EqualValue = "different" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(s_equalValueError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEqualValueEqualsComparison_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(request);
|
||||
|
||||
// Assert
|
||||
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>
|
||||
{
|
||||
public ValidatorUtilitiesTestValidator()
|
||||
{
|
||||
RuleFor(request => request.IntValue).GreaterThan(3).WithError(s_intValueError);
|
||||
RuleFor(request => request.NullableIntValue).GreaterThan(3).WithError(s_nullableIntValueError);
|
||||
RuleFor(request => request.DecimalValue).GreaterThan(3m).WithError(s_decimalValueError);
|
||||
RuleFor(request => request.NullableDecimalValue).GreaterThan(3m).WithError(s_nullableDecimalValueError);
|
||||
RuleFor(request => request.TimeSpanValue).GreaterThan(TimeSpan.FromHours(3)).WithError(s_timeSpanValueError);
|
||||
RuleFor(request => request.IntValue2).GreaterThanOrEqualTo(5).WithError(s_intValue2Error);
|
||||
RuleFor(request => request.NullableIntValue2).GreaterThanOrEqualTo(5).WithError(s_nullableIntValue2Error);
|
||||
RuleFor(request => request.NullableDecimalValue2).GreaterThanOrEqualTo(5m).WithError(s_nullableDecimalValue2Error);
|
||||
RuleFor(request => request.NotNullValue).NotNull().WithError(s_notNullValueError);
|
||||
RuleFor(request => request.NotEmptyValue).NotEmpty().WithError(s_notEmptyValueError);
|
||||
RuleFor(request => request.NotEmptyGuidValue).NotEmpty().WithError(s_notEmptyGuidValueError);
|
||||
RuleFor(request => request.NotEmptyCollectionValue).NotEmpty().WithError(s_notEmptyCollectionValueError);
|
||||
RuleFor(request => request.EnumValue).IsInEnum().WithError(s_enumValueError);
|
||||
RuleFor(request => request.NullableEnumValue).IsInEnum().WithError(s_nullableEnumValueError);
|
||||
RuleFor(request => request.TextualEnumValue).IsInEnum<ValidatorUtilitiesTestRequest, ValidatorUtilitiesTestEnum>().WithError(s_textualEnumValueError);
|
||||
RuleFor(request => request.MaxLengthValue).MaximumLength(5).WithError(s_maxLengthValueError);
|
||||
RuleFor(request => request.MinLengthValue).MinimumLength(3).WithError(s_minLengthValueError);
|
||||
RuleFor(request => request.ExactLengthValue).Length(3).WithError(s_exactLengthValueError);
|
||||
RuleFor(request => request.RangeLengthValue).Length(3, 5).WithError(s_rangeLengthValueError);
|
||||
RuleFor(request => request.MatchValue).Matches("^[a-z]{3}-\\d{3}$").WithError(s_matchValueError);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Error s_intValueError = Error.Validation(description: "IntValueError");
|
||||
private static readonly Error s_nullableIntValueError = Error.Validation(description: "NullableIntValueError");
|
||||
private static readonly Error s_decimalValueError = Error.Validation(description: "DecimalValueError");
|
||||
private static readonly Error s_nullableDecimalValueError = Error.Validation(description: "NullableDecimalValueError");
|
||||
private static readonly Error s_timeSpanValueError = Error.Validation(description: "TimeSpanValueError");
|
||||
private static readonly Error s_intValue2Error = Error.Validation(description: "IntValue2Error");
|
||||
private static readonly Error s_nullableIntValue2Error = Error.Validation(description: "NullableIntValue2Error");
|
||||
private static readonly Error s_nullableDecimalValue2Error = Error.Validation(description: "NullableDecimalValue2Error");
|
||||
private static readonly Error s_notNullValueError = Error.Validation(description: "NotNullValueError");
|
||||
private static readonly Error s_notEmptyValueError = Error.Validation(description: "NotEmptyValueError");
|
||||
private static readonly Error s_notEmptyGuidValueError = Error.Validation(description: "NotEmptyGuidValueError");
|
||||
private static readonly Error s_notEmptyCollectionValueError = Error.Validation(description: "NotEmptyCollectionValueError");
|
||||
private static readonly Error s_enumValueError = Error.Validation(description: "EnumValueError");
|
||||
private static readonly Error s_nullableEnumValueError = Error.Validation(description: "NullableEnumValueError");
|
||||
private static readonly Error s_textualEnumValueError = Error.Validation(description: "TextualEnumValueError");
|
||||
private static readonly Error s_maxLengthValueError = Error.Validation(description: "MaxLengthValueError");
|
||||
private static readonly Error s_minLengthValueError = Error.Validation(description: "MinLengthValueError");
|
||||
private static readonly Error s_exactLengthValueError = Error.Validation(description: "ExactLengthValueError");
|
||||
private static readonly Error s_rangeLengthValueError = Error.Validation(description: "RangeLengthValueError");
|
||||
private static readonly Error s_matchValueError = Error.Validation(description: "MatchValueError");
|
||||
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");
|
||||
}
|
||||
Reference in new issue
Block a user