c#moq IEnumerable Sum。 [英] c# moq IEnumerable Sum.

查看:229
本文介绍了c#moq IEnumerable Sum。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习moq,我想要一些IEnumerable总和来返回一些价值。

i告诉我需要在IEnumerable中添加两个项目然后计算。

我可以moq IEnumerable Sum来返回想要的值而不用moqing这些对象吗?



谢谢,Ofer。

解决方案

IEnumerable 上的 Sum 是一个Extension方法,因此是 static 方法。



虽然有很多方法可以模拟静态方法 Moq 但由于它是构建的,因此无法(高效)围绕创建动态代理,这意味着它只能模拟虚拟或抽象方法。



希望这会有所帮助,

Fredrik


谢谢!我从中学到了。

imbaro。


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.

解决方案

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


Thanks! i learned from it.
imbaro.


这篇关于c#moq IEnumerable Sum。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