I have been trying to use Moq to fake an object set (and get) with multiple indexers. I have previously been using Moq with single indexers for quite some time, but it doesn't seem to be working using multiple indexers. I am aware from my research that Moq can have a problem using It.IsAny<> for indexer parameters, but I have also tried the following code with specific parameters (like mock[1, "BlockItem"]) Here is my code:
m_storageAccessor.SetupSet(
mock => mock[It.IsAny<int>(), It.IsAny<string>()] = It.IsAny<object>()).Callback(
(int i, string s, object o) =>
{
m_storageAccessor.SetupGet(
mock => mock[i, s]).Returns(
() => { return o; });
});
This generates the following exception, again, no matter what parameters I give the indexer function in SetupSet().
Initialization method UnitTest.BonusHandlerTest.MyTestInitialize threw exception. System.ArgumentNullException: System.ArgumentNullException: Value cannot be null. Parameter name: arguments.
System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodInfo method, ReadOnlyCollection
1& arguments) System.Linq.Expressions.Expression.ValidateCallArgs(Expression instance, MethodInfo method, ReadOnlyCollection1& arguments) System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable1 arguments) System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments) TCall](Mock1 mock, Action1 setterExpression, Func5 callFactory) b__25() Moq.PexProtector.Invoke[T](Func1 function) Moq.Mock.SetupSet[T](Mock1 mock, Action1 setterExpression, Func1 condition) SetupSet(Action`1 setterExpression) UnitTest.BonusHandlerTest.SetupPersistence() in C:\perforce\dev\KHIRST_Client12.BonusHandler\Client12\Gaming\BonusHandler\UnitTest\BonusHandlerTest.cs: line 868 UnitTest.BonusHandlerTest.MyTestInitialize() in C:\perforce\dev\KHIRST_Client12.BonusHandler\Client12\Gaming\BonusHandler\UnitTest\BonusHandlerTest.cs: line 100
It almost seems like, based on what I have tried, that Moq is unable to do indexers with multiple parameters. Anyone have any ideas? The interwebs haven't been much help.