Precept.Api
HTTP API testing for Precept: a fluent request builder, response assertions, and automatic request/response logging into the test report.
dotnet add package Precept.Api
services.AddPreceptApi();
var response = await Rest.Post("/orders")
.WithJsonBody(new { sku = "ABC", quantity = 2 })
.SendAsync();
await Assert.That(response).ToBeSuccessfulAsync();
await Assert.That(response).ToHaveJsonValueAsync("status", "created");
await Assert.That(response).JsonAt("customer.email").ToEndWithAsync("@example.com");
await Assert.That(response).Json<Order>().ToSatisfyAsync(o => o.Lines.Count == 2, "have two lines");
Every failure carries the request line and the body, because that is always the next question.
ToHaveStatusAsync, ToBeSuccessfulAsync, ToHaveHeaderAsync, ToContainAsync,
ToHaveJsonValueAsync, ToHaveXmlValueAsync and ToRespondWithinAsync cover responses, and
JsonAt/Json<T> and XmlAt/Xml<T> narrow to a part of one so the general assertions apply to
it. An XML API is the same shape with data contracts: WithXmlBody writes a [DataContract] type,
Xml<T> reads one back, and XmlAt takes an XPath whose prefixes are declared in
Api:XmlNamespaces. Polling for a state that arrives later is the same sentence under
Assert.Eventually:
await Assert.Eventually(() => Rest.Get($"/jobs/{id}").SendAsync())
.Within(TimeSpan.FromMinutes(2))
.ToHaveJsonValueAsync("state", "Completed");
Part of Precept, a .NET 10 test automation framework. Full documentation: assertions on a response · XML · waiting · configuration