Mocking indexer setters with Moq
I quite like MoQ because it makes sense for me. Shamefully, I’ve always had some trouble understanding test code that was using mocks built with other frameworks. With MoQ , I can just grok it for some reason. It’s just super-clear to me. It doesn’t mean I have any idea how it really works but for now I’m just happy with the magic. Anyway, yesterday I wanted to check that a controller action was setting some Application variable (let’s not get into the debate on whether or not it should do that at all). Something like this: application[ "foo" ] = new Foo (); Now how do I enable the object to be set by the tested code? Well, that one is easy, I can use SetupSet on indexers just fine: var mockHttpContext = new Mock < HttpContextBase
Read More...
Read the complete post at http://weblogs.asp.net/bleroy/archive/2009/06/15/mocking-indexer-setters-with-moq.aspx