About the author

Steven HarmanSteven Harman is a passionate developer who believes that writing great software isn't just a job, its a craft.

ASP.NET MVP

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Jobs

Badges

  • Subtext Project
  • Support Subtext
  • HiddenNetwork.com Banner

Code & Stuff...

Posts about writing code... and stuff.

Rhino.Mocks Beta Bits are Running Turbo-Charged!

A few weeks ago Oren (known to many as Ayende Rahien) pushed out a Rhino.Mocks beta drop so we could take a look at the new Arrange/Act/Assert syntax being cooked up for the pending 3.5 release. Yesterday I finally upgraded my client project to the 3.5 beta bits and started digging into the new syntax. AAA, FTW! After using Arrange/Act/Assert for just a day or two I’m already hooked. It feels like a much more natural fit for bdd-style tests. The whole Given, Expect, When, Then, go-back-and-verify-expectations flow always felt clumsy and counterintuitive, and AAA allows for...

Run your MbUnit Tests from ReSharper 4.0!

I just saw that Albert Weinert has upgraded the MbUnit test runner plugin to work in ReSharper 4.0, sweet! Since ReSharper 4.0 is still in pre-beta, there is no guarantee that it will work at all, but I'm running the latest nightly builds and IMO its getting more stable every day. I verified that the MbUnit test runner plugin does work by installing it on against ReSharper 4.0 build 758 and opening the Subtext 1.9 Branch source code. The image to the left shows the ReSharper Unit Test Explorer open and displaying the MbUnit tests from Subtext. ...

Lightning Talk Recap:15 Minutes with Rhino.Mocks

At last week's CONDG meeting I gave a lightning talk on Rhino.Mocks. Overall I think the talk went pretty well - the talk was voted second best of the night, following Jon Kruger's talk on LINQ to SQL. But that's OK with me. I knew a topic like mocking would be a hard one to cover in just 15 minutes. My goal was just to get people interested so they would go out and investigate some more on their own. And judging by the questions I got during the one minute Q&A at the end of my talk and the conversations I...

Ruby Has Ranges, and So Does C#

Creating a Range in Ruby is dead simple. 1: my_range = (1..10) 2:   3: my_range.each { |i| puts "My number is: #{i}." } Running that little snippet will do just what you think, push the numbers 1 through 10 out and shove them into the sentence my number is x. ...

Expectation Based Testing with Mocks

Last week I talked about Rubifying your C# code by adding the .Each() extension method to the IEnumerable<T> interface. I was discussing that code with one of the guys at work and he asked a brilliant question So, how did you test that? I was floored. Being such a test-first fan boy I couldn’t believe that I had failed to write that little extension method in a TDD manner. Hell, I hadn’t even done TAD! So how do I test it? There are no doubt a plethora of ways to test this...

Value Type Parameters Are Still Value Types, Even in a Lambda Expression

Today I was refactoring some unit tests, trying to get rid of some funky smelling tests, I made the all to common mistake of trying to be too clever. The smell This particular project has several entities that have a Timestamp field, represented by a byte array in the domain objects - err, code... depending the semantics you use. What I found to be particularly stinky was the inline byte arrays that were scattered all through the test code. And what’s worse, most of the arrays weren’t even of the correct size! For the record, they should...

A Better Search and Replace for Your Database

The ability to search for and replace a substring of text is such a useful, and often necessary, bit of functionality that nearly every text editor on the planet has it built in. However, the tool we often use to hold our text based data, the ubiquitous relational database, typically has very poor support for doing search and replace out of the box. Its so poor in fact that I’ve actually discussed this very topic, Search & Replace for your Database, before! However, as was noted in the comments to that post, my solution hack is not 100% effective....

Anonymous Delegates, Events, and Lambda Fun!

