title: How to unit test Asp.net MVC fileUpload
body: <p>Hello I am new in TDD development.<br>
  I came across this post for <a href="http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx">Using asp.net mvc to upload file</a><br>
  Phil Haack states that a class could be used for file upload control, in which he use the default HttpFileCollectionValueProvider:</p>
  
  <pre>
  [HttpPost]
  public ActionResult Index(HttpPostedFileBase file) {
  
    if (file.ContentLength > 0) {
      var fileName = Path.GetFileName(file.FileName);
      var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
      file.SaveAs(path);
    }
  
    return RedirectToAction("Index");
  }</pre>
  
  <p>the value is bounded in a form as</p>
  
  <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt;
    &lt;label for="file"&gt;Filename:&lt;/label&gt;
    &lt;input type="file" name="file" id="file" /&gt;
    &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Note that the HttpPostedFileBase is parsed as a parameter into the controller with the name "file" in the html form and as parsing parameter in Index controller.</p>
  
  <p>I have two questions:<br>
  1. How can I verify the file.SaveAs method?<br>
  2. I am not quite sure how to unit test with this. In the test controller file I should have a fake HttpPostedFileBase but it is sealed. Does anyone have some strategies to deal with this?</p>
  
  <p>Thank you very much! </p>