本文介绍了如何伪造多个接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现多个接口的类,如何使用Fakes生成该类的存根?在Rhino Mocks中,我们可以这样:

I have a class which implements multiple interfaces, how to use Fakes to generate the stubs for this class? In Rhino Mocks, we can do like this:

var mock = MockRepository.GenerateMock<IFirst, ISecond>(); mock.Stub(m => m.FirstProperty).PropertyBehavior(); ((ISecond)mock).Stub(k=> k.SecondProperty).PropertyBehavior();


推荐答案

对于引用的程序集中的每个接口,Microsoft Fakes机制都会生成一个存根类,因此我的理解是我们将使用不同的存根类.

For every interface in the referenced assembly, the Microsoft Fakes mechanism generates a stub class, so my understanding is that we would use different stub class.

https://msdn.microsoft.com/en-us/library/hh549174.aspx #BKMK_Stub_basics

其他测试方法似乎有不同的解决方案:

It seems that other test methods have different solutions:

http://www.richard-banks.org/2010 /08/mocking-comparison-part-11-multiple.html

最好的问候,

Jack


这篇关于如何伪造多个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 18:53