I have a controller that throws an exception from the following code with the following message: -
public HttpResponseMessage PutABook(Book bookToSave) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "No Permission"); }
I am testing this method with the following code: -
var response = controller.PutABook(new Book()); Assert.That(response.StatusCode,Is.EqualTo(HttpStatusCode.Forbidden)); Assert.That(response.Content,Is.EqualTo("No Permission"));
But I get the error "No permission". I can't seem to respond to an HttpError to get the content of the "Without permission" message. The status code is returned in order. Just trying to get message content .
source share