chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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 by nsoonhui (59.1k points)

3 Answers

0 votes
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 by nsoonhui (59.1k 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 by ohad (35.4k 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.

I see! Thanks. It's good to know that WillReturnCollectionValuesOf can duck type.
________
vapir no2
answered by nsoonhui (59.1k points)
...