C# 在C中使用MoQ设置只读属性#

C# 在C中使用MoQ设置只读属性#,c#,unit-testing,moq,C#,Unit Testing,Moq,我试图模拟一个只读属性 Main.cs public class Claim : ProcessBase { public IEnumerable<Cat> Retrieve() { if(Ph2.IsEnabled){} } } Ph2.cs public class Ph2: AppFeature { public const string key = "PhaseTwo"; } IAppFeature.cs public interfa

我试图模拟一个只读属性

Main.cs

public class Claim : ProcessBase
{
 public IEnumerable<Cat> Retrieve()
 {
  if(Ph2.IsEnabled){}
 }
}
Ph2.cs

public class Ph2: AppFeature
{
    public const string key = "PhaseTwo";
}
IAppFeature.cs

public interface IAppFeature
{
    bool IsEnabled { get; }

}


public abstract class AppFeature : IAppFeature
{
    public bool IsEnabled
    {
        get { return 
  FeatureToggleProcess.RetrieveValue(this.GetType().Name); }
    }

 }
我正在编写一个单元测试方法来测试Main.cs的检索方法,但我无法模拟Ph2。 我正在使用这个作为参考,但仍然无法做到

Test.cs

 Mock<IAppFeature> _mockAppFeature;
 Mock<BritsPhaseTwoFeature> _mockPh2;
 [TestInitialize]
    public void Initialize()
    {
        _mockAppFeature = new Mock<IAppFeature>();
        _mockPh2 = new Mock<Ph2>();
        Ph2 ph2 = new Ph2();
        _mockPh2.SetupGet(x => x.IsEnabled).Returns(true); ---> Error here
        _mockAppFeature.Setup(o => o.IsEnabled).Returns(britsPhaseTwoFeature.IsEnabled);
    }
Mock\u mockAppFeature;
mocku mockPh2;
[测试初始化]
公共无效初始化()
{
_mockAppFeature=新建Mock();
_mockPh2=新Mock();
Ph2 Ph2=新的Ph2();
_mockPh2.SetupGet(x=>x.IsEnabled)。返回(true);-->Error here
_mockAppFeature.Setup(o=>o.IsEnabled).Returns(britspasetwofeature.IsEnabled);
}
在非虚拟(在VB中可重写)成员上设置无效时出错:x=>x.IsEnabled

这是一个旧的生产代码,所以不知道如何更改它以产生最小的影响。
非常感谢您提供的任何帮助。

能否显示
IAppFeature
?编辑了我的问题并添加了IAppFeature。这似乎是一个。没有解决方案吗?
 Mock<IAppFeature> _mockAppFeature;
 Mock<BritsPhaseTwoFeature> _mockPh2;
 [TestInitialize]
    public void Initialize()
    {
        _mockAppFeature = new Mock<IAppFeature>();
        _mockPh2 = new Mock<Ph2>();
        Ph2 ph2 = new Ph2();
        _mockPh2.SetupGet(x => x.IsEnabled).Returns(true); ---> Error here
        _mockAppFeature.Setup(o => o.IsEnabled).Returns(britsPhaseTwoFeature.IsEnabled);
    }