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,60 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Microservice;
|
||||
|
||||
namespace Examples.Billing.Microservice.Endpoints;
|
||||
|
||||
/// <summary>
|
||||
/// Endpoint for uploading attachments to an invoice.
|
||||
/// Demonstrates streaming upload using IRawStellaEndpoint.
|
||||
/// </summary>
|
||||
[StellaEndpoint("POST", "/invoices/{id}/attachments", SupportsStreaming = true, TimeoutSeconds = 300)]
|
||||
public sealed class UploadAttachmentEndpoint : IRawStellaEndpoint
|
||||
{
|
||||
private readonly ILogger<UploadAttachmentEndpoint> _logger;
|
||||
|
||||
public UploadAttachmentEndpoint(ILogger<UploadAttachmentEndpoint> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RawResponse> HandleAsync(
|
||||
RawRequestContext context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var invoiceId = context.PathParameters.GetValueOrDefault("id") ?? "unknown";
|
||||
|
||||
var contentType = context.Headers["Content-Type"] ?? "application/octet-stream";
|
||||
_logger.LogInformation(
|
||||
"Uploading attachment for invoice {InvoiceId}, Content-Type: {ContentType}",
|
||||
invoiceId,
|
||||
contentType);
|
||||
|
||||
// Read the streamed body
|
||||
long totalBytes = 0;
|
||||
var buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = await context.Body.ReadAsync(buffer, cancellationToken)) > 0)
|
||||
{
|
||||
totalBytes += bytesRead;
|
||||
// In a real implementation, you would write to storage here
|
||||
}
|
||||
|
||||
_logger.LogInformation(
|
||||
"Received {TotalBytes} bytes for invoice {InvoiceId}",
|
||||
totalBytes,
|
||||
invoiceId);
|
||||
|
||||
// Return success response
|
||||
var response = new
|
||||
{
|
||||
invoiceId,
|
||||
attachmentId = $"ATT-{Guid.NewGuid():N}"[..16].ToUpperInvariant(),
|
||||
size = totalBytes,
|
||||
uploadedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
return RawResponse.Ok(JsonSerializer.Serialize(response));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user