mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 23:01:10 +00:00
125 lines
3.9 KiB
C#
125 lines
3.9 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using AutoFixture;
|
|
using AutoFixture.AutoNSubstitute;
|
|
using Nemera.Application.Common.Infrastructure.Models.DTO.Configuration;
|
|
using Nemera.Domain.Common.Primitives;
|
|
using Nemera.Infrastructure.Common.Errors;
|
|
using Nemera.Infrastructure.Common.Validators;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
#endregion
|
|
|
|
namespace Nemera.Infrastructure.UnitTests.Common.Validators;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="MediaSettingsDtoValidator"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class MediaSettingsDtoValidatorTests
|
|
{
|
|
private readonly MediaSettingsDtoValidator _validator = new();
|
|
private readonly IFixture _fixture;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MediaSettingsDtoValidatorTests"/> class.
|
|
/// </summary>
|
|
public MediaSettingsDtoValidatorTests()
|
|
{
|
|
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenRootDirectoryProvided_ShouldNotHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.RootDirectory, "/path/to/media")
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenRootDirectoryIsEmpty_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.RootDirectory, string.Empty)
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenRootDirectoryIsWhitespace_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.RootDirectory, " ")
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenMediaLibrariesDirectoryIsEmpty_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.LibrariesDirectory, string.Empty)
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenMediaLibrariesDirectoryProvided_ShouldNotHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.LibrariesDirectory, "/path/to/media")
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenMediaLibrariesDirectoryIsWhitespace_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
MediaSettingsDto model = _fixture.Build<MediaSettingsDto>()
|
|
.With(x => x.LibrariesDirectory, " ")
|
|
.Create();
|
|
|
|
// Act
|
|
List<Error> result = _validator.Validate(model);
|
|
|
|
// Assert
|
|
Assert.Single(result);
|
|
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
|
|
}
|
|
}
|