Snapshot Testing
Although Alba does not ship built-in snapshotting support, it does easily integrate with the popular Verify framework. Given Verify
and Verify.AspNetCore
has been added and initialized for your test framework of choice, you can reliably feed in the HttpContext
and response data for a complete picture of your network request.
Given a test with the shape of:
cs
await using var host = await AlbaHost.For<global::Program>();
var scenario = await host.Scenario(s =>
{
s.Post.Json(new MyEntity(Guid.NewGuid(), "SomeValue")).ToUrl("/json");
});
var body = scenario.ReadAsJson<MyEntity>();
await Verify(new {
scenario.Context,
ResponseBody = body,
});
Will result in a snapshot of:
json
{
Context: {
Request: {
Headers: {
Accept: application/json,
Content-Length: 67,
Content-Type: application/json,
Host: localhost
}
},
Response: {
StatusCode: OK,
Headers: {
Content-Type: application/json; charset=utf-8
}
}
},
ResponseBody: {
Id: Guid_1,
MyValue: SomeValue
}
}