Events and delegates aren’t exactly a new concept in the .net world. I might even go so far as to say that they are fairly well understood by most experienced .net developers. That’s not to say the concepts behind them are easy to grok... I’m just saying that if you know developer who’s been around the .net-block a few times, he/she probably has a pretty good grasp of what a delegate is and how they’re used. Am I such a developer? Up until yesterday I thought I was. Here’s the scenario I found myself in: I...

A New Year's Resolution for Developers

Your Resolution this year should be: If you aren’t sure, make it public... and make everything virtual (or overridable, depending on your language) by default. Of course this primarily applies to those folks building frameworks for statically typed languages... <cough> Microsoft <cough>, but it also holds weight for the rest of us. After all, we all want other people to use our code - even if other people is your customers, your team, or yourself. The point is, we want our code to be (re)used. And I don’t know about you, but I’d...

TDD + DI + ASP.NET MVC Made Better with StructureMap's Fluent API, Oh My!

My God... could I put any more acronyms in that title. Yeah, I probably could. Oh, and if you just came for the code, jump to the bottom. In his post TDD and Dependency Injection with ASP.NET MVC, Phil used a DI framework to reduce friction and increase his Test-Fu when doing the TDD thang. How do you up your Test-Fu? By pushing the monotonous, and sometimes overbearing, work of wiring up dependencies off to a tool - in this case, a Dependency Injection tool called StructureMap. Angle bracket madness Phil was good enough to...

Replace that Stinky Code with a Bitmask and the FlagsAttribute

Pretend that you’re building an application to do something like... oh I don’t know, track employee time. Applications like this exist in almost every company on the face of the earth. After all, time == money, duh! Lets also pretend one requirement of your time tracker is to keep track of the employee’s regular work hours - meaning their start/end times and the days of the week they work. Again, seems like a pretty simple and intuitive requirement for a time tracking system. So, here’s my question: how would you go about storing the days the employee works...

Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!

One of the things I’m most excited about with Visual Studio 2008 is it’s ability to target various versions of the .net framework, a feature known as multi-targeting. I recently rebuilt a (hand-me-down) laptop for use at developer group meetings, conferences, and coding from the couch. When building out the machine I decided to only install VS2008 and make use of multi-targeting to work on my various .net 2.0 projects... like Subtext. Today I finally got around to loading Subtext up in VS2008 and I was expecting some heartache. But I did a little research first and...

Get Northwind, the Database That Won't Die, On SQL Server 2005

I am getting ready to put together a few sample applications to show off some of my favorite JavaScript libraries and demonstrate just how easy they make building AJAX enabled web applications. To simplify the process I was planning to use a little SubSonic magic to wire up REST interface to my database. But what to what database? Hello Northwind! Well the Northwind database, naturally! Problem is, I use SQL Server 2005 on both my main dev box and my laptop and it doesn’t include the sample databases. Actually, that’s entirely not true. Hello AdventureWorks...? As...

Avoiding Accidental Recursion with ReSharper 3.0

