How basdijkstra/rest-assured-net works
Main components
• DSL/API Frontend: At the top of the stack, you have the DSL. The file Dsl.cs (in the RestAssured.Net folder) exposes the fluent API for writing tests. This is what users leverage in their test code (as demonstrated in the README usage example).
• Configuration Module: The Configuration folder (with RestAssuredConfiguration.cs) indicates that the library supports customization and configuration options.
• Request Building & Processing: In the RestAssured.Net/Request subdirectory, you find multiple folders and files:
• Builders (e.g., RequestSpecBuilder.cs, GraphQLRequestBuilder.cs) which are used to construct the request (including paths, headers, query parameters, cookies, and even GraphQL support).
• HttpRequestProcessor.cs and ExecutableRequest.cs indicate the module that actually sends the HTTP calls.
• Exceptions subfolder for handling and propagating errors during request creation and execution.
• Logging Components: Both in the core library (RestAssured.Net/Logging) and the dedicated logging within Request/Response sections. These include RequestLogger.cs, ResponseLogger.cs, and related log level components.
• Response Handling: The RestAssured.Net/Response folder covers:
• Content type handling (e.g., ContentTypeUtils.cs)
• Deserialization support (with the Deserializer, DeserializeAs, etc.)
• Logging and extraction layers (ExtractableResponse, ExtractAs, and VerifyAs) to allow for robust validation and extraction of information from responses.
• Exception handling for deserialization and extraction errors.
• Testing & Demo Application: The separate projects (RestAssured.Net.DemoService and RestAssured.Net.Tests) not only demonstrate the usage but also ensure that the library is covered by a comprehensive test suite. In tests, components like Models (BlogPost, Location, Place, User) and schema definitions (JsonSchemaDefinitions, XmlSchemaDefinitions) are used to simulate real API interactions.
Component Relationships & Data Flows
• The user (or test code) starts at the DSL/API Frontend, invoking methods like Given(), When(), Get(), Then(), etc.
• These DSL calls internally use the Request Builders to create a RequestSpecification.
• The RequestSpecification is then processed by the RequestSpecificationProcessor and handed off to the HttpRequestProcessor, which makes the actual HTTP call.
• As the request is processed, logging happens at two levels – both in the request phase (via RequestLogger) and again on receiving the response (via ResponseLogger).
• The response is captured as an ExtractableResponse and then deserialized using the appropriate Deserializer, based on content type detection (handled by the ContentTypeUtils and SupportedContentType components).
• Post-processing involves validation and extraction functions (VerifyAs, ExtractAs) that the user may chain in their tests.
• Any errors in request creation, execution, response extraction, or deserialization are caught and managed by their respective Exception classes.
Architectural Patterns & Design Principles
• Fluent Interface / DSL Pattern: The library is built to offer an easy-to-use DSL that allows developers to write expressive tests.
• Separation of Concerns: Each layer (configuration, request building, processing, logging, and response handling) is modular, ensuring that each responsibility is clearly delineated.
• Exception Handling: Specialized exceptions for different kinds of failures (either on the request or response fronts) indicate robust error management.
• Extensibility: The use of builders and segregated modules for different HTTP operations (including GraphQL, multipart, etc.) shows the design’s adaptability.