mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 23:01: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
@@ -15,6 +15,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Api", "
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Web", "Lumina.Presentation.Web\Lumina.Presentation.Web.csproj", "{FABC255B-0D21-4A0A-A0E2-7759D929B4D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Application.UnitTests", "..\tests\UnitTests\Lumina.Application.UnitTests\Lumina.Application.UnitTests.csproj", "{4DEA94AF-D592-4187-8850-A569C93256C9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Infrastructure.UnitTests", "..\tests\UnitTests\Lumina.Infrastructure.UnitTests\Lumina.Infrastructure.UnitTests.csproj", "{8DB5300A-B38A-4F6D-8FF7-A722DA47667E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.DataAccess.UnitTests", "..\tests\UnitTests\Lumina.DataAccess.UnitTests\Lumina.DataAccess.UnitTests.csproj", "{6050F6A9-F136-4B7B-82D2-57E689463ACA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Domain.UnitTests", "..\tests\UnitTests\Lumina.Domain.UnitTests\Lumina.Domain.UnitTests.csproj", "{3BB42EB9-A0A3-4E3F-9053-785F429714AE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Api.UnitTests", "..\tests\UnitTests\Lumina.Presentation.Api.UnitTests\Lumina.Presentation.Api.UnitTests.csproj", "{4D5E4789-8437-4F3B-883E-28BBF8A4848F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -45,6 +55,26 @@ Global
|
||||
{FABC255B-0D21-4A0A-A0E2-7759D929B4D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FABC255B-0D21-4A0A-A0E2-7759D929B4D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FABC255B-0D21-4A0A-A0E2-7759D929B4D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4DEA94AF-D592-4187-8850-A569C93256C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4DEA94AF-D592-4187-8850-A569C93256C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4DEA94AF-D592-4187-8850-A569C93256C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4DEA94AF-D592-4187-8850-A569C93256C9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8DB5300A-B38A-4F6D-8FF7-A722DA47667E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8DB5300A-B38A-4F6D-8FF7-A722DA47667E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8DB5300A-B38A-4F6D-8FF7-A722DA47667E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8DB5300A-B38A-4F6D-8FF7-A722DA47667E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6050F6A9-F136-4B7B-82D2-57E689463ACA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6050F6A9-F136-4B7B-82D2-57E689463ACA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6050F6A9-F136-4B7B-82D2-57E689463ACA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6050F6A9-F136-4B7B-82D2-57E689463ACA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3BB42EB9-A0A3-4E3F-9053-785F429714AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3BB42EB9-A0A3-4E3F-9053-785F429714AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3BB42EB9-A0A3-4E3F-9053-785F429714AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3BB42EB9-A0A3-4E3F-9053-785F429714AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4D5E4789-8437-4F3B-883E-28BBF8A4848F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4D5E4789-8437-4F3B-883E-28BBF8A4848F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4D5E4789-8437-4F3B-883E-28BBF8A4848F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4D5E4789-8437-4F3B-883E-28BBF8A4848F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Application\Lumina.Application.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.DataAccess\Lumina.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Domain\Lumina.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="OptionsBuilderFluentValidationUtilitiesTests"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionsBuilderFluentValidationUtilitiesFixture
|
||||
{
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using FluentValidation;
|
||||
using Lumina.Infrastructure.Common.Utilities;
|
||||
using Lumina.Infrastructure.Common.Validation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="OptionsBuilderFluentValidationUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionsBuilderFluentValidationUtilitiesTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IFixture _fixture;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FluentValidationOptionsTests"/> class.
|
||||
/// </summary>
|
||||
public OptionsBuilderFluentValidationUtilitiesTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ================================================================= METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void ValidateFluently_WhenCalled_ShouldRegisterFluentValidationOptions()
|
||||
{
|
||||
// Arrange
|
||||
var services = Substitute.For<IServiceCollection>();
|
||||
var name = _fixture.Create<string>();
|
||||
var optionsBuilder = new OptionsBuilder<OptionsBuilderFluentValidationUtilitiesFixture>(services, name);
|
||||
|
||||
// Act
|
||||
var result = optionsBuilder.ValidateFluently();
|
||||
|
||||
// Assert
|
||||
result.Should().BeSameAs(optionsBuilder);
|
||||
services.Received(1).Add(Arg.Is<ServiceDescriptor>(sd =>
|
||||
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>) &&
|
||||
sd.Lifetime == ServiceLifetime.Singleton &&
|
||||
sd.ImplementationFactory != null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateFluently_WhenCalled_ShouldUseCorrectName()
|
||||
{
|
||||
// Arrange
|
||||
var services = Substitute.For<IServiceCollection>();
|
||||
var name = _fixture.Create<string>();
|
||||
var optionsBuilder = new OptionsBuilder<OptionsBuilderFluentValidationUtilitiesFixture>(services, name);
|
||||
|
||||
// Act
|
||||
optionsBuilder.ValidateFluently();
|
||||
|
||||
// Assert
|
||||
services.Received(1).Add(Arg.Is<ServiceDescriptor>(sd =>
|
||||
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>) &&
|
||||
sd.Lifetime == ServiceLifetime.Singleton &&
|
||||
sd.ImplementationFactory != null));
|
||||
|
||||
var serviceDescriptor = services.ReceivedCalls()
|
||||
.Select(call => call.GetArguments().First())
|
||||
.OfType<ServiceDescriptor>()
|
||||
.First();
|
||||
|
||||
var implementationFactory = serviceDescriptor.ImplementationFactory;
|
||||
implementationFactory.Should().NotBeNull();
|
||||
|
||||
var serviceProvider = Substitute.For<IServiceProvider>();
|
||||
var mockValidator = Substitute.For<IValidator<OptionsBuilderFluentValidationUtilitiesFixture>>();
|
||||
serviceProvider.GetService(typeof(IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>))
|
||||
.Returns(Substitute.For<IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>>());
|
||||
|
||||
var fluentValidationOptions = implementationFactory!(serviceProvider) as FluentValidationOptions<OptionsBuilderFluentValidationUtilitiesFixture>;
|
||||
fluentValidationOptions.Should().NotBeNull();
|
||||
fluentValidationOptions!.Name.Should().Be(name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FluentValidationOptionsTests"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FluentValidationOptionsFixture
|
||||
{
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using Lumina.Infrastructure.Common.Validation;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FluentValidationOptions"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FluentValidationOptionsTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IFixture _fixture;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FluentValidationOptionsTests"/> class.
|
||||
/// </summary>
|
||||
public FluentValidationOptionsTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ================================================================= METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Validate_WhenMatchingName_ShouldValidateOptions()
|
||||
{
|
||||
// Arrange
|
||||
var name = _fixture.Create<string>();
|
||||
var options = _fixture.Create<FluentValidationOptionsFixture>();
|
||||
var validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
|
||||
validator.Validate(options).Returns(new ValidationResult());
|
||||
var sut = new FluentValidationOptions<FluentValidationOptionsFixture>(name, validator);
|
||||
|
||||
// Act
|
||||
var result = sut.Validate(name, options);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ValidateOptionsResult>();
|
||||
result.Failed.Should().BeFalse();
|
||||
validator.Received(1).Validate(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNonMatchingName_ShouldSkipValidation()
|
||||
{
|
||||
// Arrange
|
||||
var name = _fixture.Create<string>();
|
||||
var differentName = _fixture.Create<string>();
|
||||
var options = _fixture.Create<FluentValidationOptionsFixture>();
|
||||
var validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
|
||||
var sut = new FluentValidationOptions<FluentValidationOptionsFixture>(name, validator);
|
||||
|
||||
// Act
|
||||
var result = sut.Validate(differentName, options);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(ValidateOptionsResult.Skip);
|
||||
validator.DidNotReceive().Validate(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullName_ShouldValidateOptions()
|
||||
{
|
||||
// Arrange
|
||||
var options = _fixture.Create<FluentValidationOptionsFixture>();
|
||||
var validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
|
||||
validator.Validate(options).Returns(new ValidationResult());
|
||||
var sut = new FluentValidationOptions<FluentValidationOptionsFixture>(null, validator);
|
||||
|
||||
// Act
|
||||
var result = sut.Validate(_fixture.Create<string>(), options);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ValidateOptionsResult>();
|
||||
result.Failed.Should().BeFalse();
|
||||
validator.Received(1).Validate(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNullOptions_ShouldThrowArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var name = _fixture.Create<string>();
|
||||
var validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
|
||||
var sut = new FluentValidationOptions<FluentValidationOptionsFixture>(name, validator);
|
||||
|
||||
// Act
|
||||
Action act = () => sut.Validate(name, null!);
|
||||
|
||||
// Assert
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenInvalidOptions_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
var name = _fixture.Create<string>();
|
||||
var options = _fixture.Create<FluentValidationOptionsFixture>();
|
||||
var validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
|
||||
var validationFailures = new List<ValidationFailure>
|
||||
{
|
||||
new("PropertyName", "Error Message")
|
||||
};
|
||||
validator.Validate(options).Returns(new ValidationResult(validationFailures));
|
||||
var sut = new FluentValidationOptions<FluentValidationOptionsFixture>(name, validator);
|
||||
|
||||
// Act
|
||||
var result = sut.Validate(name, options);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ValidateOptionsResult>();
|
||||
result.Failed.Should().BeTrue();
|
||||
// TODO: should be modified to account for translation of error messages
|
||||
result.Failures.Should().ContainSingle()
|
||||
.Which.Should().Contain("Options validation failed for 'PropertyName' with error: 'Error Message'");
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+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
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Presentation.Api\Lumina.Presentation.Api.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user