This is probably a fairly simple question but I'll admit, I'm stuck.
I have a controller that is returning IHttpActionResult
and I need to write unit tests for this.
Here's the controller:
public IHttpActionResult GetPerson(int id) {
Person person = repository.Get(id);
if (person == null) {
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Ok(new {
User = person
});
}
Here's the unit test:
[TestMethod]
public void GetReturnsValidPerson() {
var userController = new UserController();
IHttpActionResult actionResult = userController.GetPerson(1);
Assert.IsInstanceOfType(actionResult, typeof(OkResult));
}
And here's the error from the test:
Assert.IsInstanceOfType failed. Expected type:. Actual type:.
What exactly is going on here? The return from the controller is an HTTP 200 Ok response. Why is this expecting OkNegotiatedContentResult
?
Aucun commentaire:
Enregistrer un commentaire