mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 05:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+121
@@ -0,0 +1,121 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Infrastructure.Common.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ExceptionUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ExceptionUtilitiesTests
|
||||
{
|
||||
[Fact]
|
||||
public void AggregateMessages_WhenCalledWithNestedException_ShouldConcatenateAllMessages()
|
||||
{
|
||||
// Arrange
|
||||
Exception exception = new("outer", new InvalidOperationException("inner", new ArgumentException("deepest")));
|
||||
|
||||
// Act
|
||||
string result = exception.AggregateMessages();
|
||||
|
||||
// Assert
|
||||
Assert.Contains("outer", result);
|
||||
Assert.Contains("inner", result);
|
||||
Assert.Contains("deepest", result);
|
||||
Assert.Contains(" -> ", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AggregateMessages_WhenCalledWithSingleException_ShouldReturnItsMessageWithArrow()
|
||||
{
|
||||
// Arrange
|
||||
Exception exception = new("only-message");
|
||||
|
||||
// Act
|
||||
string result = exception.AggregateMessages();
|
||||
|
||||
// Assert
|
||||
Assert.Contains("only-message", result);
|
||||
Assert.Contains(" -> ", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInnerExceptions_WhenExceptionIsNull_ShouldReturnEmptySequence()
|
||||
{
|
||||
// Act
|
||||
IEnumerable<Exception> result = ((Exception)null!).GetInnerExceptions();
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInnerExceptions_WhenExceptionHasNestedInners_ShouldReturnAllLevels()
|
||||
{
|
||||
// Arrange
|
||||
Exception exception = new("first", new InvalidOperationException("second", new ArgumentException("third")));
|
||||
|
||||
// Act
|
||||
List<Exception> result = [.. exception.GetInnerExceptions()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, result.Count);
|
||||
Assert.Equal("first", result[0].Message);
|
||||
Assert.Equal("second", result[1].Message);
|
||||
Assert.Equal("third", result[2].Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInnerExceptions_WhenChainExceedsMaximumDepth_ShouldStopAtMaximumDepth()
|
||||
{
|
||||
// Arrange
|
||||
Exception exception = new("level-1", new Exception("level-2", new Exception("level-3", new Exception("level-4", new Exception("level-5", new Exception("level-6"))))));
|
||||
|
||||
// Act
|
||||
List<Exception> result = [.. exception.GetInnerExceptions(maximumDepth: 3)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, result.Count);
|
||||
Assert.Equal(["level-1", "level-2", "level-3"], result.Select(inner => inner.Message));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInnerExceptions_WhenExceptionIsAggregate_ShouldReturnItsInnerExceptions()
|
||||
{
|
||||
// Arrange
|
||||
AggregateException exception = new(
|
||||
"aggregate",
|
||||
[new InvalidOperationException("first-inner", new Exception("first-deep")), new ArgumentException("second-inner")]);
|
||||
|
||||
// Act
|
||||
List<Exception> result = [.. exception.GetInnerExceptions()];
|
||||
|
||||
// Assert
|
||||
// The aggregate exception itself, its inner exceptions and their inners are traversed, and the first inner exception
|
||||
// is also reachable through the regular InnerException chain, so it is yielded twice.
|
||||
Assert.Equal(6, result.Count);
|
||||
Assert.Contains(result, inner => inner is AggregateException);
|
||||
Assert.Equal(2, result.Count(inner => inner.Message == "first-inner"));
|
||||
Assert.Equal(2, result.Count(inner => inner.Message == "first-deep"));
|
||||
Assert.Single(result, inner => inner.Message == "second-inner");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AggregateMessage_WhenCalled_ShouldContainMessageAndCallStack()
|
||||
{
|
||||
// Arrange
|
||||
Exception exception = new("some-message");
|
||||
|
||||
// Act
|
||||
string result = exception.AggregateMessage();
|
||||
|
||||
// Assert
|
||||
Assert.Contains("Message: some-message", result);
|
||||
Assert.Contains("CallStack:", result);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Infrastructure.Common.Utilities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ImageTypeUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ImageTypeUtilitiesTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(ImageType.BMP, "bmp")] // Bitmap image.
|
||||
[InlineData(ImageType.GIF, "gif")] // Graphics interchange format.
|
||||
[InlineData(ImageType.PNG, "png")] // Portable network graphics.
|
||||
[InlineData(ImageType.TIFF, "tiff")] // Tagged image file format.
|
||||
[InlineData(ImageType.PICT, "pct")] // Macintosh picture.
|
||||
[InlineData(ImageType.ICO, "ico")] // Icon format.
|
||||
[InlineData(ImageType.PSD, "psd")] // Photoshop document.
|
||||
[InlineData(ImageType.JPEG2000, "jp2")] // JPEG 2000.
|
||||
[InlineData(ImageType.AVIF, "avif")] // AV1 image file format.
|
||||
[InlineData(ImageType.WEBP, "webp")] // Web picture format.
|
||||
[InlineData(ImageType.TGA, "tga")] // Truevision TGA.
|
||||
[InlineData(ImageType.SVG, "svg")] // Scalable vector graphics.
|
||||
public void ToFileExtension_WhenTypeIsRecognized_ShouldReturnConventionalExtension(ImageType imageType, string expectedExtension)
|
||||
{
|
||||
// Act
|
||||
string result = imageType.ToFileExtension();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedExtension, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageType.JPEG)] // Joint photographic experts group.
|
||||
[InlineData(ImageType.JPEG_CANON)] // Canon-specific JPEG.
|
||||
[InlineData(ImageType.JPEG_UNKNOWN)] // Unknown JPEG.
|
||||
public void ToFileExtension_WhenTypeIsAnyJpeg_ShouldReturnJpg(ImageType imageType)
|
||||
{
|
||||
// Act
|
||||
string result = imageType.ToFileExtension();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("jpg", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileExtension_WhenTypeIsNotARecognizedImage_ShouldReturnBin()
|
||||
{
|
||||
// Act
|
||||
string result = ImageType.None.ToFileExtension();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("bin", result);
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Infrastructure.Common.Utilities;
|
||||
using Lumina.Infrastructure.Common.Validation;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Utilities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="OptionsBuilderValidationUtilities"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionsBuilderValidationUtilitiesTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionsBuilderValidationUtilitiesTests"/> class.
|
||||
/// </summary>
|
||||
public OptionsBuilderValidationUtilitiesTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateFluently_WhenCalled_ShouldRegisterFluentValidationOptions()
|
||||
{
|
||||
// Arrange
|
||||
IServiceCollection services = Substitute.For<IServiceCollection>();
|
||||
string name = _fixture.Create<string>();
|
||||
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> optionsBuilder = new(services, name);
|
||||
|
||||
// Act
|
||||
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> result = optionsBuilder.ValidateFluently();
|
||||
|
||||
// Assert
|
||||
Assert.Same(optionsBuilder, result);
|
||||
services.Received(1).Add(Arg.Is<ServiceDescriptor>(sd =>
|
||||
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderValidationUtilitiesFixture>) &&
|
||||
sd.Lifetime == ServiceLifetime.Singleton &&
|
||||
sd.ImplementationFactory != null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateFluently_WhenCalled_ShouldUseCorrectName()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
string name = _fixture.Create<string>();
|
||||
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> optionsBuilder = new(services, name);
|
||||
|
||||
// Act
|
||||
optionsBuilder.ValidateFluently();
|
||||
|
||||
// Assert
|
||||
ServiceDescriptor? serviceDescriptor = services.FirstOrDefault(sd =>
|
||||
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderValidationUtilitiesFixture>) &&
|
||||
sd.Lifetime == ServiceLifetime.Singleton &&
|
||||
sd.ImplementationFactory != null);
|
||||
|
||||
Assert.NotNull(serviceDescriptor);
|
||||
|
||||
Func<IServiceProvider, object>? implementationFactory = serviceDescriptor!.ImplementationFactory;
|
||||
Assert.NotNull(implementationFactory);
|
||||
|
||||
IServiceProvider serviceProvider = Substitute.For<IServiceProvider>();
|
||||
IValidator<OptionsBuilderValidationUtilitiesFixture> mockValidator = Substitute.For<IValidator<OptionsBuilderValidationUtilitiesFixture>>();
|
||||
serviceProvider.GetService(typeof(IValidator<OptionsBuilderValidationUtilitiesFixture>))
|
||||
.Returns(mockValidator);
|
||||
|
||||
ValidationOptions<OptionsBuilderValidationUtilitiesFixture>? validationOptions = implementationFactory!(serviceProvider) as ValidationOptions<OptionsBuilderValidationUtilitiesFixture>;
|
||||
Assert.NotNull(validationOptions);
|
||||
Assert.Equal(name, validationOptions.Name);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user