title: Unit Test a file upload, how?
body: <p>Using MVC3.NET I have a file upload method in a controller that works fine with the following signature <code>public ActionResult UploadFile(IEnumerable&lt;HttpPostedFileBase&gt; file)</code></p>
  
  <p>How can I unit test this with NUnit? I have looked around and everyone seems to point to Moq but I'm new to unit testing and cannot get Moq working.</p>
  
  <p>I have found interesting blogs such as this: <a href="http://danielglyde.blogspot.com/2011/07/tdd-with-aspnet-mvc-3-moq-and.html">http://danielglyde.blogspot.com/2011/07/tdd-with-aspnet-mvc-3-moq-and.html</a> but am struggling to figure out how the same might be done to 'fake' a file upload, and am also wary that a lot on moq examples that I have managed to find now seem to have deprecated code in them.</p>
  
  <p>I would simply like to know how I can simulate a HttpPostedFileBase so I can test my upload code, using Moq or otherwise - I would be really grateful if someone could give me some code examples on how to do this.</p>
  
  <p>The following code taken from other examples on here:</p>
  
  <pre><code>var file = new Mock&lt;HttpPostedFileBase&gt;();
              file.Setup(f =&gt; f.ContentLength).Returns(1);
              file.Setup(f =&gt; f.FileName).Returns("test.txt");
  
  controller.upload(file);
  </code></pre>
  
  <p>generates the following error when I try to compile: </p>
  
  <blockquote>
    <p>cannot convert from 'Moq.Mock' to
    'System.Web.HttpPostedFileBase'</p>
  </blockquote>
  
  <p>I have changed the method to take a singular HttpPostedFileBase for now, rather than an IEnumerable, as being able to 'mock' one is what I'm trying to focus on for the purpose of this question.</p>