When i try to fake a delegate-type, i get System.InvalidCastException

[TestMethod]
public void TestDelegateFake()
{
    var func = A.Fake<Func<long, object>>();

    A.CallTo(() => func(A<long>.Ignored))
        .Returns(new {});

    func(123);
}

How du i fake delegates?

有帮助吗?

解决方案

I think you have to specify the Invoke-method explicitly:

A.CallTo(() => func.Invoke(A<long>.Ignored)).Returns(new {});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top