I try to mock the Count-Property of an instance of HttpFileCollectionBase - but somehow it doesn't work.
var fakedRequest = new Mock<HttpRequestBase>();
var fakedFile = new Mock<HttpPostedFileBase>();
fakedFile.SetupGet(x => x.InputStream).Returns(inputStream);
var fakedFileCollection = new Mock<HttpFileCollectionBase>();
fakedFileCollection.SetupGet(x => x.Count).Returns(1);
fakedRequest.SetupGet(x => x.Files).Returns(fakedFileCollection.Object);
fakedRequest.SetupGet(x => x.Files[0]).Returns(fakedFile.Object);
var sut = new TestableExploreController(null, fakedTemporaryStorageRepository.Object)
{
HttpRequest = fakedRequest.Object
};
As you see, I create a mocked HttpRequest, which I inject to the system under test. The Count-Property is defined to return 1 - but it always returns 0. I'm using Moq.
What am I doing wrong?