I want to test the following line of code:
...
Bitmap uploadedPicture = Bitmap.FromStream(model.Picture.InputStream) as Bitmap;
...
Picture is a property in my model type HttpPostedFileBase. So I would like to mock a HttpPostedFileBase property for unit-testing:
model.Picture = new Mock<HttpPostedFileBase>().Object;
No problem at all.
Now I have to mock the InputStream, otherwise it's null:
model.Picture.InputStream = new Mock<Stream>().Object;
This isn't working as the InputStream is read-only (hasn't a setter method):
public virtual Stream InputStream { get; }
Is there a good and clean way to handle this problem? One solution would be to override HttpPostedFileBase in a derived class for my unit-test. Any other idea?
FileName.EndsWith(.jpg).Returns(true)
? – Jilleen