Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i just started to learn moq, and i want some IEnumerable sum to return some value.
i was told i need to add two items to IEnumerable and then calculate.
can i moq IEnumerable Sum to return the wanted value without moqing the objects?

Thanks, Ofer.
Posted

The Sum on IEnumerable is an Extension method and as such is a static method.

While there are ways to mock static methods Moq isn't able to do so (efficiently) since it is built around creating a dynamic proxy, which means it can only mock virtual or abstract methods.

Hope this helps,
Fredrik
 
Share this answer
 
Comments
imbaro 21-Nov-13 4:04am    
How can mock mock static methods?
Fredrik Bornander 21-Nov-13 4:39am    
TypeMock (http://www.typemock.com/) can mock static methods, but honestly I would argue against trying to mock the Linq methods. You'll be better off sticking to Moq and mocking the input to the Linq method.
Thanks! i learned from it.
imbaro.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900