我可以“继承”吗?代表?寻找将 Moq 和 MSpec 结合起来而不发生冲突的方法

发布于 2024-09-02 08:45:34 字数 927 浏览 10 评论 0原文

我已经开始使用 MSpec 进行 BDD,并且很久以前我就使用 Moq 作为我的模拟框架。但是,它们都定义了 It,这意味着我不能在同一个代码文件中使用 using Moqusing Machine.Specifications,而无需每次使用 It 时都显式指定名称空间。任何使用过 MSpec 的人都知道这并不是一个真正的选择。

我在谷歌上搜索了这个问题的解决方案,这位博主提到为自己分叉了 MSpec,并实现了 paralell支持GivenWhenThen

我想这样做,但我不知道如何声明 Given ,而不必遍历整个框架寻找对 Establish 的引用,并且更改那里的代码以匹配我想要的任何一个都可以。

作为参考,EstablishBecauseIt 的声明方式如下:

public delegate void Establish();
public delegate void Because();
public delegate void It();

我需要的是以某种方式声明 Given,这样代码到处都会寻找 EstablishGiven 也可以。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2024-09-09 08:45:35

您可以使用“using”作为类型名称的别名,而不是使用完全限定的类型名称来克服冲突,例如:

using MadeUpName = System.Windows.Forms.SomeClass;

然后您可以使用 MadeUpName 而不发生冲突。

MadeUpName obj = new MadeUpName();

Rather than using fully qualified type names to overcome the clash, you could use "using" to alias the type names, e.g.:

using MadeUpName = System.Windows.Forms.SomeClass;

You can then use MadeUpName without the clash.

MadeUpName obj = new MadeUpName();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文