mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 23:01:10 +00:00
Merge pull request #24 from BinaryAlley/refactor/add-get-thumbnail-query-validator-unit-tests
Adds unit tests for GetThumbnailQueryValidator
This commit is contained in:
1 file changed
+110
+110
@@ -0,0 +1,110 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailQueryValidatorTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly GetThumbnailQueryValidator _validator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThumbnailQueryValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public GetThumbnailQueryValidatorTests()
|
||||
{
|
||||
_validator = new GetThumbnailQueryValidator();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new(null!, 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new(string.Empty, 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new("test", 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsNegative_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new("test", -1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsOver100_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new("test", 101);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = new("test", 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Quality);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user