为什么默认情况下,moq不设置所有属性? [英] Why doesn't moq setup all properties by default?

查看:85
本文介绍了为什么默认情况下,moq不设置所有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在Moq中,需要先设置属性,然后才能分配值.我的问题是为什么为什么Moq不能只允许您默认设置属性,而不必设置"它们.

I understand that in Moq, you need to set up properties before you can assign values. My question is why doesn't Moq just allow you to set properties by default without having to "set" them up.

推荐答案

对于开发人员来说,这是一个问题.然后,您可以查看快速入门,看看它是否有助于回答您的问题.

That is a question for the developer. Till then you can take a look at the Quickstart and see if it helps answer your question.

mock.SetupAllProperties();会将模拟的所有属性存根.

mock.SetupAllProperties(); which stubs all properties on a mock.

我的猜测是,并不是所有的模拟都拥有属性,因此使框架尝试查找和设置属性不会构成有效的API.如果需要的话,选择启用该选项似乎是一种最佳方法.

My guess would be that not all mocks would possess properties so making the framework attempt to look up and setup properties would not make for an efficient API. the opt-in option of setting it up if needed seems like an optimal approach.

这篇关于为什么默认情况下,moq不设置所有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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