C# 使用MOQ获取属性失败,表达式不受支持(不可重写成员)

C# 使用MOQ获取属性失败,表达式不受支持(不可重写成员),c#,unit-testing,moq,C#,Unit Testing,Moq,我有一行这样的代码: foo = _testOutputService.SelectedPoint.PointType; mockTestOutputService.Setup(x => x.SelectedPoint).Returns(mockSelectedPoint.Object); 我的测试尝试获取第一个参数,如下所示: foo = _testOutputService.SelectedPoint.PointType; mockTestOutputService.Setu

我有一行这样的代码:

 foo = _testOutputService.SelectedPoint.PointType;
mockTestOutputService.Setup(x => x.SelectedPoint).Returns(mockSelectedPoint.Object);
我的测试尝试获取第一个参数,如下所示:

 foo = _testOutputService.SelectedPoint.PointType;
mockTestOutputService.Setup(x => x.SelectedPoint).Returns(mockSelectedPoint.Object);
但是我得到了不支持的表达式x=>x.SelectedPoint不可重写的成员

有什么建议吗


谢谢

该错误意味着
SelectedPoint
不是
TestOutputService
上的虚拟方法,您应该模拟该类接口或使该方法在具体类上虚拟。如前一评论所述,该错误通常与尝试设置非虚拟(可重写)成员相关。你能给出你帖子中显示的成员的定义吗?