Reputation: 55022
How can I mock HttpPostedFileBase ?
its props are readonly and i need to test a fileupload module.
What mocking framework should i use?
public class FileUpload
{
private readonly HttpPostedFileBase _file;
private readonly string _filePath;
public FileUpload(HttpPostedFileBase file, string path)
{
_file = file;
_filePath = path;
}
.......
Upvotes: 0
Views: 664
Reputation: 44706
HttpPostedFileBase
is an abstract class. In your test, just create a new class inheriting from it and create your own stub version (hardcoding the method results you need to test). What style of testing are you doing?
I think here stubbing would be most appropriate.
Alternatively, you could use Moq (or another framework) to help with this.
Upvotes: 2