Skip to content

Instantly share code, notes, and snippets.

@mauricedb
Created May 12, 2013 09:30
Show Gist options
  • Save mauricedb/5562976 to your computer and use it in GitHub Desktop.
Save mauricedb/5562976 to your computer and use it in GitHub Desktop.
Unit test an ASP.NET ApiController that uses the ApiController.Request property
[TestMethod]
public void GetWithAnUnknownIdShouldReturnNotFound()
{
// Arrange
var controller = new BooksController()
{
Request = new HttpRequestMessage()
{
Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
}
};
// Act
var response = controller.Get(999);
// Assert
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment