且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换实现接口并从基类继承的声明类型的 C# 方法

更新时间:2022-03-09 01:55:45

您所问的实际上是 typemock 中的一项功能,这是一个单元测试框架,允许您通过简单的一行代码将模拟方法的实现更改为另一个代码,例如:

What you are asking is actually a feature in typemock a unit testing framework that allows you to change the implementation of a mocked method to another one in a simple line of code, for example:

[TestMethod]
public void TestMethod1()
{
    var real = new Foo();

    Isolate.WhenCalled(() => real.Apple()).DoInstead(x => { return real.Orange(); });

    Assert.AreEqual("Orange", real.Apple());
}

您可以在此处了解有关此功能的更多信息.