TDD: I am finally getting it

My friend Mark and I have talked a lot in the past about doing more at unit testing. That's something I've really been focusing on lately and one of the things that has come out of it is that code written for unit tests is subtly different than code not. This became crystal clear to me just a moment ago as I was writing this code:

http://pastie.org/322821

The first way I wrote it was a somewhat untestable way of doing things: in order to test AllowPost my unit test had to know all about our configuration stuff and it just couldn't easily be tested without a bunch of dependencies. Of course, my unit test framework doesn't know about those dependencies without making it jump through a whole bunch of hoops. By re-writing it the second way, the method AllowPost was an atomic unit that could be tested without knowing about the other stuff.

Of course, I want some tests that cover "the other stuff", but that's at a higher level. First, I have to get the lowest levels of tests working before the higher level tests will, otherwise it's all spaghetti.

This may all be old news to you, but for me it really drove home the phrase "test-driven development"...in other words, the tests are actually shaping the code. Suddenly, it makes so much sense why, in order for TDD to be effective, you have to write the tests first. Otherwise, you may end up with code that isn't testable in terms of a unit test framework.