returns 属性的模拟方法

Mocking method that returns properties

我将如何在 returns 属性列表的方法上模拟 属性。

public class Data
{
  public string Property1 {get: set;}
  public string Property2 {get: set;}
  public string Property3 {get: set;}
}

public Data GetData(bool paramVal){
  Data myData = new Data();

  myData.Property1 = "Value1",
  myData.Property2 = "Value2",
  myData.Property3 = "Value3"

  return myData
}

如何在此方法上设置我的模拟,以便我可以在属性中设置值?

我尝试了什么:

MyDataBo = new Mock<IDataBo>`(); //(this is injected into my test class as a dependency)

MyDataBo.Setup(x => x.GetData(It.IsAny<bool>()).Property1).Returns("Value");`

它可以编译,但在调试我的测试时出现错误:

System.NotSupportedException: Unsupported express...

如何模拟 Property1 或所有属性?

在这种情况下需要 Data class 的实际实例。

Data myFakeData = new Data() {
    Property1 = "Value1",
    Property2 = "Value2",
    Property3 = "Value3"
};

var MyDataBo = new Mock<IDataBo>();

MyDataBo
    .Setup(_ => _.GetData(It.IsAny<bool>()))
    .Returns(myFakeData);

并且在调用模拟成员时将模拟设置为 return 假数据。