I am using .net core creating an API. One of my methods is a POST which inserts a new record. The successful response returns a 201 Created. In .net I can use the helper CreatedResult e.g.
return Created(new Uri(Url.Link("get_method", new { id = record.id })), record);
This will return a 201 response with the correct Location header set. The Location header uses the incoming request to build up the url using the hostname.
When unit testing in .net webapi2 I could create a custom HttpRequestMessage and set the hostname myself. Now this seems to have disappeared in the new .net core framework.
How do I mock the incoming request so I can unit test and create a valid Location header.
I believe that I need to be mocking HttpRequest on the HttpContext for the controller.
UserController controller = new UserController();
controller.ControllerContext.HttpContext.Request = ?
How to I mock this Request parameter? It is a readonly property.