I am trying to mock this interface:
public interface IManager
{
TVal GetOrAdd<TVal, TArg>(string key, Func<TArg, TVal> valueFactory, TArg valueFactoryArg) where TVal : class;
}
And i am having isuse to mock the lambda expression.
var _menagerMock = new Mock<IManager>();
_menagerMock.Setup(x => x.GetOrAdd<string, Tuple<int>>("stringValue",
It.IsAny<Func<Tuple<int>,string>>, It.IsAny<Tuple<int>>);
the It.IsAny< Func,string>> is not passing compilation, and the error is: Expected a method with 'string IsAny(Tuple)' signature.
Is it possible to mock this kind of function?
Try:
var _menagerMock = new Mock<IManager>();
_menagerMock.Setup(x => x.GetOrAdd("stringValue",
It.IsAny<Func<Tuple<int>, string>>(), It.IsAny<Tuple<int>>()));
Edit: As an aside, It.IsAny() is not a best practice for testing. You should be setting up explicit values instead of relying on It.IsAny(). If you're not really sure of the inputs in your tests, how can you be sure that you're getting valid output?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With