Setup()与SetupGet() [英] Setup() vs SetupGet()

查看:113
本文介绍了Setup()与SetupGet()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MOQ的SetupGet()和Setup()方法之间有什么区别?

What is the difference between the SetupGet() and Setup() methods for MOQ?

推荐答案

Setup()可用于模拟方法或属性.

Setup() can be used for mocking a method or a property.

SetupGet()专用于模拟属性的getter.快速浏览Moq源代码,看起来如果您在属性getter上使用Setup(),它将调用SetupGet().因此,在那种情况下,您是否更明确地使用SetupGet()而不是Setup()可能是更个人的偏爱.

SetupGet() is specifically for mocking the getter of a property. Took a quick peek at the Moq source code and it looks like if you use Setup() on a property getter, it will call SetupGet(). So in that case, it is probably more personal preference as to whether you want to be more explicit and use SetupGet() instead of Setup().

当然,我对Moq的了解是有限的,所以我不知道是否有特殊情况需要在Setup()上使用SetupGet().

Of course, my knowledge of Moq is limited, so I don't know if there special cases where you would need to use SetupGet() over Setup().

这篇关于Setup()与SetupGet()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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