Microsoft Fakes and Shims

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

http://msdn.microsoft.com/en-us/library/hh549175.aspx

// Code under test:
public int GetTheCurrentYear()
{
return DateTime.Now.Year;
}
//
//--------------------
//
[TestClass]
public class TestClass1
{
[TestMethod]
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);
}
}
}

Advertisements

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 :
StateMachine<BigState>
{
//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
Initially(
When(Ordered)
.Then(state=> { /*do cool stuff */ })
.TransitionTo(InProcess)
);

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

//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.

http://blog.grushin.com/2008/04/21/iis6-compression-including-js-css-etc/

http://blog.grushin.com/2008/04/21/iis6-compression-file-extensions-and-testing/

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.

http://bearnecessities.org/

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:

http://personalinertia.blogspot.com/2007/06/there-bug-in-compiler.html

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”>

</compilation>

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 

[HKEY_CLASSES_ROOTSystemFileAssociations.sln]

[HKEY_CLASSES_ROOTSystemFileAssociations.slnshell]

[HKEY_CLASSES_ROOTSystemFileAssociations.slnshellBuild]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.slnshellClean]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.slnshellRebuild]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.csproj]

[HKEY_CLASSES_ROOTSystemFileAssociations.csprojshell]

[HKEY_CLASSES_ROOTSystemFileAssociations.csprojshellBuild]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.csprojshellClean]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.csprojshellRebuild]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.vbproj]

[HKEY_CLASSES_ROOTSystemFileAssociations.vbprojshell]

[HKEY_CLASSES_ROOTSystemFileAssociations.vbprojshellBuild]

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

[HKEY_CLASSES_ROOTSystemFileAssociations.vbprojshellClean]

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

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