Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Implemented comprehensive unit tests for RabbitMqTransportServer, covering constructor, disposal, connection management, event handlers, and exception handling. - Added configuration tests for RabbitMqTransportServer to validate SSL, durable queues, auto-recovery, and custom virtual host options. - Created unit tests for UdpFrameProtocol, including frame parsing and serialization, header size validation, and round-trip data preservation. - Developed tests for UdpTransportClient, focusing on connection handling, event subscriptions, and exception scenarios. - Established tests for UdpTransportServer, ensuring proper start/stop behavior, connection state management, and event handling. - Included tests for UdpTransportOptions to verify default values and modification capabilities. - Enhanced service registration tests for Udp transport services in the dependency injection container.
123 lines
3.3 KiB
C#
123 lines
3.3 KiB
C#
using StellaOps.Microservice;
|
|
using StellaOps.Router.Integration.Tests.Fixtures;
|
|
|
|
namespace StellaOps.Router.Integration.Tests;
|
|
|
|
/// <summary>
|
|
/// Integration tests for path matching and routing.
|
|
/// </summary>
|
|
[Collection("Microservice Integration")]
|
|
public sealed class PathMatchingIntegrationTests
|
|
{
|
|
private readonly MicroserviceIntegrationFixture _fixture;
|
|
|
|
public PathMatchingIntegrationTests(MicroserviceIntegrationFixture fixture)
|
|
{
|
|
_fixture = fixture;
|
|
}
|
|
|
|
#region Exact Path Matching Tests
|
|
|
|
[Theory]
|
|
[InlineData("POST", "/echo")]
|
|
[InlineData("POST", "/users")]
|
|
[InlineData("POST", "/slow")]
|
|
[InlineData("POST", "/fail")]
|
|
[InlineData("POST", "/stream")]
|
|
[InlineData("DELETE", "/admin/reset")]
|
|
[InlineData("GET", "/quick")]
|
|
public void PathMatching_ExactPaths_MatchCorrectly(string method, string path)
|
|
{
|
|
// Arrange
|
|
var registry = _fixture.EndpointRegistry;
|
|
|
|
// Act
|
|
var found = registry.TryMatch(method, path, out var match);
|
|
|
|
// Assert
|
|
found.Should().BeTrue();
|
|
match.Should().NotBeNull();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Parameterized Path Tests
|
|
|
|
[Theory]
|
|
[InlineData("/users/123", "/users/{userId}")]
|
|
[InlineData("/users/abc-def", "/users/{userId}")]
|
|
[InlineData("/users/user_001", "/users/{userId}")]
|
|
public void PathMatching_ParameterizedPaths_MatchCorrectly(string requestPath, string expectedPattern)
|
|
{
|
|
// Arrange
|
|
var registry = _fixture.EndpointRegistry;
|
|
|
|
// Act
|
|
var found = registry.TryMatch("GET", requestPath, out var match);
|
|
|
|
// Assert
|
|
found.Should().BeTrue();
|
|
match!.Endpoint.Path.Should().Be(expectedPattern);
|
|
}
|
|
|
|
[Fact]
|
|
public void PathMatching_PostUsersPath_MatchesCreateEndpoint()
|
|
{
|
|
// Arrange
|
|
var registry = _fixture.EndpointRegistry;
|
|
|
|
// Act
|
|
var found = registry.TryMatch("POST", "/users", out var match);
|
|
|
|
// Assert
|
|
found.Should().BeTrue();
|
|
match!.Endpoint.HandlerType.Should().Be(typeof(CreateUserEndpoint));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Non-Matching Path Tests
|
|
|
|
[Theory]
|
|
[InlineData("GET", "/nonexistent")]
|
|
[InlineData("POST", "/unknown/path")]
|
|
[InlineData("PUT", "/echo")] // Wrong method
|
|
[InlineData("GET", "/admin/reset")] // Wrong method
|
|
public void PathMatching_NonMatchingPaths_ReturnFalse(string method, string path)
|
|
{
|
|
// Arrange
|
|
var registry = _fixture.EndpointRegistry;
|
|
|
|
// Act
|
|
var found = registry.TryMatch(method, path, out var match);
|
|
|
|
// Assert
|
|
found.Should().BeFalse();
|
|
match.Should().BeNull();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method Matching Tests
|
|
|
|
[Fact]
|
|
public void PathMatching_SamePathDifferentMethods_MatchCorrectEndpoint()
|
|
{
|
|
// Arrange
|
|
var registry = _fixture.EndpointRegistry;
|
|
|
|
// Act
|
|
registry.TryMatch("POST", "/users", out var postMatch);
|
|
registry.TryMatch("GET", "/users/123", out var getMatch);
|
|
|
|
// Assert
|
|
postMatch.Should().NotBeNull();
|
|
postMatch!.Endpoint.HandlerType.Should().Be(typeof(CreateUserEndpoint));
|
|
|
|
getMatch.Should().NotBeNull();
|
|
getMatch!.Endpoint.HandlerType.Should().Be(typeof(GetUserEndpoint));
|
|
}
|
|
|
|
#endregion
|
|
}
|