Who here loves ReSharper? I do, I do! Now that I’ve got that out of the way, let me tell you yet one more reason that I <3 ReSharper. While doing a little Subtexting tonight I was looking through a new class and noticed a couple those little yellow ReSharper (R# from now on) warning lights. You know, the ones it so kindly puts next to the vertical scroll bar to let you know there are some things that need your attention. The first one was safe to ignore - a warning about an unused...

Visual Studio: The Output Window, External Tools, and a Gremlin

I’ve been using SubSonic for a while now and I totally love it. Not only has it made developing in .net fun again, it’s also been a huge productivity booster for me and the guys I work with. And while I appreciate all of the hard work that the team has put into the SubSonic Build Provider for use with WebSite Projects, I just don’t work that way. I like having the actual generated code files included in my project (be it a WebSite or WebApplication) and checked into source control. I gives me the warm and fuzzies. But...

Add Option Elements to a Select List with JavaScript

While working on a web application I had the need to dynamically add new Option elements to a Select element (drop down list) using some fancy client-side JavaScript. The obvious solution was to do something like this: var theSelectList = $('theBigFatSelectList'); var myNewOption = new Option("My Option", "123"); theSelectList.selectedIndex = InsertNewOption(myNewOption, theSelectList); function InsertNewOption(newOption, selectElement) { var optsLen = selectElement.options.length; selectElement.options[optsLen] = newOption; return optsLen; } And it worked just as I’d expected. I got a new option in the drop down list and all was right with...

Use the PageRequestManager to Get More Control of Your UpdatePanels.

Being Web 2.0 is a hot topic right now. So much so that everyone and their mom is out to dress up their web presence with whatever Ajaxy goodness they can. Lucky for the Internet the ASP.NET AJAX framework has made adding Ajax functionality to asp.net web sites and web applications a pretty simple task. The simplicity is made possible because the framework hides much of the magical mechanics of doing the actual Ajax and DOM work behind a new control, the UpdatePanel. However, like most magical solutions this one comes at a cost. Actually a couple of costs. Two...

Note To Self: Remember to Add Assembly References Before Banging Head Into Desk

This is a quick note to myself - and all of you as well - for writing code and using classes from outside the standard .net assemblies. Be sure to add assembly references to the project! I was was working on some code today and tried to use a .net class from outside the assemblies that are automatically referenced when a new project is created. In this particular case I was trying to make use of the System.Transactions.TransactionScope class - from the System.Transactions assembly. After several minutes of banging my head into the desk and Googling I threw my...

Lightbox and Subtext Galleries Integration

Recently several Subtext users have asked how to integrate Lightbox JS into Subtext's photo galleries. My standard answer has been Right now it's not possible because the control that renders the galleries emits links with relative URLs rather than fully qualified URLs. We'll look into making a change to the data binding mechanism for a future release - so hold tight! I finally had a few spare cycles so I looked into the existing data binding logic and realized that it is possible to get the control to emit fully qualified URLs right now! Notice, I said it's...

Some Small Ways to Reduce Daily Development Friction

Brennan recently posted a great tip for changing the RSS Feeds that Visual Studio displays on the Startup page. Finally I can get rid of those horrible Microsoft articles and get some good content in that window! I quickly realized that many VS users probably already knew about this, but to many others, self included, this was totally new. And what's more, it's useful! So with that in mind, I decided I would start sharing some simple tips, tricks, and shortcuts that I use within the VS IDE and Windows environment to reduce the friction of many day-to-day development tasks. Open Containing Folder...

URL and HTML Encoding on the Client? JavaScript to the Rescue!

Phil recently wrote about some of The Most Useful .NET Utility Classes Developers Tend to Reinvent Rather Than Reuse - an article chock full of tasty tips, tricks, and reminders about [.net] framework features you forgot (or never knew) existed. One of the utility classes Phil mentioned was the System.Web.HttpUtility class. Two of the super useful methods this class offers are UrlEncode and UrlDecode... used to uh, convert a string into a URL encoded string and decode a URL encoded string, respectively. Do you encode? All web developers, regardless of language/platform, should be intimately familiar with the basic encoding schemes...

[Note to Self] SubSonic Requires a Primary Key for Every Table

After stumbling over this a couple of times in the past week I decided to blog-it so I won't forget again. By convention, SubSonic requires that any tables to be auto-generated into the DAL have a primary key. #1 sign you're missing a primary key You have your super-sweet database humming along in it's fully normalized form. You try to generate your DAL with SubSonic but one of your tables isn't being code-gened. For example, if you have a Customer table then SubSonic should generate the following three classes: Customer CustomerCollection CustomerController Note: Customer and CustomerCollection will...

CSS Friendly Control Adapters Now Hosted on CodePlex

I don't know how I missed this for so long... but I just realized that the CSS Adapters are now a community product. As best I can tell, Microsoft decided to hand control of the Adapters project over to the OSS community and it is now being hosted at CodePlex. Actually... I do know how and why I didn't catch onto this until now - Microsoft's asp.net site make no mention of the fact that the product has now been handed off to the open source community. (Or, at least it didn't as of the time of this writing.)...

