jeudi 23 avril 2015

How to create a file to populate HttpContext.Current.Request.Files?

In my Web API, The POST action method uploads a file on server.

For unit testing this method I need to create a HttpContext and put a file inside it's request:

HttpContext.Current.Request.Files

So far I am faking HttpContext with this Code which works perfectly:

  HttpRequest request = new HttpRequest("", "http://localhost/", "");
  HttpResponse response = new HttpResponse(new StringWriter());
  HttpContext.Current = new HttpContext(request, response);

Note that I DON'T want to use Moq or any other Mocking libraries.

How can I accomplish this? (MultipartContent maybe?)

Thanks

Aucun commentaire:

Enregistrer un commentaire