A simple and efficient tool for testing your API endpoints without any hassle. Just create and add your request endpoints, then run the tests.
First, we create a class that inherits from the base class RequestEndpoint
For example:
[Endpoint("/todos")]
internal class JsonPlaseholderTest : RequestEndpoint
{
public override async Task<IEndpointResult> Handle(IEndpointResult previousResult)
{
var todos = await GetAsync();
if (todos.IsSuccessStatusCode)
return TestSucceeded(todos);
return TestFailed(todos);
}
}
Each RequestEndpoint
provides two functions for sending the final response: TestSucceeded
and TestFailed
. You send the response generated in the current test as input to these functions so that it remains available for subsequent tests. For example, if you want to retrieve a todo item by its ID, which was created from the response of the previous test, you can access it using the previousResult
object from parameter
It also has functions to send requests to specified endpoints such as
GetAsync
PostAsync
and..
is
But note that entering the functions does not require entering the request address
Finally, to set up the request pipeline, you need to add your tests in your console application with MapFromAssembly
and execute the RunTests
function
var baseAddress = new Uri("https://jsonplaceholder.typicode.com");
var builder = new RequesterBuilder(baseAddress)
.MapFromAssembly(typeof(Program).Assembly);
var app = builder.Build();
await app.RunTests();