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

后端 未结 4 1429
青春惊慌失措
青春惊慌失措 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:11

    var httpResponse = MockRepository.GenerateMock();
    var cache = MockRepository.GenerateMock();
       cache.Stub(x => x.SetOmitVaryStar(true));
       httpResponse.Stub(x => x.Cache).Return(cache);
       httpContext.Stub(x => x.Response).Return(httpResponse);
       httpContext.Response.Stub(x => x.Cache).Return(cache);
    

提交回复
热议问题