Wednesday, September 30, 2009

Using ASP.NET MVC with Windows Azure

I've been playing with Windows Azure quite a bit lately. Here is a 'blog post that details how to use an ASP.NET MVC website as a Windows Azure web role: ASP.Net MVC on Windows Azure | ASP.Net MVC Web Role.

Thursday, September 3, 2009

ColorCode 1.0 Released!

Nearly two years ago I started a "slack project" to create a source code colorizer for CodePlex because none of the existing open source options that would work for us had a friendly license. Then, a year ago, I publicly launched ColorCode as an open source project. But I didn't actually package the library as a release that people could download. Folks who wanted to use ColorCode had to build it from source themselves.

CodePlex has been using ColorCode throughout that time. And Microsoft's Forums websites have been using ColorCode for six months. There's another team within Microsoft currently building a site that uses ColorCode as well. It's fair to say it's been stable and well-used for quite some time, even without a formal release.

But there were some things I wanted to do before I took the 1.0 step. Forums needed C++ language support. And there were a handful of unresolved bugs. Well, thanks to tonight's insomnia, all that's behind me. I'm happy to announce that ColorCode 1.0 is now available on CodePlex.

There are still plenty of features that could be added, but I'd rather let the people using ColorCode drive that. And, of course, there will always be new languages to add (Ruby and Python are high atop my list). But I'm happy with the languages included in 1.0 (HTML, JavaScript, CSS, XML, C#, VB.NET, C++, and ASP.NET).

I send many thanks to the CodePlex team's developers and testers for their contributions, especially Matt Hawley and Rahul Jajoo.

Monday, August 24, 2009

Record.Exception for Ruby TDD

I've been working on a Ruby chat server (well, it's actually more of a connection broker for peer-to-peer chat clients) for an upcoming app I'm going to release. TDD is how I roll, but I haven't done much of it in Ruby because the tooling and workflow is so very different than what I'm used to in the .NET world. Today, finally, I settled into a workflow with TextMate and Test::Unit that makes me happy.

I use xUnit.net in the .NET world, which was created and is maintained by my friend Brad and my skip-level boss Jim. There is one thing from xUnit.net that I was really missing when using Test::Unit: Record.Exception. Here is a C# example of how Record.Exception can be used:
using System;
using System.Collections.Generic;
using Xunit;

namespace ColorCode.Compilation
{
    public class LanguageRule_Facts
    {
        public class Constructor_Facts
        {
            [Fact]
            public void It_will_throw_when_the_regex_is_null()
            {
                Dictionary captures = new Dictionary { { 0, "fnord" } };

                Exception ex = Record.Exception(() => new LanguageRule(null, captures));

                Assert.IsType(ex);
                Assert.Equal("regex", ((ArgumentNullException)ex).ParamName);
            }
        }
    }
}
The important thing about Record.Exception is that it allows you to stay true to the 3A pattern (arrange, act, assert), even though you are dealing with an exception. This is pretty important to me. So I threw together a quick and dirty Ruby method to do the same thing:
def record_exception
  begin
    yield if block_given?
    return nil
  rescue Exception => ex
    return ex
  end
end
Yes, it's ridiculously simple. But now I can do this:
require "test/unit"
require "assert"
require "client"

class ClientTests < Test::Unit::TestCase
  def test_init_will_throw_when_io_is_nil
    ex = record_exception do
      client = Client.new(nil, Object.new) 
    end
    
    assert_not_nil(ex)
    assert_equal(ex.to_s, "io must not be nil.")
  end
end
This solves the second-most severe pain point I had with Ruby TDD. There are many more yet, and they'll likely be the subject of future 'blog posts.

http://twitter.com/anglicangeek