March 2008 - Posts

The Indy Code Camp's schedule was just published. If you were waiting to register until you could see what kind of content would be available, now is the time! We have 24 sessions with a wide range of topics. It should be a great day! I'm very pleased with the turn out of presenters and topics. When I started thinking about the code camp a while ago, I thought a good event would include six sessions - let's just say my expectations have been exceeded yet again.

We've got room for a maximum of 250 people, and I can tell you that the registration list is filling up - so hurry up and register if you are even thinking about coming.

I'm also working to organize a fairly informal "after party" at the local sports bar - leave a comment here if you would be interested in coming. I need to gauge a general interest level. :)

See you there!

About a month and a half ago Ben Scheirman wrote about testing TempData in ASP.NET MVC. It's good stuff, and aside from changes between Preview 1 and Preview 2, it still works fine. (See Scott Hanselman's post for some Preview 2-friendly mock helpers using Rhino Mocks.)

While I can easily understand what Ben's code is doing, what I couldn't figure out is why it worked. If you reflect over TempDataDictionary (the type of the Controller.TempData property), you'll see that the data type it persists to the session is an internal structure.

Ben's code, however, mocks out the Session to return the expected TempDataDictionary object. By all counts, that should fail, since the TempDataDictionary won't be getting back the values it expects--it expects the internal map structure.

Well, it turns out I was glossing over one very important fact. TempDataDictionary was written to be smart enough that if the underlying session store either didn't work, or didn't provide the right data, TempData will continue to operate as normal--for the current request only. You can see below that if the session data was null or wasn't the right type, it just creates a new internal map.


(image cut off for space)

One of the benefits of TempData is the cross-request persistence via the session. You might not have known it, but when you call RedirectToAction in your controller action, for example, it's actually resulting in a 300-level HTTP redirect, which means an entirely new HttpContext for the next request. It's basically deferring to the browser to perform the redirect.

So, while Ben's code will definitely work, here's an extension method that can help with mocking out the session a little more "correctly":

public static void NullifySessionState(this HttpSessionStateBase session)
{
    SetupResult.For(session[null]).IgnoreArguments().Return(null);
    session[null] = null;
    LastCall.IgnoreArguments();
}

Administrative note: I used to maintain two RSS feeds. One for weblogs.asp.net/aaronlerch, and the other for www.aaronlerch.com/blog. I've decided that's dumb, as the content between the two is nearly exactly the same. So, if you subscribe to my weblogs.asp.net feed, it should be automatically redirected, at which point it'll be like you subscribed to my main site. Again, the content is the same, just a little more of it (a very little more).

Hopefully you have no interruptions--but if you do, let me know in the comments here. If you really really care, for some weird reason, and want them separate (and have a good reason), let me know that too.

Cordially,
The Management 

Tim Heuer announced today the release of "S3 Browser", a plug-in for Windows Live Writer that enables easy inserting of links or images from your S3 storage. See his announcement on his blog, and on the Code Trip's blog.

Like Tim, I've been using S3 to host my images for the blog, and I wholeheartedly agree with him - the workflow for writing a post sucked big time. This plug-in had been on my //TODO list for a long while now. Somehow I mentioned that fact to Tim on Twitter and he sent me a link to a screenshot of his initial version. My response? Sign me up!

He uploaded his source to CodePlex and I immediately started implementing the remaining features. The result is the 0.9 beta release of the S3 Browser Windows Live Writer plug-in. Give it a download and try it out! Please submit any feature ideas or bugs on the codeplex site, or you can leave a comment here as well.

Posted Tuesday, March 11, 2008 1:25 AM by alerch | with no comments
Filed under:
More Posts