Add unit tests for Router configuration and transport layers
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled

- 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.
This commit is contained in:
StellaOps Bot
2025-12-05 08:01:47 +02:00
parent 635c70e828
commit 6a299d231f
294 changed files with 28434 additions and 1329 deletions

View File

@@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using StellaOps.Microservice;
namespace Examples.Inventory.Microservice.Endpoints;
/// <summary>
/// Request model for getting a single inventory item.
/// </summary>
public sealed record GetItemRequest
{
public required string Sku { get; init; }
}
/// <summary>
/// Response model for a single inventory item with details.
/// </summary>
public sealed record GetItemResponse
{
public required string Sku { get; init; }
public required string Name { get; init; }
public required string Description { get; init; }
public required string Category { get; init; }
public required int QuantityOnHand { get; init; }
public required int ReorderPoint { get; init; }
public required decimal UnitPrice { get; init; }
public required string Location { get; init; }
public required DateTime LastUpdated { get; init; }
}
/// <summary>
/// Endpoint for getting a single inventory item by SKU.
/// Demonstrates path parameter extraction.
/// </summary>
[StellaEndpoint("GET", "/items/{sku}", TimeoutSeconds = 10)]
public sealed class GetItemEndpoint : IStellaEndpoint<GetItemRequest, GetItemResponse>
{
private readonly ILogger<GetItemEndpoint> _logger;
public GetItemEndpoint(ILogger<GetItemEndpoint> logger)
{
_logger = logger;
}
public Task<GetItemResponse> HandleAsync(
GetItemRequest request,
CancellationToken cancellationToken)
{
_logger.LogInformation("Fetching inventory item {Sku}", request.Sku);
// Simulate item lookup
return Task.FromResult(new GetItemResponse
{
Sku = request.Sku,
Name = "Widget A",
Description = "A high-quality widget for general purpose use",
Category = "widgets",
QuantityOnHand = 100,
ReorderPoint = 25,
UnitPrice = 9.99m,
Location = "Warehouse A, Aisle 3, Shelf 2",
LastUpdated = DateTime.UtcNow.AddHours(-2)
});
}
}

View File

@@ -0,0 +1,107 @@
using Microsoft.Extensions.Logging;
using StellaOps.Microservice;
namespace Examples.Inventory.Microservice.Endpoints;
/// <summary>
/// Request model for listing inventory items.
/// </summary>
public sealed record ListItemsRequest
{
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 20;
public string? Category { get; init; }
}
/// <summary>
/// Response model for listing inventory items.
/// </summary>
public sealed record ListItemsResponse
{
public required List<InventoryItem> Items { get; init; }
public required int TotalCount { get; init; }
public required int Page { get; init; }
public required int PageSize { get; init; }
}
/// <summary>
/// Inventory item model.
/// </summary>
public sealed record InventoryItem
{
public required string Sku { get; init; }
public required string Name { get; init; }
public required string Category { get; init; }
public required int QuantityOnHand { get; init; }
public required decimal UnitPrice { get; init; }
}
/// <summary>
/// Endpoint for listing inventory items.
/// Demonstrates pagination and filtering.
/// </summary>
[StellaEndpoint("GET", "/items", TimeoutSeconds = 15)]
public sealed class ListItemsEndpoint : IStellaEndpoint<ListItemsRequest, ListItemsResponse>
{
private readonly ILogger<ListItemsEndpoint> _logger;
public ListItemsEndpoint(ILogger<ListItemsEndpoint> logger)
{
_logger = logger;
}
public Task<ListItemsResponse> HandleAsync(
ListItemsRequest request,
CancellationToken cancellationToken)
{
_logger.LogInformation(
"Listing inventory items - Page: {Page}, PageSize: {PageSize}, Category: {Category}",
request.Page,
request.PageSize,
request.Category ?? "(all)");
// Simulate item list
var items = new List<InventoryItem>
{
new()
{
Sku = "SKU-001",
Name = "Widget A",
Category = "widgets",
QuantityOnHand = 100,
UnitPrice = 9.99m
},
new()
{
Sku = "SKU-002",
Name = "Widget B",
Category = "widgets",
QuantityOnHand = 50,
UnitPrice = 14.99m
},
new()
{
Sku = "SKU-003",
Name = "Gadget X",
Category = "gadgets",
QuantityOnHand = 25,
UnitPrice = 29.99m
}
};
// Filter by category if specified
if (!string.IsNullOrWhiteSpace(request.Category))
{
items = items.Where(i =>
i.Category.Equals(request.Category, StringComparison.OrdinalIgnoreCase)).ToList();
}
return Task.FromResult(new ListItemsResponse
{
Items = items,
TotalCount = items.Count,
Page = request.Page,
PageSize = request.PageSize
});
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-rc.2.25502.107" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\src\__Libraries\StellaOps.Microservice\StellaOps.Microservice.csproj" />
<ProjectReference Include="..\..\..\..\src\__Libraries\StellaOps.Router.Common\StellaOps.Router.Common.csproj" />
<ProjectReference Include="..\..\..\..\src\__Libraries\StellaOps.Router.Transport.InMemory\StellaOps.Router.Transport.InMemory.csproj" />
<!-- Reference the source generator -->
<ProjectReference Include="..\..\..\..\src\__Libraries\StellaOps.Microservice.SourceGen\StellaOps.Microservice.SourceGen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,38 @@
using Examples.Inventory.Microservice.Endpoints;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using StellaOps.Microservice;
using StellaOps.Router.Common.Enums;
using StellaOps.Router.Transport.InMemory;
var builder = Host.CreateApplicationBuilder(args);
// Configure the Stella microservice
builder.Services.AddStellaMicroservice(options =>
{
options.ServiceName = "inventory";
options.Version = "1.0.0";
options.Region = "demo";
options.InstanceId = $"inventory-{Environment.MachineName}";
options.Routers =
[
new RouterEndpointConfig
{
Host = "localhost",
Port = 5100,
TransportType = TransportType.InMemory
}
];
});
// Register endpoint handlers
builder.Services.AddScoped<ListItemsEndpoint>();
builder.Services.AddScoped<GetItemEndpoint>();
// Add in-memory transport
builder.Services.AddInMemoryTransport();
var host = builder.Build();
Console.WriteLine("Inventory microservice starting...");
await host.RunAsync();