Add unit tests for Router configuration and transport layers
- 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:
@@ -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)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user