|
Hi There.
I have an ASP.net MVC 4 (beta) WebApi that looks something like this:
public void Post() { if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); }
IEnumerable<HttpContent> parts = Request.Content.ReadAsMultipartAsync().Result;
// Rest of code here. }
I am trying to unit test this code, but can't work out how to do it. Am I on the right track here?
[TestMethod] public void Post_Test() { MultipartFormDataContent content = new MultipartFormDataContent(); content.Add(new StringContent("bar"), "foo");
this.controller.Request = new HttpRequestMessage(); this.controller.Request.Content = content; this.controller.Post(); }
This code is throwing the following exception:
System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Unexpected end of MIME multipart stream. MIME multipart message is not complete. at System.Net.Http.MimeMultipartBodyPartParser.d__0.MoveNext() at System.Net.Http.HttpContentMultipartExtensions.MoveNextPart(MultipartAsyncContext
context) at System.Net.Http.HttpContentMultipartExtensions.MultipartReadAsyncComplete(IAsyncResult result) at System.Net.Http.HttpContentMultipartExtensions.OnMultipartReadAsyncComplete(IAsyncResult result)
Am I on the right track? How do I mark the end of the MultipartFormDataContent?
|