Mock HttpPostedFileWrapper
.net, asp.net-mvc, c#, mocking, moq
Solution
You should be mocking `HttpPostedFileBase`, not `HttpPostedFileWrapper`.
Problem
I am trying to Mock the MVC object `HttpPostedFileWrapper` so I can test the "ContentType" and "InputStream" properties in particular. I set up my mock as so: ``` 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 on the first line: Type to mock must be an interface or an abstract or non-sealed class. If I change `HttpPostedFile` to `HttpPostedFileBase` I get this exception when I call `mockFileWrapper.Object` Can not instantiate proxy of class: System.Web.HttpPostedFileWrapper. Could not find a constructor that would match given arguments: Moq.Mock`1[System.Web.HttpPostedFileBase] Does anyone know what I can do to pull this off?