我陷入了使用 Moq 的模拟问题。
我如何模拟这个属性?
public interface ICommand {
Func<object, Document> GetDocument { get; }
}
最佳答案
How do I mock this property?
通过使用实际函数
给定
public interface ICommand {
Func<object, Document> GetDocument { get; }
}
在测试中使用实际函数并从模拟接口(interface)返回该函数
var mock = new Mock<ICommand>();
Func<object, Document> function = (object arg) => {
//...code to return a document
};
mock.Setup(_ => _.GetDocument).Returns(function);
引用Moq Quickstart更好地了解如何使用模拟框架。
关于c# - 如何在 Moq Func<object, Class> Property { get; 中进行模拟},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49048588/