I am trying to write tests for a custom MultipartMemoryStreamProvider
- one that is very similar to this MultipartFormDataMemoryStreamProvider.cs
In particular, I am trying to test my own implementation of the GetStream(HttpContent parent, HttpContentHeaders headers)
method.
It requires an HttpContent and HttpContentHeaders.
To achieve this I am trying to create a controller context and controller, then pass through the appropriate properties from that controllers request.
In fact, I have tried to implement the answer on this (duplicate) question: Testing a Web API method that uses HttpContext.Current.Request.Files?
Everything I try results in the Content-Disposition
on the headers being null
As shown in the images below:
Any idea what I am missing?
For code-sake, here is a copy of the code. You will notice it's the same as that in the answer on the other question. I just can't get passed the null content-disposition.
var content = new ByteArrayContent(new Byte[100]);
content.Headers.Add("Content-Disposition", "form-data");
var controllerContext = new HttpControllerContext
{
Request = new HttpRequestMessage
{
Content = new MultipartContent { content }
}
};
var controller = new MockController();
controller.ControllerContext = controllerContext;
MockController is simply:
public class MockController : ApiController { }