Adds unit tests improving application project code coverage

This commit is contained in:
BinaryAlley committed 2026-09-02 07:10:34 -07:00
1 parent 0ec6eb7ab4
commit ca2e7f9d97
15 files changed
+785

No files matched your search

@@ -0,0 +1,93 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Telemetry;
using Lumina.Domain.Common.Primitives;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Telemetry;
/// <summary>
/// Contains unit tests for the <see cref="HandlerOutcomeDetector"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class HandlerOutcomeDetectorTests
{
[Fact]
public void IsSuccessful_WhenResultIsNull_ShouldReturnTrue()
{
// Act
bool result = HandlerOutcomeDetector.IsSuccessful(null);
// Assert
Assert.True(result);
}
[Fact]
public void IsSuccessful_WhenResultExposesNoSuccessFlag_ShouldReturnTrue()
{
// Act
bool result = HandlerOutcomeDetector.IsSuccessful("a plain dto");
// Assert
Assert.True(result);
}
[Fact]
public void IsSuccessful_WhenResultIsSuccessful_ShouldReturnTrue()
{
// Arrange
Result<string> resultValue = Result<string>.Success("value");
// Act
bool result = HandlerOutcomeDetector.IsSuccessful(resultValue);
// Assert
Assert.True(result);
}
[Fact]
public void IsSuccessful_WhenResultIsFailed_ShouldReturnFalse()
{
// Arrange
Result<string> resultValue = Result<string>.Failure(Error.Validation("Test.Code", "Test description"));
// Act
bool result = HandlerOutcomeDetector.IsSuccessful(resultValue);
// Assert
Assert.False(result);
}
[Fact]
public void GetErrorDescription_WhenResultIsNull_ShouldReturnNull()
{
// Act
string? result = HandlerOutcomeDetector.GetErrorDescription(null);
// Assert
Assert.Null(result);
}
[Fact]
public void GetErrorDescription_WhenResultExposesNoFirstError_ShouldReturnNull()
{
// Act
string? result = HandlerOutcomeDetector.GetErrorDescription("a plain dto");
// Assert
Assert.Null(result);
}
[Fact]
public void GetErrorDescription_WhenResultIsFailed_ShouldReturnFirstErrorDescription()
{
// Arrange
Result<string> resultValue = Result<string>.Failure(Error.Validation("Test.Code", "Test description"));
// Act
string? result = HandlerOutcomeDetector.GetErrorDescription(resultValue);
// Assert
Assert.Equal("Test description", result);
}
}
@@ -0,0 +1,72 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Telemetry;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Telemetry;
/// <summary>
/// Contains unit tests for the <see cref="TelemetryDecoratorFactory"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TelemetryDecoratorFactoryTests
{
[Fact]
public void GetDecoratorType_WhenContractIsQueryHandler_ShouldReturnQueryDecoratorType()
{
// Arrange
Type contract = typeof(IQueryHandler<GetRolePermissionsQuery, Result<RolePermissionsResponse>>);
// Act
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
// Assert
Assert.Equal(typeof(TelemetryQueryHandlerDecorator<GetRolePermissionsQuery, Result<RolePermissionsResponse>>), result);
}
[Fact]
public void GetDecoratorType_WhenContractIsCommandHandler_ShouldReturnCommandDecoratorType()
{
// Arrange
Type contract = typeof(ICommandHandler<AddRoleCommand, Result<RolePermissionsResponse>>);
// Act
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
// Assert
Assert.Equal(typeof(TelemetryCommandHandlerDecorator<AddRoleCommand, Result<RolePermissionsResponse>>), result);
}
[Fact]
public void GetDecoratorType_WhenContractIsDomainEventHandler_ShouldReturnDomainEventHandlerDecoratorType()
{
// Arrange
Type contract = typeof(IDomainEventHandler<LibrarySavedDomainEvent>);
// Act
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
// Assert
Assert.Equal(typeof(TelemetryDomainEventHandlerDecorator<LibrarySavedDomainEvent>), result);
}
[Fact]
public void GetDecoratorType_WhenContractIsNotSupported_ShouldThrowArgumentException()
{
// Arrange
Type contract = typeof(IEnumerable<int>);
// Act & Assert
ArgumentException exception = Assert.Throws<ArgumentException>(() => TelemetryDecoratorFactory.GetDecoratorType(contract));
Assert.Contains("No telemetry decorator is defined", exception.Message);
}
}