Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fake delegates with FakeItEasy

Tags:

fakeiteasy

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?

like image 712
Jesper Jensen Avatar asked Jul 17 '12 08:07

Jesper Jensen


1 Answers

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

A.CallTo(() => func.Invoke(A<long>.Ignored)).Returns(new {});
like image 144
Patrik Hägne Avatar answered Sep 21 '22 11:09

Patrik Hägne