Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -6,6 +6,7 @@ using StellaOps.Microservice;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +34,8 @@ public class EndpointDiscoveryServiceTests
|
||||
_logger);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_CallsDiscoveryProvider()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>();
|
||||
@@ -49,7 +51,8 @@ public class EndpointDiscoveryServiceTests
|
||||
_discoveryProviderMock.Verify(x => x.DiscoverEndpoints(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_CallsYamlLoader()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>();
|
||||
@@ -65,7 +68,8 @@ public class EndpointDiscoveryServiceTests
|
||||
_yamlLoaderMock.Verify(x => x.Load(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_PassesCodeEndpointsAndYamlConfigToMerger()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -95,7 +99,8 @@ public class EndpointDiscoveryServiceTests
|
||||
_mergerMock.Verify(x => x.Merge(codeEndpoints, yamlConfig), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_ReturnsMergedEndpoints()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -119,7 +124,8 @@ public class EndpointDiscoveryServiceTests
|
||||
result.Should().BeSameAs(mergedEndpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_ContinuesWithNullYamlConfig_WhenLoaderReturnsNull()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -143,7 +149,8 @@ public class EndpointDiscoveryServiceTests
|
||||
result.Should().BeSameAs(codeEndpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DiscoverEndpoints_ContinuesWithNullYamlConfig_WhenLoaderThrows()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Reflection;
|
||||
using StellaOps.Microservice;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
// Test endpoint classes
|
||||
@@ -23,7 +24,8 @@ public record TestResponse;
|
||||
|
||||
public class EndpointDiscoveryTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StellaEndpointAttribute_StoresMethodAndPath()
|
||||
{
|
||||
// Arrange & Act
|
||||
@@ -34,7 +36,8 @@ public class EndpointDiscoveryTests
|
||||
Assert.Equal("/api/test", attr.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StellaEndpointAttribute_NormalizesMethod()
|
||||
{
|
||||
// Arrange & Act
|
||||
@@ -44,7 +47,8 @@ public class EndpointDiscoveryTests
|
||||
Assert.Equal("GET", attr.Method);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StellaEndpointAttribute_DefaultTimeoutIs30Seconds()
|
||||
{
|
||||
// Arrange & Act
|
||||
@@ -54,7 +58,8 @@ public class EndpointDiscoveryTests
|
||||
Assert.Equal(30, attr.TimeoutSeconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ReflectionDiscovery_FindsEndpointsInCurrentAssembly()
|
||||
{
|
||||
// Arrange
|
||||
@@ -77,7 +82,8 @@ public class EndpointDiscoveryTests
|
||||
Assert.Contains(endpoints, e => e.Method == "POST" && e.Path == "/api/create");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ReflectionDiscovery_SetsServiceNameAndVersion()
|
||||
{
|
||||
// Arrange
|
||||
@@ -100,7 +106,8 @@ public class EndpointDiscoveryTests
|
||||
Assert.Equal("2.0.0", endpoint.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ReflectionDiscovery_SetsStreamingAndTimeout()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -6,6 +6,7 @@ using StellaOps.Microservice;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,7 +23,8 @@ public class EndpointOverrideMergerTests
|
||||
_merger = new EndpointOverrideMerger(_loggerMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_WithNullYamlConfig_ReturnsCodeEndpointsUnchanged()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -35,7 +37,8 @@ public class EndpointOverrideMergerTests
|
||||
result.Should().BeEquivalentTo(codeEndpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_WithEmptyYamlConfig_ReturnsCodeEndpointsUnchanged()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -49,7 +52,8 @@ public class EndpointOverrideMergerTests
|
||||
result.Should().BeEquivalentTo(codeEndpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_OverridesTimeout_WhenYamlSpecifiesTimeout()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -75,7 +79,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].DefaultTimeout.Should().Be(TimeSpan.FromMinutes(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_OverridesStreaming_WhenYamlSpecifiesStreaming()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -101,7 +106,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].SupportsStreaming.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_OverridesClaims_WhenYamlSpecifiesClaims()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -132,7 +138,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].RequiringClaims[0].Value.Should().Be("admin");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_PreservesCodeDefaults_WhenYamlDoesNotOverride()
|
||||
{
|
||||
var originalTimeout = TimeSpan.FromSeconds(45);
|
||||
@@ -160,7 +167,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].SupportsStreaming.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_MatchesCaseInsensitively()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -186,7 +194,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].DefaultTimeout.Should().Be(TimeSpan.FromMinutes(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_LeavesUnmatchedEndpointsUnchanged()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -216,7 +225,8 @@ public class EndpointOverrideMergerTests
|
||||
result[2].DefaultTimeout.Should().Be(TimeSpan.FromSeconds(30)); // unchanged
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_LogsWarning_WhenYamlOverrideDoesNotMatchAnyEndpoint()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -248,7 +258,8 @@ public class EndpointOverrideMergerTests
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_AppliesMultipleOverrides()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -282,7 +293,8 @@ public class EndpointOverrideMergerTests
|
||||
result[1].DefaultTimeout.Should().Be(TimeSpan.FromMinutes(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_PreservesOriginalEndpointProperties()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
@@ -322,7 +334,8 @@ public class EndpointOverrideMergerTests
|
||||
result[0].HandlerType.Should().Be(typeof(object));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Merge_YamlOverridesCodeClaims_Completely()
|
||||
{
|
||||
var codeEndpoints = new List<EndpointDescriptor>
|
||||
|
||||
@@ -3,6 +3,7 @@ using StellaOps.Microservice;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
public class EndpointRegistryTests
|
||||
@@ -19,7 +20,8 @@ public class EndpointRegistryTests
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_ExactMatch_ReturnsEndpoint()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -34,7 +36,8 @@ public class EndpointRegistryTests
|
||||
match.PathParameters.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_MethodMismatch_ReturnsFalse()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -46,7 +49,8 @@ public class EndpointRegistryTests
|
||||
match.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_PathMismatch_ReturnsFalse()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -58,7 +62,8 @@ public class EndpointRegistryTests
|
||||
match.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_WithPathParameter_ExtractsParameter()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -72,7 +77,8 @@ public class EndpointRegistryTests
|
||||
match.PathParameters["id"].Should().Be("123");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_MethodCaseInsensitive_ReturnsMatch()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -84,7 +90,8 @@ public class EndpointRegistryTests
|
||||
match.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_PathCaseInsensitive_ReturnsMatch()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -96,7 +103,8 @@ public class EndpointRegistryTests
|
||||
match.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RegisterAll_MultipeEndpoints_AllRegistered()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -112,7 +120,8 @@ public class EndpointRegistryTests
|
||||
registry.GetAllEndpoints().Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void GetAllEndpoints_ReturnsAllRegistered()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -128,7 +137,8 @@ public class EndpointRegistryTests
|
||||
all.Should().Contain(endpoint2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_FirstMatchWins_WhenMultiplePossible()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -145,7 +155,8 @@ public class EndpointRegistryTests
|
||||
match!.Endpoint.Should().Be(endpoint1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void TryMatch_EmptyRegistry_ReturnsFalse()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -156,7 +167,8 @@ public class EndpointRegistryTests
|
||||
match.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Constructor_CaseSensitive_RespectsSetting()
|
||||
{
|
||||
var registry = new EndpointRegistry(caseInsensitive: false);
|
||||
|
||||
@@ -2,6 +2,7 @@ using FluentAssertions;
|
||||
using StellaOps.Microservice;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -9,7 +10,8 @@ namespace StellaOps.Microservice.Tests;
|
||||
/// </summary>
|
||||
public class MicroserviceYamlConfigTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void MicroserviceYamlConfig_DefaultsToEmptyEndpoints()
|
||||
{
|
||||
var config = new MicroserviceYamlConfig();
|
||||
@@ -18,7 +20,8 @@ public class MicroserviceYamlConfigTests
|
||||
config.Endpoints.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EndpointOverrideConfig_DefaultsToEmptyStrings()
|
||||
{
|
||||
var config = new EndpointOverrideConfig();
|
||||
@@ -30,7 +33,8 @@ public class MicroserviceYamlConfigTests
|
||||
config.RequiringClaims.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("30s", 30)]
|
||||
[InlineData("60s", 60)]
|
||||
[InlineData("1s", 1)]
|
||||
@@ -44,7 +48,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().Be(TimeSpan.FromSeconds(expectedSeconds));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("5m", 5)]
|
||||
[InlineData("10m", 10)]
|
||||
[InlineData("1m", 1)]
|
||||
@@ -58,7 +63,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().Be(TimeSpan.FromMinutes(expectedMinutes));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("1h", 1)]
|
||||
[InlineData("2h", 2)]
|
||||
[InlineData("24h", 24)]
|
||||
@@ -72,7 +78,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().Be(TimeSpan.FromHours(expectedHours));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("00:00:30", 30)]
|
||||
[InlineData("00:05:00", 300)]
|
||||
[InlineData("01:00:00", 3600)]
|
||||
@@ -86,7 +93,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().Be(TimeSpan.FromSeconds(expectedSeconds));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
@@ -99,7 +107,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("invalid")]
|
||||
[InlineData("abc")]
|
||||
[InlineData("30x")]
|
||||
@@ -112,7 +121,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ClaimRequirementConfig_ToClaimRequirement_ConvertsCorrectly()
|
||||
{
|
||||
var config = new ClaimRequirementConfig
|
||||
@@ -127,7 +137,8 @@ public class MicroserviceYamlConfigTests
|
||||
result.Value.Should().Be("admin");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ClaimRequirementConfig_ToClaimRequirement_HandlesNullValue()
|
||||
{
|
||||
var config = new ClaimRequirementConfig
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Microservice;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +30,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ReturnsNull_WhenConfigFilePathIsNull()
|
||||
{
|
||||
var options = new StellaMicroserviceOptions
|
||||
@@ -46,7 +48,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ReturnsNull_WhenConfigFilePathIsEmpty()
|
||||
{
|
||||
var options = new StellaMicroserviceOptions
|
||||
@@ -63,7 +66,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ReturnsNull_WhenFileDoesNotExist()
|
||||
{
|
||||
var options = new StellaMicroserviceOptions
|
||||
@@ -80,7 +84,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ParsesValidYaml()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -111,7 +116,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result.Endpoints[0].SupportsStreaming.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ParsesMultipleEndpoints()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -143,7 +149,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result!.Endpoints.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ParsesClaimRequirements()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -178,7 +185,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result.Endpoints[0].RequiringClaims![1].Value.Should().Be("delete");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_HandlesEmptyEndpointsList()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -201,7 +209,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result!.Endpoints.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_IgnoresUnknownProperties()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -228,7 +237,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
result!.Endpoints.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ThrowsOnInvalidYaml()
|
||||
{
|
||||
var yamlContent = """
|
||||
@@ -252,7 +262,8 @@ public class MicroserviceYamlLoaderTests : IDisposable
|
||||
act.Should().Throw<Exception>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Load_ResolvesRelativePath()
|
||||
{
|
||||
var yamlContent = """
|
||||
|
||||
@@ -7,6 +7,8 @@ using StellaOps.Router.Common.Frames;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using Xunit;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
public sealed class RequestDispatcherTests
|
||||
@@ -17,7 +19,8 @@ public sealed class RequestDispatcherTests
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DispatchAsync_WhenEndpointNotFound_Returns404()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -44,7 +47,8 @@ public sealed class RequestDispatcherTests
|
||||
Encoding.UTF8.GetString(response.Payload.Span).Should().Be("Not Found");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DispatchAsync_WhenBodyEmpty_BindsFromPathAndQueryParameters()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
@@ -86,7 +90,8 @@ public sealed class RequestDispatcherTests
|
||||
dto.Filter.Should().Be("active");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DispatchAsync_WhenBodyPresent_PathAndQueryOverrideJsonProperties()
|
||||
{
|
||||
var registry = new EndpointRegistry();
|
||||
|
||||
@@ -2,11 +2,13 @@ using StellaOps.Microservice;
|
||||
using StellaOps.Router.Common.Enums;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
public class StellaMicroserviceOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StellaMicroserviceOptions_CanBeCreated()
|
||||
{
|
||||
// Arrange & Act
|
||||
@@ -24,7 +26,8 @@ public class StellaMicroserviceOptionsTests
|
||||
Assert.NotEmpty(options.InstanceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RouterEndpointConfig_CanBeCreated()
|
||||
{
|
||||
// Arrange & Act
|
||||
@@ -41,7 +44,8 @@ public class StellaMicroserviceOptionsTests
|
||||
Assert.Equal(TransportType.Tcp, config.TransportType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_ThrowsIfServiceNameEmpty()
|
||||
{
|
||||
// Arrange
|
||||
@@ -56,7 +60,8 @@ public class StellaMicroserviceOptionsTests
|
||||
Assert.Throws<InvalidOperationException>(() => options.Validate());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_ThrowsIfVersionInvalid()
|
||||
{
|
||||
// Arrange
|
||||
@@ -72,7 +77,8 @@ public class StellaMicroserviceOptionsTests
|
||||
Assert.Contains("not valid semver", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_ThrowsIfNoRouters()
|
||||
{
|
||||
// Arrange
|
||||
@@ -88,7 +94,8 @@ public class StellaMicroserviceOptionsTests
|
||||
Assert.Contains("router endpoint is required", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_AcceptsValidSemver()
|
||||
{
|
||||
// Arrange
|
||||
@@ -104,7 +111,8 @@ public class StellaMicroserviceOptionsTests
|
||||
options.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_AcceptsSemverWithPrerelease()
|
||||
{
|
||||
// Arrange
|
||||
@@ -120,7 +128,8 @@ public class StellaMicroserviceOptionsTests
|
||||
options.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DefaultHeartbeatInterval_Is10Seconds()
|
||||
{
|
||||
// Arrange & Act
|
||||
|
||||
@@ -25,5 +25,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\__Libraries\StellaOps.Microservice\StellaOps.Microservice.csproj" />
|
||||
<ProjectReference Include="../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -4,6 +4,8 @@ using FluentAssertions;
|
||||
using StellaOps.Microservice;
|
||||
using Xunit;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Microservice.Tests;
|
||||
|
||||
public class TypedEndpointAdapterTests
|
||||
@@ -41,7 +43,8 @@ public class TypedEndpointAdapterTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_TypedWithRequest_DeserializesAndSerializes()
|
||||
{
|
||||
var handler = new TestTypedHandler();
|
||||
@@ -69,7 +72,8 @@ public class TypedEndpointAdapterTests
|
||||
result.Success.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_TypedNoRequest_SerializesResponse()
|
||||
{
|
||||
var handler = new TestNoRequestHandler();
|
||||
@@ -93,7 +97,8 @@ public class TypedEndpointAdapterTests
|
||||
result!.Message.Should().Be("No request needed");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_RawHandler_PassesThroughDirectly()
|
||||
{
|
||||
var handler = new TestRawHandler();
|
||||
@@ -112,7 +117,8 @@ public class TypedEndpointAdapterTests
|
||||
response.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_InvalidJson_ReturnsBadRequest()
|
||||
{
|
||||
var handler = new TestTypedHandler();
|
||||
@@ -131,7 +137,8 @@ public class TypedEndpointAdapterTests
|
||||
response.StatusCode.Should().Be(400);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_EmptyBody_ReturnsBadRequest()
|
||||
{
|
||||
var handler = new TestTypedHandler();
|
||||
@@ -150,7 +157,8 @@ public class TypedEndpointAdapterTests
|
||||
response.StatusCode.Should().Be(400);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Adapt_WithCancellation_PropagatesCancellation()
|
||||
{
|
||||
var handler = new CancellableHandler();
|
||||
|
||||
Reference in New Issue
Block a user