Let's assume this is my action method
public IHttpActionResult Get(int id)
{
var status = GetSomething(id);
if (status)
{
return Ok();
}
else
{
return NotFound();
}
}
Test will be
var httpActionResult = controller.Get(1);
How do I check my http status code after this?
Best Answer
Here
Ok()
is just a helper for the typeOkResult
which sets the response status to beHttpStatusCode.Ok
...so you can just check if the instance of your action result is anOkResult
...some examples(written inXUnit
):