Files
git.stella-ops.org/src/__Libraries/StellaOps.Microservice/Validation/SchemaValidationException.cs
master cc69d332e3
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Add unit tests for RabbitMq and Udp transport servers and clients
- Implemented comprehensive unit tests for RabbitMqTransportServer, covering constructor, disposal, connection management, event handlers, and exception handling.
- Added configuration tests for RabbitMqTransportServer to validate SSL, durable queues, auto-recovery, and custom virtual host options.
- Created unit tests for UdpFrameProtocol, including frame parsing and serialization, header size validation, and round-trip data preservation.
- Developed tests for UdpTransportClient, focusing on connection handling, event subscriptions, and exception scenarios.
- Established tests for UdpTransportServer, ensuring proper start/stop behavior, connection state management, and event handling.
- Included tests for UdpTransportOptions to verify default values and modification capabilities.
- Enhanced service registration tests for Udp transport services in the dependency injection container.
2025-12-05 19:01:12 +02:00

54 lines
1.6 KiB
C#

namespace StellaOps.Microservice.Validation;
/// <summary>
/// Exception thrown when request or response body fails schema validation.
/// </summary>
public sealed class SchemaValidationException : Exception
{
/// <summary>
/// Gets the endpoint path where validation failed.
/// </summary>
public string EndpointPath { get; }
/// <summary>
/// Gets the HTTP method of the endpoint.
/// </summary>
public string EndpointMethod { get; }
/// <summary>
/// Gets whether this was request or response validation.
/// </summary>
public SchemaDirection Direction { get; }
/// <summary>
/// Gets the list of validation errors.
/// </summary>
public IReadOnlyList<SchemaValidationError> Errors { get; }
/// <summary>
/// Creates a new schema validation exception.
/// </summary>
public SchemaValidationException(
string endpointMethod,
string endpointPath,
SchemaDirection direction,
IReadOnlyList<SchemaValidationError> errors)
: base(BuildMessage(endpointMethod, endpointPath, direction, errors))
{
EndpointMethod = endpointMethod;
EndpointPath = endpointPath;
Direction = direction;
Errors = errors;
}
private static string BuildMessage(
string method,
string path,
SchemaDirection direction,
IReadOnlyList<SchemaValidationError> errors)
{
var directionText = direction == SchemaDirection.Request ? "request" : "response";
return $"Schema validation failed for {directionText} of {method} {path}: {errors.Count} error(s)";
}
}