Microsoft Fakes and Shims

This is pretty cool that you can use this technique to test around .net framework items like this

// Code under test:
public int GetTheCurrentYear()
return DateTime.Now.Year;
public class TestClass1
public void TestCurrentYear()
int fixedYear = 2000;

// Shims can be used only in a ShimsContext:
using (ShimsContext.Create())
// Arrange:
// Shim DateTime.Now to return a fixed date:
System.Fakes.ShimDateTime.NowGet =
() =>
{ return new DateTime(fixedYear, 1, 1); };

// Instantiate the component under test:
var componentUnderTest = new MyComponent();

// Act:
int year = componentUnderTest.GetTheCurrentYear();

// Assert:
// This will always be true if the component is working:
Assert.AreEqual(fixedYear, year);


Fluent .Net State Machine

I was listening to an episode of DNR featuring Chris Patterson who is behind MassTransit, an open source .net service bus.  I’d recently been working a little with NServiceBus so I was interested to hear his take on the subject.  One of the interesting things to come out of the interview was a quick mention of another of his projects, Automatonymous, which is a .net state machine that operates in a fluent interface.

So for example:

public class BigComplexStateMachine :
//declare states
public State InProcess { get; set; }
public State Delayed { get; set; }
public State OnHold { get; set; }
public State Delivered { get; set; }
//you get 'complete' and 'initial' for free

//declare events
public Event Ordered { get; set; }
public Event Delay { get; set; }
public Event Hold { get; set; }
public Event<CustomEventData> Deliver { get; set; }

//must NOT have arguments
public BigComplexStateMachine()
//inform the statemachine of your states
State(() => InProcess);
State(() => Delayed);
State(() => OnHold);
State(() => Delivered);

//inform the statemachine of your events
Event(() => Ordered);
Event(() => Delay);
Event(() => Hold);
Event(() => Deliver);

//define transitions
.Then(state=> { /*do cool stuff */ })

When(Deliver) //notice the new param available
.Then((state, @event) => { /* do cool stuff */ })

//so on and so forth
* During(state, When(event).[StuffIWantToDo].TransitionTo(state));
Anytime(When(Hold) //also support an anytime concept
.Then(state=> { /*cool stuff*/ })
.Complete() //convenience method


Some more info here as well.

SlowCheetah config transforms

I’ve been using this tool for some time on a number of projects.  SlowCheetah allows you to transform your config files at build time based on the build type.  So when you do a Debug build, you can include values that are meant for your dev environment, while at the same time doing a Release build will use values meant for production.

Very nice.

IIS6 HTTP Compression

Here are some great articles talking about properly enabling compression in IIS6.

I had made some of these changes in the past, but I noticed that they had since been overwritten or not persisted.  I believe with the changes to the metabase file it will help keep the compression working.

Bear Necessities Pediatric Cancer Foundation

Last year, I donated a weekend of my time to work with some other developers to create a new site for Bear Necessities Pediatric Cancer Foundation.

When we wrapped up work, the site was nearly completed, with a few ends to tie up, and of course, all the content needed to be entered and hosting setup and DNS ….. you get the idea.

So FF a many months and I was starting to think that the site would never go live.  Well it finally did.

It isn’t the most beautiful site (we didn’t have any graphic artists on the team) but it’s waaaaay better than what they had.

XXXX is ambiguous in the namespace 'ASP'

I’ve been getting this error every now and then.

Usually this problem is caused by having 2 controls with the same name.  It can be that they are in different folders as well.

I came across this post today:

Well, a quick search online told me that this might be a result of a known bug in the compiler. The fix was easy, you have to compile your app in non-batch -mode. How do you do this, I hear you asking. Simple: enter the compilation section of your web.config, and set batch=”false”, as so:

<compilation debug=”true” batch=”false”>


Build Visual Studio Solutions and Projects from Explorer

Adding this to your registry will give you the ability to build/clean/rebuild projects using the right click in windows explorer.  It uses .net 4.0 version of msbuild.  Just paste this into a .reg file and run it.

Windows Registry Editor Version 5.00 




@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:build""


@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:clean""


@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:rebuild""




@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:build""


@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:clean""


@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:rebuild""




@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:build""


@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:clean""

@="cmd.exe /K ""%%windir%%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "%1" /t:rebuild""

ASP.NET Server Tags

There are a number of different server tags (<%, <%#, <%$, <%@, <%=) which each mean different things.

This article goes into a little depth talking about each of these tags.

The one I never use, is <%$, which I learned is for displaying expressions, but you can also easily write your own expression provider by extending the expressionbuilder class.  An example of doing so can be found here.

Pretty cool.

VS.Net Go To Implementation

Visual Studio has a nice “Go to definition” shortcut, but with our MVP pattern we are doing a lot of work against interfaces, which means that quite often going to definition actually takes us to a method in an interface.  For example:

Dim e As IEmployee = New Employee(1234)
Call e.GiveRaise(1.05)

If you did “Go to Definition” on “GiveRaise” you would not end up in the Employee class, but rather than IEmployee interface.

This plugin helps fix that problem.

I ended up skipping that part where he sets up the keyboard shortcut in favor of just using right click, but if you want to set that up you might find that the menu item he talks about is missing.  To get that dialog to show up use the keyboard shortcut CTRL+ALT+SHIFT+O.