Creating a System.Web.Caching.Cache object in a unit test

后端 未结 4 1501
青春惊慌失措
青春惊慌失措 2021-02-15 01:49

I\'m trying to implement a unit test for a function in a project that doesn\'t have unit tests and this function requires a System.Web.Caching.Cache object as a parameter. I\'ve

4条回答
  •  没有蜡笔的小新
    2021-02-15 02:02

    A very useful tool for unit testing legacy code is TypeMock Isolator. It'll allow you to bypass the cache object entirely by telling it to mock that class and any method calls you find problematic. Unlike other mock frameworks, TypeMock uses reflection to intercept those method calls you tell it to mock for you so you don't have to deal with cumbersome wrappers.

    TypeMock is a commercial product, but it has free versions for open-source projects. They used to have a "community" edition that was a single-user license but I don't know if that's still offered.

提交回复
热议问题