Mock HttpPostedFileWrapper

I am trying to mock an MVC object HttpPostedFileWrapper, so I can check the ContentType and InputStream properties in particular. I set up my layout like this:

var mockPostedFile = new Mock<HttpPostedFile>();
var mockFileWrapper = new Mock<HttpPostedFileWrapper>(mockPostedFile);
mockFileWrapper.Setup(file => file.ContentType).Returns("application/pdf");
mockFileWrapper.Setup(file => file.InputStream).Returns(fileStream);

but I get this exception in the first line:

The type for bullying must be an interface or an abstract or unsealed class.

If I change HttpPostedFileto HttpPostedFileBase, I get this exception when I callmockFileWrapper.Object

Unable to create proxy class: System.Web.HttpPostedFileWrapper. Could not find a constructor that matches the given arguments: Moq.Mock`1 [System.Web.HttpPostedFileBase]

Does anyone know what I can do to take this off?

+3
source share
2 answers

HttpPostedFileBase, HttpPostedFileWrapper.

+7

, , HttpPostedFile.

0

All Articles