Review: Eat Drink and Be Healthy

28 August 2007

I have a new review up of a book that I found to be quite good. You can find a review of Eat Drink and Be Healthy here. Want to learn more about eating well, with positive information on what you should be eating that people may not be telling you as well as information on bunk that is being handed out as truth? In my opinion, this book is worth your time.

Comments:4

Stick This In Your C# Code Toolkit: The Null Coalescing Operator

27 August 2007

Ran across a post today on the null coalescing operator in C#. I can honestly say that I've never seen this one before. If you're a C#-er, you might find it useful as well!

Comments:2

On Removing HttpContext Dependencies

23 August 2007

A faithful reader of the blog commented on my post the other day about using HttpRuntime vs HttpContext. Anderson's main point is absolutely right, and worth repeating. Here's what he said:


"You might consider refactoring your methods so that they don't have dependencies on context. If you have methods that depend on context to execute, you are not 'Unit' testing them, you are performing a functional test.
"It's a thin line and hard to keep straight, but basically your methods should be refactored to accept information that your presentation tier passes to them, rather than having them pull it straight out. Once you have done this, you can perform a "real" unit test that only tests that one unit of code, without dependencies on your presentation tier."

Having a dependency on the HttpContext in anything other than the UI makes the code much more difficult to test. There are ways of doing this by spinning up Cassini or even IIS in the background (ouch), but in general just keep HttpContext out of your BL and it will make testing a lot easier.

Of course there are two things I want to throw in here. First, we're doing this on an existing application. This is the second application I've worked on where we tried to retrofit the app for easy testing. At another job we failed to get adequate testing done on an application because of complete lack of support from upper management and whatnot. Fortunately at the current locale, we've got this being pushed by someone both smarter than me and with more clout than me, so we have a better chance of success :). Not only do we have HttpContext in our BL that we need to get out, we've got DL code in our UI code that bypasses the BL layer that we need to purge! If it was a new application, and we were building it for testability from the ground up, as I bet you know Anderson, it's a lot easier to build in looser coupling! It's refactor time...

Second, I would say that just about everything that you could get from HttpContext.Current via property should stop at the UI layer, with one exception: caching. It's made more sense to me to have the BL layer know caching and not the UI layer, so you need to be able to test the caching as a part of the BL testing. Even if one wants to make a strong distinction between "unit tests" and "functional tests", if you switch to HttpRuntime.Cache, you no longer have an external dependency (technically you do because it's in another dll, but you can depend on it being there, so it's not really a big dependency). In our case specifically (not to go into the details of how the guts of this application works), the BL has to know about the caching. So I think it makes sense here.
Comments:3

Real Technology Heroes

21 August 2007

It's sad, but I've met a number of these guys. I've even been some of them at one time :)

Real Technology Heroes

Thanks for the link, Robert!

Comments:2

HttpRuntime vs HttpContext

21 August 2007

Sometimes I find a discussion on something and I think to myself "you really need to blog this, because you may need to find it again some day and someone else might find it helpful." The adverse side effects of not doing this hit me the other day. I needed this little tidbit, but it took me a while to find it because I didn't blog it the last time I saw it! So here it is.

We're starting to put in some automated testing here at work (finally!), and we have some dependencies on elements in the Http world of ASP.NET. The problem when writing automated tests for web apps is that you do not have HttpContext.Current, which gives you access to some very important stuff, like HttpContext.Current.Request. Not surprisingly, that's not available during the execution of a unit test...because there is no web request!

The cache is one of the things that HttpContext.Current makes available. Fortunately, the cache can be used outside of an asp.net request by using HttpRuntime.Cache. Not only does this mean that you could write a winform app that uses the cache, but it also means that you can use it, and test it, in your automated tests.

The following is a short but significant discussion on the topic. If you're an ASP.NET guy, it is definitely worth your time reading it:

http://weblogs.asp.net/pjohnson/archive/2006/02/06/437559.aspx

Comments:1

Not A Broken Foot

20 August 2007

Good news for me! Late last week I had some new x-rays of my foot. As it turns out I don't have a broken foot at all, just soft-tissue damage. I was getting skeptical of the broken foot theory when I realized earlier in the week that I could put some weight on the foot. That seemed a little odd...

So now I've moved on to one crutch while putting some weight on my right foot. I can walk without a crutch, but it still hurts quite a bit. Thankfully, I can also drive. The movements needed for driving cause me no pain. I even made sure I could slam on the brakes if need be. No problem. The only negative in this is that I won't be able to work from home anymore :(

Comments:0

Rent-A-Crawler

15 August 2007

A few months ago I drastically changed how the urls on my site were built. I moved to using the ASP.NET 2.0 virtual path provider to make more friendly urls. Because I changed the "directory" structure, havoc was wreaked upon my unsuspecting relative urls. I had to go through my posts and look for bad links. I figured I might had missed some.

So I decided to write a crawler, to crawl my site and look for bad urls. And sure enough...I did miss some. Just in case you want to use it yourself, I have it available for download, along with some notes on how you implement a crawler in C#.

Enjoy!

Comments:0

Updates...

14 August 2007

Some of my very nice readers pointed out some issues in my rss feed. I've worked through some of those issues. First, my guids were messed up. Second, posts for my rss feed weren't showing up in Google reader. I re-downloaded RSS Bandit and they weren't showing up there either. They were in Sharpreader, the feedreader I use, so I didn't notice. Anyway, that's now fixed.

Also, I updated my reading list. Making progress on those books. Four for the month so far. Will this be my biggest reading month of the year? Given the pain caused by the Great Fall of 2007, and the time I now spend on my rump, this seems likely.

Comments:3

Ouch!

07 August 2007

That's sorta what I said the other night when I fell off a ladder (while painting) and cracked the bone in my right heel.

So now I'm on crutches. Most of the pain is gone, unless I try to stand with any weight whatsoever on my right leg. I don't. I also now own my very own pair of crutches. This is the first bone I have ever broken/cracked (that I know of...longer story). How are you guys doing? Broken any bones lately?

Two nice things have come out of this, however. First, there are all sorts of chores I don't have to deal with at the moment. Whoopee! Second, and more seriously, I've gotten quite a bit of reading done in the last few days. Reading is the only thing that this bone crack hasn't affected negatively so far.

I finished two books. First was Steven Krug's Don't Make Me Think. I liked it a lot. It gave me some really good ideas for, at the very least, improving this blog. I highly recommend it. The second was Goldsberry's The Writer's Book of Wisdom: 101 Rules for Mastering Your Craft. I enjoyed it and it seemed to have some good advice. I think this book is more directled at novelists than others, but to a very novice writer a lot of the advice made sense. If you've got a few extra bucks, go ahead and pick it up. It is pretty cheap and is a very fast read.

I bought a new book this last Friday called Lucifer's Hammer. I'm 437 pages out of 494 done. Great book so far. It is a fiction book, so if you need some fiction, pick it up. I got it for $10 at Half Price Books. Thanks for the recommendation, Edward!

Comments:0