mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Adds Infrastructure unit tests
This commit is contained in:
1 parent
433f0c2ad5
commit
b69e59a3d8
12 files changed
+576
No files matched your search
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Infrastructure.Common.Models.Configuration;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CommonSettingsModelValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CommonSettingsModelValidatorTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly CommonSettingsModelValidator _validator;
|
||||
private readonly IFixture _fixture;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CommonSettingsModelValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public CommonSettingsModelValidatorTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_validator = new();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ================================================================= METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void CommonSettingsModelValidator_WhenThemeProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var model = _fixture.Build<CommonSettingsModel>()
|
||||
.With(x => x.Theme, "Dark")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
var result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeTrue();
|
||||
result.Errors.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CommonSettingsModelValidator_WhenThemeNotProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var model = _fixture.Build<CommonSettingsModel>()
|
||||
.With(x => x.Theme, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
var result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeFalse();
|
||||
result.Errors.Should().ContainSingle()
|
||||
.Which.ErrorMessage.Should().Be(Errors.Configuration.ApplicationThemeCannotBeEmpty.Code);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Infrastructure.Common.Models.Configuration;
|
||||
using Lumina.Infrastructure.Common.Validators;
|
||||
using Lumina.Infrastructure.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CommonSettingsModelValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DatabaseSettingsModelValidatorTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly DatabaseSettingsModelValidator _validator;
|
||||
private readonly IFixture _fixture;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CommonSettingsModelValidatorTests"/> class.
|
||||
/// </summary>
|
||||
public DatabaseSettingsModelValidatorTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_validator = new();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ================================================================= METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void DatabaseSettingsModelValidator_WhenDefaultConnectionProvided_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var model = _fixture.Build<DatabaseSettingsModel>()
|
||||
.With(x => x.DefaultConnection, "dummy-connection-string")
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
var result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeTrue();
|
||||
result.Errors.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DatabaseSettingsModelValidator_WhenDefaultConnectionNotProvided_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var model = _fixture.Build<DatabaseSettingsModel>()
|
||||
.With(x => x.DefaultConnection, string.Empty)
|
||||
.Create();
|
||||
|
||||
// Act
|
||||
var result = _validator.Validate(model);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeFalse();
|
||||
result.Errors.Should().ContainSingle()
|
||||
.Which.ErrorMessage.Should().Be(Errors.Configuration.DatabaseConnectionStringCannotBeEmpty.Code);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user