using System.Net; using FluentAssertions; using Xunit; namespace Examples.Integration.Tests; /// /// Tests that verify multiple microservices can register and receive /// correctly routed requests through the gateway. /// public sealed class MultiServiceRoutingTests : IClassFixture { private readonly GatewayFixture _fixture; public MultiServiceRoutingTests(GatewayFixture fixture) { _fixture = fixture; } [Fact] public async Task Gateway_RoutesBillingRequests_ToBillingService() { // Act var response = await _fixture.GatewayClient.GetAsync("/invoices/INV-001"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain("INV-001"); } [Fact] public async Task Gateway_RoutesInventoryRequests_ToInventoryService() { // Act var response = await _fixture.GatewayClient.GetAsync("/items/SKU-001"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain("SKU-001"); } [Fact] public async Task Gateway_HandlesSequentialRequestsToDifferentServices() { // Act - Send requests to both services var billingResponse = await _fixture.GatewayClient.GetAsync("/invoices/INV-001"); var inventoryResponse = await _fixture.GatewayClient.GetAsync("/items/SKU-001"); // Assert - Both should succeed billingResponse.StatusCode.Should().Be(HttpStatusCode.OK); inventoryResponse.StatusCode.Should().Be(HttpStatusCode.OK); } [Fact] public async Task Gateway_HandlesConcurrentRequestsToDifferentServices() { // Act - Send requests to both services concurrently var billingTask = _fixture.GatewayClient.GetAsync("/invoices/INV-001"); var inventoryTask = _fixture.GatewayClient.GetAsync("/items/SKU-001"); await Task.WhenAll(billingTask, inventoryTask); // Assert - Both should succeed billingTask.Result.StatusCode.Should().Be(HttpStatusCode.OK); inventoryTask.Result.StatusCode.Should().Be(HttpStatusCode.OK); } [Fact] public async Task Gateway_ReturnsNotFound_ForUnknownRoute() { // Act var response = await _fixture.GatewayClient.GetAsync("/unknown/route"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); } }