gpt4 book ai didi

c# - CallBaseMethod () 是否适用于 FakeItEasy 中的虚拟属性?

转载 作者:行者123 更新时间:2023-11-30 17:51:59 25 4
gpt4 key购买 nike

我有简单的类(class)

public class Simple
{
public virtual int VirtualProperty { get; set; }
}

当我运行 (FakeItEasy.1.13.1)

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(() => strict.VirtualProperty).CallsBaseMethod();
strict.VirtualProperty = 999;

我得到一个错误

Call to non configured method "set_VirtualProperty" of strict fake.

我必须

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(strict).Where(a => a.Method.Name == "get_VirtualProperty").CallsBaseMethod();
A.CallTo(strict).Where(a => a.Method.Name == "set_VirtualProperty").CallsBaseMethod();
strict.VirtualProperty = 999;

CallBaseMethod() 是否适用于虚拟属性(property)?我做错了什么?

最佳答案

更新:自 2.0.0 发布以来,有一个 more convenient way to configure a property setter in some cases .

随着在 FakeItEasy Issue 175 上的更多光照,很明显,真正的障碍是 A.CallTo(() => strict.VirtualProperty).CallsBaseMethod() 配置属性 getter,而不是 setter。配置完成后,对 strict.VirtualProperty 进行的 get 调用将调用基本方法(属性)。

但是,没有方便的方法来配置属性 setter。您的解决方法已经差不多了。

关于c# - CallBaseMethod () 是否适用于 FakeItEasy 中的虚拟属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18757960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com