This is a follow-up on that other post: Mocking indexer setters with Moq . So thanks to that post, we now know how to intercept the setting of a particular indexed property (in our example, an application variable) and set a local variable with the value that was set by the tested code. Now if you want the application to return that same value when queried by the tested code, you also need to mock the indexer getter. This operation is also not entirely trivial. Here?s how you do it: you do a SetupGet chained with a Returns with a lambda expression as the parameter: mockHttpContext .SetupGet(c => c.Application[ "foo " ]) .Returns(() => ( object )map); That last point about using a lambda is pretty important. If you just use map...(read more) ...
Go to the complete details ...