whebz
whebz

Reputation: 121

How to mock in Moq Func<object, Class> Property { get; }

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

Answers (1)

Nkosi
Nkosi

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

Related Questions