- Implemented tests for RouterConfig, RoutingOptions, StaticInstanceConfig, and RouterConfigOptions to ensure default values are set correctly. - Added tests for RouterConfigProvider to validate configurations and ensure defaults are returned when no file is specified. - Created tests for ConfigValidationResult to check success and error scenarios. - Developed tests for ServiceCollectionExtensions to verify service registration for RouterConfig. - Introduced UdpTransportTests to validate serialization, connection, request-response, and error handling in UDP transport. - Added scripts for signing authority gaps and hashing DevPortal SDK snippets.
115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
using Examples.Billing.Microservice.Endpoints;
|
|
using Examples.Inventory.Microservice.Endpoints;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using StellaOps.Microservice;
|
|
using StellaOps.Router.Common.Enums;
|
|
using StellaOps.Router.Transport.InMemory;
|
|
using Xunit;
|
|
|
|
namespace Examples.Integration.Tests;
|
|
|
|
/// <summary>
|
|
/// Test fixture that sets up the gateway and microservices for integration testing.
|
|
/// Uses in-memory transport for fast, isolated tests.
|
|
/// </summary>
|
|
public sealed class GatewayFixture : IAsyncLifetime
|
|
{
|
|
private WebApplicationFactory<Examples.Gateway.Program>? _gatewayFactory;
|
|
private IHost? _billingHost;
|
|
private IHost? _inventoryHost;
|
|
|
|
public HttpClient GatewayClient { get; private set; } = null!;
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
// Start the gateway
|
|
_gatewayFactory = new WebApplicationFactory<Examples.Gateway.Program>()
|
|
.WithWebHostBuilder(builder =>
|
|
{
|
|
builder.UseEnvironment("Testing");
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
services.AddInMemoryTransport();
|
|
});
|
|
});
|
|
|
|
GatewayClient = _gatewayFactory.CreateClient();
|
|
|
|
// Start billing microservice
|
|
var billingBuilder = Host.CreateApplicationBuilder();
|
|
billingBuilder.Services.AddStellaMicroservice(options =>
|
|
{
|
|
options.ServiceName = "billing";
|
|
options.Version = "1.0.0";
|
|
options.Region = "test";
|
|
options.InstanceId = "billing-test";
|
|
options.Routers =
|
|
[
|
|
new RouterEndpointConfig
|
|
{
|
|
Host = "localhost",
|
|
Port = 5100,
|
|
TransportType = TransportType.InMemory
|
|
}
|
|
];
|
|
});
|
|
billingBuilder.Services.AddScoped<CreateInvoiceEndpoint>();
|
|
billingBuilder.Services.AddScoped<GetInvoiceEndpoint>();
|
|
billingBuilder.Services.AddScoped<UploadAttachmentEndpoint>();
|
|
billingBuilder.Services.AddInMemoryTransport();
|
|
|
|
_billingHost = billingBuilder.Build();
|
|
await _billingHost.StartAsync();
|
|
|
|
// Start inventory microservice
|
|
var inventoryBuilder = Host.CreateApplicationBuilder();
|
|
inventoryBuilder.Services.AddStellaMicroservice(options =>
|
|
{
|
|
options.ServiceName = "inventory";
|
|
options.Version = "1.0.0";
|
|
options.Region = "test";
|
|
options.InstanceId = "inventory-test";
|
|
options.Routers =
|
|
[
|
|
new RouterEndpointConfig
|
|
{
|
|
Host = "localhost",
|
|
Port = 5100,
|
|
TransportType = TransportType.InMemory
|
|
}
|
|
];
|
|
});
|
|
inventoryBuilder.Services.AddScoped<ListItemsEndpoint>();
|
|
inventoryBuilder.Services.AddScoped<GetItemEndpoint>();
|
|
inventoryBuilder.Services.AddInMemoryTransport();
|
|
|
|
_inventoryHost = inventoryBuilder.Build();
|
|
await _inventoryHost.StartAsync();
|
|
|
|
// Allow services to register
|
|
await Task.Delay(100);
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
GatewayClient.Dispose();
|
|
|
|
if (_billingHost is not null)
|
|
{
|
|
await _billingHost.StopAsync();
|
|
_billingHost.Dispose();
|
|
}
|
|
|
|
if (_inventoryHost is not null)
|
|
{
|
|
await _inventoryHost.StopAsync();
|
|
_inventoryHost.Dispose();
|
|
}
|
|
|
|
_gatewayFactory?.Dispose();
|
|
}
|
|
}
|