Moq an indexed property and use the index value in the return/callback
问题 I want to moq a property that has an index, and I want to be able to use the index values in the callback, the same way you can use method arguments in the callback for moq'd methods. Probably easiest to demonstrate with an example: public interface IToMoq { int Add(int x, int y); int this[int x] { get; set; } } Action<int, int> DoSet = (int x, int y) => { Console.WriteLine("setting this[{0}] = {1}", x, y); throw new Exception("Do I ever get called?"); }; var mock = new Mock<IToMoq>