Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

AAA syntax: How to mock HttpFileCollectionBase

+1 vote
Here's a question, how to mock HttpFileCollectionBase?

I tried to use
WillReturnCollectionValuesOf(new HttpFileCollectionBase(){//blah blah});


But compiler gives me a compilation error because there is no public constructor for HttpFileCollectionBase, and there is no Add method for it as well.

Then I tried to use
WillReturn()


But this WillReturn doesn't work if there is a foreach looping over the collection.

Any ideas?
________
vaporizer affiliate program
asked Nov 18, 2008 by nsoonhui (9,460 points)

3 Answers

+1 vote
I solved the problem by usingDuck-type swapping, but it is not really working because I can't access the element by name.
________
vapor genie
answered Nov 18, 2008 by nsoonhui (9,460 points)
0 votes
Hi soon

Actually you can use WillReturnCollectionValuesOf with any IEnumrble type
even simple array should work:

Isolate.WhenCalled(()=> fake.F()).WillReturnCollectionValuesOf(new [] {new HttpFileCollectionWrapper()});


WillReturnCollectionValuesOf will duck typing just like Swap.CallsOn.
answered Nov 18, 2008 by ohad (37,080 points)
+1 vote
Hi soon

Actually you can use WillReturnCollectionValuesOf with any IEnumrble type
even simple array should work:

Isolate.WhenCalled(()=> fake.F()).WillReturnCollectionValuesOf(new [] {new HttpFileCollectionWrapper()});


WillReturnCollectionValuesOf will duck typing just like Swap.CallsOn.

I see! Thanks. It's good to know that WillReturnCollectionValuesOf can duck type.
________
vapir no2
answered Nov 18, 2008 by nsoonhui (9,460 points)
...