New to ASP.NET MVC? Test-Drive Your Way
New to ASP.NET MVC? Test-Drive Your Way
Join the DZone community and get the full member experience.Join For Free
The Agile Zone is brought to you in partnership with Techtown Training. Learn how DevOps and SAFe® can be used either separately or in unison as a way to make your organization more efficient, more effective, and more successful in our SAFe® vs DevOps eBook.
Short version: Jonathan McCracken has produced a great guided tour of ASP.NET MVC 2, meaning if you’re trying to figure out what everybody’s getting so amped up about (as opposed to traditional page-oriented ASP.NET), then Test-Drive ASP.NET MVC is a great way to understand the excitement.
I first met Jon when I was out in Bangalore, India, doing some consulting work for ThoughtWorks (my employer at the time). Jon was out in Bangalore working as an instructor for ThoughtWorks University, and we got to talking about the .NET community and specifically, how he could grow as a recognizable speaker and pontificator within that community. He’d had this idea, you see, for a book on ASP.NET MVC, and was thinking about pitching it to publishers. I suggested that he talk to the Pragmatic Bookshelf, and he agreed whole-heartedly—in fact, he was hoping to pitch it to them. We talked a bit about the process of writing a book, the pains involved and the total lack of fiscal incentive to do so, and despite all that, he still went ahead with the idea.
Time passed, as time has a way of doing, and I left ThoughtWorks. Jon and I kept in sporadic touch after that, but not much about writing or books. Until a few months ago, when a copy of Test-Drive ASP.NET MVC showed up at my door, and an email from Jon saying, “It’s done!” appeared in my Inbox shortly thereafter.
Bear in mind, I’m not much of a front-end guy anymore—quite frankly, all those questions about “Which Web framework should I use?” at Java conferences, combined with the fact that people keep trying to make Web applications into desktop applications when what they really wanted in the first place was a desktop app, just burned me out on All Things Web. So I’ve not spent a lot of time studying ASP.NET MVC, or anything else ASP.NET-related, for that matter. So, I figured, I’d sacrifice a weekend or so and slog my way through the book, for Jon’s sake. I mean, he helped me figure out what to order at the restaurant in Bangalore, so I figured I owed him at least that much.
Folks, to use the words first made famous by Neo, “Whoa. Now I know
ASP.NET MVC.” And in about the same amount of time, too.
Jon’s writing style is quick, easy-to-read, and most importantly he’s not out to try and impress you with his vocabulary or mastery of the English language—he writes in the way most of us think, using single-syllable words and clear examples (and without reference to words like “catamorphism” or “orthogonal”). He’s not out to prove to the world that he’s a smart guy—he’s out to do exactly what the book claims to do: help you test drive the ASP.NET MVC framework, getting to feel how it approaches certain problems and exploring the ways it provides extensibility points.
One of the most striking things about ASP.NET MVC that comes across clearly in Jon’s book, in fact, is how easy it is to get up and running with it. I don’t mean “Look, Ma, I can code a demo with just a few mouse clicks!” kind of up to speed, but more of the “Look, folks, I can do a fair amount of pretty straightforward work in a pretty straightforward way after reading just a single chapter”, that chapter being (naturally) Chapter 1. In it, Jon walks the reader through a simple Web app (the “Quote-O-Matic”, for handing out witty and/or deep quotes to people who hit the home page), from installing the bits to seeing how requests route through the ASP.NET pipeline and into the MVC framework, and to your Controller and View from there. In fact, armed with just what you learn in Chapter 1, you could arguably do a fairly simple Web app in MVC without reading the rest of the book.
Of course, you’d miss out on a whole bunch if you did that, but you get my point.
Chapter 2 then gets into TDD (Test-Driven Development), and here I’m not quite so much a fan, if only because I’m not a TDD fanatic. Don’t get me wrong, Jon’s prose isn’t preachy, evangelical or in any way reminiscent of the “fire-and-brimstone” kind of tone that often accompany TDD discussions, despite Jim Newkirk’s chapter quote, which doesn’t exactly help convince the reader that this isn’t going to be one of those “Repent and come to TDD!” chapters. In truth, it’s not a “TDD” chapter, per se, but a chapter on how to unit test with MVC as a whole, which is important. (In fact, if you’re not unit-testing, why bother with MVC at all? A significant part of the point of MVC is the ease by which you can unit-test your code.) If you don’t unit-test your ASP.NET apps today, spend some time with the chapter and give it a fair shot before making a decision. Jon—and all of ThoughtWorks—believes strongly in unit-testing, and they churn out projects with an incredible on-time/under-budget/defect-free habit. Which is, I’m sure, part of the reason why this chapter appears here and not later in the book.
That’s the Fundamentals section. Seriously, those two chapters. That’s it.
Part II then gets in to deeper concepts around building the app: Chapter 3 discusses overall organization, Chapter 4 on Controllers, Chapter 5 on state and files, Chapter 6 on Views with HTML Helpers and Master Pages, and Chapter 7 on Views with AJAX and “Partials”. Part III then talks about MVC integration with other frameworks, a la NHibernate.
Part IV is, in many ways, a coup de grace for the book, though, because Jon fearlessly tackles that bugaboo of Web development books: Web security (Chapter 11). So many books on the subject just skim over security or give it a pass with “My examples aren’t supposed to be real applications, so make sure you do the right security stuff before ship” and leave it at that. Not so for Jon—he go straight into error handling and logging and health monitoring. He then rounds out the section with Chapter 12, Build and Deployment, talking about what ThoughtWorks now refers to as “Continuous Deployment”, and how to use MSBuild to achieve this kind of automation. Nice.
Overall, I could wish the book was larger, because I think there’s so much more that could have been brought into the discussion, such as building a RESTful service using MVC, instead of a human-centric app, but the Prags like their books to be short and sweet, and this one is no exception (288 pages, including front and back matter, which means about 250 pages of “meat”). It’s not a reference you’re going to keep on your desk as you’re working through ASP.NET MVC, and the title reflects that: it’s a test drive through the MVC framework, with you as the passenger, watching over Jon’s shoulder as he puts this particular race car through the paces.
Published at DZone with permission of Ted Neward , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.