views:

61

answers:

1

I'm currently working on a large scale ASP.NET MVC application and one area where testing is failing is around things that we're storing in session. My first pass at abstracting session is just to create a very simple static class and make all calls to session go through that. So I might have something like this:

public static class AppSession {
    public string CurrentLanguage {
        get { return HttpContext.Current.Session["CurrentLanguage"]; }
        set { HttpContext.Current.Session["CurrentLanguage"] = value; }
    }
}

Then in my controllers actions I can call AppSession.CurrentLanguage = "en-US" and I don't have to think about session. The problem is that when I go to test a controller action that uses this static class I get an obvious exception...session state doesn't really exist.

Now I can mock out calls to HttpContext.Current.Session in my tests, what I can't mock out is calls to AppSession...any ideas on how I might get around this?

A: 

Please see this duplicate question

Nebakanezer