Setup() vs SetupGet()

折月煮酒 提交于 2019-12-08 23:16:09

问题


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


回答1:


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

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().

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().




回答2:


SetupGet works when you're trying to mock read only property



来源:https://stackoverflow.com/questions/5767640/setup-vs-setupget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!