I have the following:
public interface IAction
{
void Do(string a, int b = 0);
}
public class A : IAction
{
public void Do(string a, int b = 0)
{
// work is done
}
}
public class B
{
private readonly IAction _a;
public B(IAction a) //assume IOC is configured to inject an instance of B
{
_a = a;
}
//this is the method i want to test.
public void DoStuff(string arg)
{
//I am calling Do() with ONLY ONE parameter - because the other is optional
_a.Do(arg);
//do something else - optional
}
}
And my test looks something like this:
[TestClass]
public class BTest
{
[TestMethod]
public void DoStuffShouldBlablaForValidInput()
{
Mock<IAction> _mockedB = new Mock<IAction>(MockBehavior.Strict);
var b = new B(_mockedB.Object);
_mockedB .Setup(x => x.Do(It.IsAny<string())).Verifiable();
b.DoStuff("sample");
// verify that Do() was called once
_mockedB.Verify(x => x.Do(It.IsAny<string()), Times.Once);
}
}
But I'm getting: "An expression cannot contain a call or invocation that uses optional argument" error on this line"_mockedB .Setup(x => x.Do(It.Any x.Do(It.IsAny
How do i fix this without requiring method DoStuff() to pass the optional parameter as well for method Do()?
Thanks,