I'm porting a project to the new minimal api of ASP.Net 6.
Right now I have something similar to this:
builder.MapGet("/hello", CiaoCiao);
IResult CiaoCiao()
{
return Results.Ok("Ciao ciao!");
}
The reason for having the endpoint implementation in a separate function is that I want to write a unit test for it. But I'm having the following issue:
How do I get the response value (in this case the string "Ciao ciao!"
) out of the IResult
?
So far I didn't find anything in the official documentation about that. There is a class Microsoft.AspNetCore.Http.Result.OkObjectResult
which I could cast to. But that's internal to AspNetCore
, so it's not accessible from my unit test project.