CSS Control Adapters Cause Double PostBack in IE

As you might have been able to tell by my last few posts about CSS Friendly Control Adapters - I'm in the middle of using the adapters on a project... and I'm running into all kinds of trouble. I finally came to the realization that many of the issues I've seen are all caused by the same bit of busted functionality - a double PostBack. I just posted a new message to the CSS Friendly Control Adapters Forum over at asp.net, and I figured I'd re-post it here in hopes of drawing a little more attention to the issue....

CSS Friendly Adapters - Using Comments in your Browser File can be Touchy

If you're using CSS Friendly Control Adapters to get some of your asp.net 2.0 controls under control - at least when it comes to the markup they render - be careful when adding comments to the CSSFriendlyAdapters.browser file. The .browser file is an XML formatted file that the asp.net runtime uses to configure what adapter(s) gets attached to which framework control(s). And as some of you may be aware, there are some known issues with using the CSS Adapters with some of the new Login controls. One common solution work around is to disable the CSS Adapters for the controls...

WebForm_PostBackOptions is Undefined - Check Your httpModules

While working on a new client application and ran into a bizarre issue with the WebResource.axd handler. The issue manifests itself as a JavaScript error when trying to do a PostBack from your WebForm. In IE7 you'll get the standard Error pop-up message informing you that 'WebForm_PostBackOptions' is undefined Not exactly the most useful error message. After a little JavaScript debugging in Firebug I found that the error was thrown because the WebForm_PostBackOptions method was missing. Yikes! How is it missing? As of asp.net 2.0, the Framework uses a new WebResource.axd handler to send assembly resources (like images, CSS...

CSS Friendly Control Adapters, CreateUserWizard, and ViewState... Oh My!

So you're using the CSS Friendly Control Adapters to generate lean, mean markup for your asp.net 2.0 controls, awesome! And you're also using some of the new Login controls to cut down on the hand-rolled authentication/authorization code, great. Do you also have ViewState disabled? Are you also having trouble getting values out of the controls during PostBack processing? I was! My scenario I was using the CSS Friendly Control Adapters and the Login controls without ViewState. Specifically I was using the CreateUserWizard and it's ContentTemplate to generate a sleek user registration UI. I had attached a LoginCancelEventHandler to the wizard's...

Themes, Themes Go Away!

I was working on some CSS based printing stuff today (inside an ASP.NET WebForms application) and I ran into an odd issue. The application is making use of MasterPages and Themes, but I was working on a new page (a full blown .aspx) that was used exclusively for printing. This meant two things: I made sure to NOT use a MasterPage in the @Page declaration. I set EnableTheming="false" in the @Page declaration. With that done I should have had a page with zero style... that is, no stylesheets or inherited markup - essentially a blank slate. So I started...

Search & Replace - For Your Database

UPDATE: It appears that the .zip file I posted earlier was actually busted - I guess that's what I get for being lazy and not testing the parameterized version before putting it out there. Anyhow, Phil emailed me a version that actually works as advertised. I've updated the link at the bottom of this post, so grab the updated version from there. Search and replace is a common (and most useful) feature that is present in even the most basic of text editors. Some of the more powerful text editors (I like notepad++) even allow you to use Regular...

Reporting Services + Your Custom Assembly = #Error. WTF?

