mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
78 lines
2.9 KiB
C#
78 lines
2.9 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Nemera.Presentation.Web.Common.DTO.Configuration;
|
|
using Nemera.Presentation.Web.Common.Primitives;
|
|
using Nemera.Presentation.Web.Common.Validators;
|
|
using Nemera.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
|
using Nemera.Presentation.Web.UnitTests.Common.Setup;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
#endregion
|
|
|
|
namespace Nemera.Presentation.Web.UnitTests.Common.Validators;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="ServerConfigurationDtoValidator"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class ServerConfigurationModelValidatorTests
|
|
{
|
|
private readonly ServerConfigurationDtoFixture _serverConfigurationDtoFixture = new();
|
|
private readonly ServerConfigurationDtoValidator _validator = new();
|
|
|
|
[Fact]
|
|
public void Validate_WhenBaseAddressIsEmpty_ShouldHaveValidationError()
|
|
{
|
|
// Arrange
|
|
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: string.Empty, port: 5214);
|
|
|
|
// Act
|
|
List<Error> result = _validator.TestValidate(configuration);
|
|
|
|
// Assert
|
|
result.ShouldHaveValidationError(Error.Validation(description: "Base address cannot be empty!"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData((ushort)0)] // Minimum allowed value.
|
|
[InlineData((ushort)65535)] // Maximum allowed value.
|
|
public void Validate_WhenPortIsAtBoundary_ShouldNotHaveValidationError(ushort port)
|
|
{
|
|
// Arrange
|
|
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: port);
|
|
|
|
// Act
|
|
List<Error> result = _validator.TestValidate(configuration);
|
|
|
|
// Assert
|
|
result.ShouldNotHaveAnyValidationErrors();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData((char)0)] // Minimum allowed API version.
|
|
[InlineData((char)255)] // Maximum allowed API version.
|
|
public void Validate_WhenApiVersionIsAtBoundary_ShouldNotHaveValidationError(char apiVersion)
|
|
{
|
|
// Arrange
|
|
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: apiVersion, baseAddress: "http://localhost", port: 5214);
|
|
|
|
// Act
|
|
List<Error> result = _validator.TestValidate(configuration);
|
|
|
|
// Assert
|
|
result.ShouldNotHaveAnyValidationErrors();
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_WhenConfigurationIsValid_ShouldNotHaveValidationError()
|
|
{
|
|
// Arrange
|
|
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: 5214);
|
|
|
|
// Act
|
|
List<Error> result = _validator.TestValidate(configuration);
|
|
|
|
// Assert
|
|
result.ShouldNotHaveAnyValidationErrors();
|
|
}
|
|
}
|