Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 16, 2007 07:19 PM by JeremyS
Dec 15, 2007 03:18 PM|LINK
I think it would be useful if IHttpContext.Cache exposed an IHttpCache interface rather than a concrete Cache object. This would make unit testing code that interacts with the cache much easier.
Dec 15, 2007 07:38 PM|LINK
What are you trying to test and how do you intend to use it?
Dec 16, 2007 11:33 AM|LINK
I am trying to test an action that stores some data in the HttpContext.Cache. What I would like to be able to do is create a mock Cache object so that I can assert that the correct data has been stored.
My current solution is to create a wrapper object for the cache. While this works, it would be nice to see it in the framework by default, especially as other properties on httpcontext have been abstracted this way (Reques, Response, Session etc)
Dec 16, 2007 04:55 PM|LINK
Ah, I see +1 to an interface. Or at least make the default constructor of Cache new up an instance of one of the internal CacheInternal implementations so a simple call to new Cache() can actually be used.
Dec 16, 2007 06:27 PM|LINK
Dec 16, 2007 07:19 PM|LINK
...just hit: System.Web.HttpRuntime.Cache
Thanks - I'll use this approach in my tests for now. It seems cleaner than the wrapper object that I was using. The only caveat is having to explicitly remove all items from the cache in my test Setup method.
An interface would be better though ;)