How do I Moq a method that has an optional argument in its signature without explicitly specifying it or using an overload?

前端 未结 3 1491
闹比i
闹比i 2020-12-01 10:08

Given the following interface:

public interface IFoo
{
    bool Foo(string a, bool b = false);
}

Attempting to mock it using Moq:



        
3条回答
  •  Happy的楠姐
    2020-12-01 10:28

    Using Moq version 4.10.1 I have been able to do the following

    With Interface:

    public interface IFoo
    {
        bool Foo(string a, bool b = false);
    }
    

    And Mock

    var mock = new Mock();
    mock.Setup(mock => mock.Foo(It.IsAny(), It.IsAny())).Returns(false);
    

    Resolves a call to Foo with the first parameter okay

提交回复
热议问题