Telerik JustMock
When you isolate your test case from a call to a delegate, a common requirement is that the delegate returns a predefined value.
public class Foo
{
public Func<int, int> FuncDelegate { get; set; }
public int GetInteger(int toThisInt)
{
return FuncDelegate(toThisInt);
}
}
...
[TestMethod]
public void ShouldArrangeReturnExpectation()
{
// ARRANGE
// Creating a mock instance of the Func<int, int> delegate.
var delegateMock = Mock.Create<Func<int, int>>();
// Arranging: When the mock is called with 10 as an integer argument,
// it should return 20.
Mock.Arrange(() => delegateMock(10)).Returns(20);
// ACT
var foo = new Foo();
// Assigning the mock to the dependent property.
foo.FuncDelegate = delegateMock;
var actual = foo.GetInteger(10);
// ASSERT
Assert.AreEqual(20, actual);
}