OK, so you've spent the last (fill in some obscenely long time period) trying to get SQL Server Reporting Services to use your Custom Assembly for retrieving data from your application. But no matter what you try, you keep seeing #Error rather than your data when you run the report on the server. By this point you've read countless white papers, tutorials, blog posts, etc... that outlining how the scenario should work*. That's right, you've added the necessary <codegroup> to your .config files. You've added references to your assembly from your report, and you've even made some example code (from the previously...

XFN Microformat - with Icon Goodness

Tonight while working on some blog posts about CodeMash I decided to make use of a new Windows Live Writer plug-in, Insert XFN Link. In my post about becoming a more productive programmer I tagged a link to Jon Galloway's site with the XFN markup. I quickly realized that I didn't like the icon that Subtext's XFN Highlighter uses. So naturally I set to the web to find some alternatives. I came across some great icons for the XFN Microformat, and I just had to have them. Since they are licensed under the Creative Commons ShareAlike 1.0 license I pulled them down...

CSS Friendly Control Adapters - Add 'em to Your Site

Recently I've been playing around with the new ASP.NET 2.0 CSS Friendly Control Adapters as I loath the bloated and overly complex table based markup that so many WebControls render by default. After building a test website using the Web Site template that is included with the adapter's v1.0 download I decided to incorporate them into a project I'm currently work on. There is a good white paper that walks you thru integrating the adapters into your existing web site that I followed step-by-step... almost. First off, my site was using the Web Application Project model, not the Web Site Project...

Migrating a VS 2003 Web Project to VS 2005 Web Application Project - Gotcha!

I recently tasked myself with upgrading a (work) project from the Microsoft .NET Framework version 1.1 to the much improved 2.0 version. One of the biggest (and best) side effects of  upgrading to the 2.0 framework is getting to develop the project in the Visual Studio 2005 IDE - which is a huge improvement over the 2003 edition.  The project I was upgrading was known as a Web Project (in VS 2003 terms) and I wanted to upgrade it to a VS 2005 Web Application Project. Prior to VS 2005 SP1 the default web project model was the Web Site Project and using a...

Installing VS 2005 Service Pack 1 - It went well!

Despite the horror stories I'd read/heard regarding the upgrade to Visual Studio 2005 SP1, last night I decided to just bite the bullet and go for it. Had I gone delirious from too many hours of scanning the blogosphere in search of the ultimate How-To guide for upgrading? Was I being naive... or perhaps suffering from delusions of grandeur? Who knows. But once I decided that I was going to do the upgrade, I knew there was no turning back. How I did it As I said, I spent several hours scouring the web for all of the tips, tricks, and gottcha's...

Hotfix KB928388 - Revised Daylight Savings Time

Today I was merging the Subtext 1.9 branch back into the trunk in our SVN repository and I came across an interesting "Gottcha" to keep in your back pocket - Microsoft has changed the Time Zone settings with the fix for KB928388. The Back Story One of the great things that Subtext has going for it (from a developer's perspective) is our great suite of Unit tests. At the time of this writing we were up around 39% code coverage. So, being the contentious developer that I am, after I merged the branch into trunk and cleaned up any...

Get Around Database Locks with the NOLOCK Keyword

Tonight I was trying to debug a couple of failing unit tests for Subtext and I came across a common (though not exactly obvious) issue. These particular tests required access to a database, so I was using MBUnit's Rollback attribute to make sure that any changes made during execution of the test were rolled back when the test was finished. Essentially all the Rollback attribute is doing is wrapping the entire test in a SQL Transaction - smart! So what's wrong? As I was debugging one of the failing tests I realized that I was not getting the expected...

Mouse Over Row Highlighting - Redux

Some Background A while ago, a smart guy that I know wrote a little post entitled "Adding Mouse Over Row Highlighting To Tables". In his post, Haacked showed us how to use Markup Based JavaScript Effect Libraries (via Jon Galloway) to add a little UI Goodness to your typically boring HTML Tables. I recently decided to use this nice effect in a project for work, and ended up building it out to be more robust and play nice with others (other CSS styles, that is). So, in the spirit of the OSS movement, I thought I would share my new...

The 'ATLAS' Framework - Callback Handler JavaScript Bug

First, an introduction. "ATLAS" is a free (as in beer) framework from Microsoft aimed at building rich, responsive UIs by utilizing AJAX techniques on the web. This framework is different from other AJAX libraries/frameworks as it is built for, and fully integrates with the ASP.NET 2.0 server-based development framework. This tight integration makes adding AJAX-ish functionality to your existing ASP.NET applications quick and (relatively) painless. My First Take I recently decided to look into using ATLAS as the AJAX Framework of choice for the Subtext project. After running through the step-by-step installation instructions, and reading a few quick...

Another Bulletproof SQL Script Using INFORMATION_SCHEMA Views

As I'm sure many of you know, peer pressure can be a very powerful motivator... and I am not immune to such pressure. So, hot on the heels of Phil and Jon's posts on the magic voodoo that can be accomplished with the INFORMATION_SCHEMA Views, I felt obligated to add my own small bit of wisdom to the fray. In reading through Phil's article I noticed he didn't mention anything in particular about the creating, modifying, and/or dropping of Stored Procedures when working with a common schema among a development team. This is one thing we often have to deal with...

Custom Output Caching in ASP.NET

When building a web application, one of the most important aspects of the its usability is performance. To be more exact, how quickly the app responds to and process requests for information. One of the best ways to help improve your app's performance is by caching some of the data the server/app needs to render the requested resource [in this a web page]. For a quick-and-dirty intro to what caching is all about, check out this Wikipedia entry. Caching with ASP.NET The ASP.NET framework provides three types of caching for web-based applications: Page Level Caching (called Output Caching) Page Fragment Caching (often called Partial-Page...

[How-To] Override equals() and hashCode()... Part 2.

In Part 1 of this series we discussed how to override the equals method for any class the extends from java.lang.Object, why we would want to do so, and a few pitfalls of doing this. In this post we will look at how and why you must also override the hashCode method any time you override an object's equals' method. So why the hype about hashCode()? Good question. And I have an answer for you! If you take a look at the Java JDK documentation covering Object.equals you will see that one of the last things mentioned is the following: Note that it...

[How-To] Override equals() and hashCode()... Part 1.

Despite the enticing title of this two part series, I'm sure its content will prove to be quite obvious and mundane for many experienced Java and/or C# developers out there... but that doesn't make it any less important. This is a topic that I often find myself covering with our new entry level developers, and on occasion even with some more seasoned developers. Java & C#, huh? You probably noticed that I mentioned both Java and C# above... and I did so for good reason(s): this is applicable to both languages (and probably many other for that matter) We are a purely Java...

Using SQL-DMO in your .NET app... mine's broken!

"SQL Distributed Management Objects (SQL-DMO) is a collection of objects encapsulating Microsoft® SQL Server™ database and replication management." Well pretty much sums it up for me!But in all honesty, SQL-DMO is a great tool that you can use for accessing and manipulating your SQL Server DB's from within your .NET applications. One such application [here comes the obligatory plug] is subText! We are currently using SQL-DMO in a custom database connection string builder that we use to get information about local (or network) SQL Servers while installing the subText platform. This allows us to have a quazi-wizard method for building...

Using MbUnit with COM+ 1.5 transactions... a big Gotcha!

Its been a while since I took my first steps into the wild world of software engineering, but only recently did I finally start down the Test Driven Development path. I have always been a proponent of Extreme Programming but seeing as the majority of my experience, prior to joining the subText Project Team, is from the corporate world, I'd never had the opportunity to truly implement many of the practices in my daily design/development work. I'm not saying that _the corporate world_ doesn't believe in EP and/or TDD, just that our shop doesn't follow these techniques. Anyhow, I finally...

Debugging a .NET WebApp in VS.NET

I've blogged before about debugging dotText in Visual Studio, and recently I've gotten a few emails asking for some help with getting the VS.NET Debugger working. I know that it took some time to get the debugger working correctly with dotText, so I thought I'd put together a little How-To. I'm pretty sure that these instructions will work for most ASP.NET web applications, but I'll be using dotText v0.95 for this Guide. First, a few things that you'll need to have in order for this to work: Visual Studio .NET running on the local machine.The ASP.NET Web server running on...