views:

31

answers:

1

I have to write a Unit test for this method but I am unable to construct HttpPostedFileBase... When I run the method from the browser, it works well but I really need an autoamted unit test for that. So my question is: how do I construct HttpPosterFileBase in order to pass a file to HttpPostedFileBase.

Thanks.

    public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (var file in files)
        {
           // ...
        }
    }
A: 

How about doing something like this:

public class MockHttpPostedFileBase : HttpPostedFileBase
{
    public MockHttpPostedFileBase()
    {

    }
}

then you can create a new one:

MockHttpPostedFileBase mockFile = new MockHttpPostedFileBase();
Yngve B. Nilsen