我可以“继承”吗?代表?寻找将 Moq 和 MSpec 结合起来而不发生冲突的方法
我已经开始使用 MSpec 进行 BDD,并且很久以前我就使用 Moq 作为我的模拟框架。但是,它们都定义了 It
,这意味着我不能在同一个代码文件中使用 using Moq
和 using Machine.Specifications
,而无需每次使用 It
时都显式指定名称空间。任何使用过 MSpec 的人都知道这并不是一个真正的选择。
我在谷歌上搜索了这个问题的解决方案,这位博主提到为自己分叉了 MSpec,并实现了 paralell支持Given
、When
、Then
。
我想这样做,但我不知道如何声明 Given
,而不必遍历整个框架寻找对 Establish
的引用,并且更改那里的代码以匹配我想要的任何一个都可以。
作为参考,Establish
、Because
和 It
的声明方式如下:
public delegate void Establish();
public delegate void Because();
public delegate void It();
我需要的是以某种方式声明 Given,这样代码到处都会寻找
Establish
,Given
也可以。
I have started to use MSpec for BDD, and since long ago I use Moq as my mocking framework. However, they both define It
, which means I can't have using Moq
and using Machine.Specifications
in the same code file without having to specify the namespace explicitly each time I use It
. Anyone who's used MSpec knows this isn't really an option.
I googled for solutions to this problem, and this blogger mentions having forked MSpec for himself, and implemented paralell support for Given
, When
, Then
.
I'd like to do this, but I can't figure out how to declare for example Given
without having to go through the entire framework looking for references to Establish
, and changing code there to match that I want either to be OK.
For reference, the Establish
, Because
and It
are declared in the following way:
public delegate void Establish();
public delegate void Because();
public delegate void It();
What I need is to somehow declare Given
, so that everywhere the code looks for an Establish
, Given
is also OK.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用“using”作为类型名称的别名,而不是使用完全限定的类型名称来克服冲突,例如:
然后您可以使用 MadeUpName 而不发生冲突。
Rather than using fully qualified type names to overcome the clash, you could use "using" to alias the type names, e.g.:
You can then use MadeUpName without the clash.