I am moving to use and ActionResult rather than IActionResult so that Swagger automatically picks up my types, but I am getting an error saying that I cannot cast an ActionResult to an OkObjectResult.
How do I cast to an OKObjectResult for testing a 200 status code?
My IActionResult Controller
[HttpGet]
public async Task<IActionResult<IEnumerable<Listing>>> Get()
{
var listings = await listingService.GetAllListings();
if (listings.Any())
{
return Ok(listings);
}
return NotFound();
}
My ActionResult Controller
[HttpGet]
public async Task<ActionResult<IEnumerable<Listing>>> Get()
{
var listings = await listingService.GetAllListings();
if (listings.Any())
{
return Ok(listings);
}
return NotFound();
}
My Test
[Fact]
public async Task ShouldReturnA200StatusCode()
{
var res = (OkObjectResult)await sut.Get();
res.StatusCode.Should().Be(200);
}