Reputation: 121
I am stuck with mocking problem using Moq.
How do I mock this property?
public interface ICommand {
Func<object, Document> GetDocument { get; }
}
Upvotes: 2
Views: 437
Reputation: 247641
How do I mock this property?
By using an actual Function
Given
public interface ICommand {
Func<object, Document> GetDocument { get; }
}
Use an actual function in the test and return that from the mocked interface
var mock = new Mock<ICommand>();
Func<object, Document> function = (object arg) => {
//...code to return a document
};
mock.Setup(_ => _.GetDocument).Returns(function);
Reference Moq Quickstart to get a better understanding of how to use the mocking framework.
Upvotes: 2