Using Moq to Mock a Func<> constructor parameter and Verify it was called twice

前端 未结 3 592
萌比男神i
萌比男神i 2021-01-03 18:59

Taken the question from this article (How to moq a Func) and adapted it as the answer is not correct.

public class FooBar
{
    private Func

        
3条回答
  •  Happy的楠姐
    2021-01-03 19:29

    As of at least Moq 4.5.28, you can mock and verify the Func as you would expect to be able to. I couldn't tell when this feature was added (according to the original question at some point this did not work).

    [Test]
    public void TestFoobar()
    {
        var funcMock = new Mock>();
        var fooBar = new FooBar(funcMock.Object);
        fooBar.Process();
        funcMock.Verify(x => x(), Times.AtLeast(2));
    }
    

提交回复
热议问题