Asp.net MVC Session State Extension Method

There are a few implementations of the conical wizard out there using Asp.net MVC.  I’m working on a project where we are needing one such wizard and we’re trying out using session state, not session skate, to keep the models that make up the larger data set persisted for the user until the final submission.Sessions

This will allow the user to go back to any of the stages and edit the information if needed.  There are are options but for now we’re testing driving this approach.

Inspired (dang near a complete duplicate) by Donn Felker’s ASP.NET MVC TempData Extension Methods I created one that uses HttpSessionStateBase.

    public static class SessionStateExtensions
    {
        public static void Put<T>(this HttpSessionStateBase httpSession, T value) where T : class
        {
            httpSession[typeof (T).FullName] = value;
        }

        public static void Put<T>(this HttpSessionStateBase httpSession, string key, T value) where T : class
        {
            httpSession[typeof (T).FullName + key] = value;
        }

        public static T Get<T>(this HttpSessionStateBase httpSession) where T : class
        {
            var o = (T) httpSession[typeof (T).FullName];
            return o == null ? null : o;
        }

        public static T Get<T>(this HttpSessionStateBase httpSession, string key) where T : class
        {
            var o = (T) httpSession[typeof (T).FullName + key];
            return o == null ? null : o;
        }
    }
Tagged with:
 

Unit Testing, Just Do It!

I used to be the ConsoleApplication132 type of developer and no big surprise my projects didn’t have any unit tests in them, if any at all.  To try and remedy this I took a 3 week TestProject1 challenge.  Instead of doing quick spikes to a .NET console application to ‘try something out’ I spun up a Test Project.

bell So where am I now?  Well my stuff has tests, but I’m in some bell curve of using Mocks improperly and over specifying my tests.  I really like the naming style of BDD but flirted around with class name test method convention is about as deep as I have got into that realm so far.

… to be continued … over many years, I’m sure …