Given the following interface:
public interface IFoo { bool Foo(string a, bool b = false); }
Trying to mock him with Moq:
var mock = new Mock<IFoo>(); mock.Setup(mock => mock.Foo(It.IsAny<string>())).Returns(false);
gives the following error at compile time:
The expression tree may not contain a call or a call that uses optional arguments
I found the problem above, raised as an improvement in the Moq error list, and it seems to have been assigned to version 4.5 (whenever possible).
My question is: what should I do, given that the foregoing will not be fixed in the near future? Are my options just to either explicitly set a default value for an optional parameter every time I scoff at it (what kind of point the point wins first), or to create an overload without a bool (for example, what would I do to C # 4)?
Or can someone find a smarter way to overcome this problem?
c # unit-testing moq
Appulus Oct. 18 '12 at 14:53 2012-10-18 14:53
source share