Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:21:15+00:00 2026-05-26T09:21:15+00:00

Scenario We’re developing a new MVC web project and we’re trying to adhere to

  • 0

Scenario

We’re developing a new MVC web project and we’re trying to adhere to the Skinny Controller pattern as described in this article http://codebetter.com/iancooper/2008/12/03/the-fat-controller/

As part of one of our actions we are retrieving some navigation data (Menu structure) from the Cache.

Problem

I order to maintain the skinny controller pattern we’d like to have the cache check call in the ViewModel, which we have tried and we know works, using the following code.

var cachedCategories = (List<Category>)HttpContext.Current.Cache["Categories"];
if (cachedCategories == null) {
       cachedCategories = _service.GetCategories().ToList<Category>();
       HttpContext.Current.Cache["Categories"] = cachedCategories;
}

However when it comes to unit testing it we hit a problem. Since we are not directly passing the HttpContext into the ViewModel we have no idea how to go about mocking the HttpContext.

We’re using Moq and while we have some options (one is to pass the context from the controller to the viewmodel at instantiation) those options require changing the code purely to make the tests work.

Does anyone have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:21:16+00:00Added an answer on May 26, 2026 at 9:21 am

    Ultimately we choose to modify our code to allow for easier testing.

    We accomplished this by passing the HttpContext to the ViewModel at instantiation as I mentioned in my original question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario : I'm currently trying to build a poor man's Google Maps using scripts
Scenario: I am working on a Android project where in one particular openGL page,
Scenario: Storyboard with UINavigationController as initial controller. MainVC (navigation controller's root vc) needs the
Scenario : I have an ASP.NET MVC application developed in Visual Studio 2008. There
Scenario: ASP.NET web site Global static classes containing TONS of configuration data the static
Scenario: A web site with x number of pages is being served with a
Scenario 1 (That Works) This is a POC i created. I have a script
Scenario I was reviewing one of my devs HTML structure for a project and
Scenario I have an web application which needs some calculations and processing on data.
Scenario Route: /template/customize/10 Where: 10 = ID of Template() In the controller the model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.