Party with Palermo (pre-Tech Ed party) final announcement – level 000

I posted earlier about the details of Party with Palermo 2006.  You can read the original post here.  Since the announcement, I’ve received tons of emails from folks who are planning to party with Palermo.  If you are coming to Tech Ed a day early, this is the place to be Saturday night.

Here are the details again.
Date/Time:  Saturday, June 10th @ 7:30PM until late, late, late
Location:  Millennium Bostonian Hotel’s Atrium Lounge (collared shirt required)
Who’s Invited:  Anyone who reads this.  Tell your friends.  Invite anyone and everyone.  Blog that  you will be attending.

At
the Atrium Lounge, we’ll have plenty of drinks, and they have a light
supper menu if you would like to grab something to eat as well.  The
lounge looks on to the Faneuil Hall market place as well, so the hotel is right in the heart of where everything is happening in Boston.

The Atrium Lounge has free WiFi Internet, so pictures could be uploaded in realtime.

When the only thing that will work is gacutil – level 200

I try to avoid the GAC at all costs.  I prefer xcopy deployments
of applications.  However, if you use some projects that all
reference log4net, then you know the pain of trying to resolve log4net
versions.  More often than not, it’s not feasible to recompile
every project you depend on.  If you need to reference two
libraries that each then reference different versions of log4net, you
have a tough problem because only one file named “log4net.dll” can be
copied to the /bin directory.

log4net is a strong-named assembly, so version information is a part of
finding the assembly.  In this case, I had to resort to putting
two versions in the GAC.  As much as I hated doing so, it seemed
like the only way out.

gacutil /i log4net.dll (x2)

Resharper 2.0 now released – level 000

Resharper 2.0 is finally released.  I’ve been using the beta of 2.0 for a while, and I used v1.5 on VS 2003, and it enhances productivity a lot.  One of the simplest things that I couldn’t live without is rename.  If I rename a class property that is used throughout my solution, it’s done instantly.  Without an autorename, I’m left with search and replace, a time-consuming affair.

Check it out!!!  They have a 30-day trial.  Read the docs and get familiar with the keyboard shortcuts.

You can see the list of new features at:
http://www.jetbrains.com/resharper/releaseNotes20.html

To download this latest version of ReSharper 2.0:
http://www.jetbrains.com/resharper/download

Microsoft republishes Guidelines for Test-Driven Development – level 200

If you remember the article in October that was on MSDN on Test-Driven Development, you remember the hub-bub that it caused because of the inaccuracies, and how it soon was pulled from the web.

Microsoft has published new Guidelines for Test-Driven Development.  See the article to see why I think they got it right. 馃檪

Many thanks to Paul Schafer and Rob Caron.

StructureMap v1.1 (for .Net 2.0) released on sourceforge – level 000

Not long ago, Jeremy Miller released version 1.0 his excellent dependency injection tool, StructureMap.  I’ve ported it to .Net 2.0, and I’ve added generics to the bread and butter class, ObjectFactory.  Download the .Net 2.0 release on sourceforge.net.  StructureMap supports creating very loosely coupled applications by service location and dependency injection.


Coding to interfaces is fine and dandy, but at some point, you need an instance of the concrete class that implements the interface.  Typing “new SomeClass” tightly couples your code, so what do you do?


Slap an attribute on the interface, the concrete class, and then all you have to type is:


IMyInterface instance = ObjectFactory.GetInstance<IMyInterface>( );


That’s all it takes, and you have an instance of the interface you are binding against.  Using this pattern, you can harvest reuse in your applications and test any component in isolation.

Party with Palermo: Tech Ed 2006 – location announced! – level 000

Since this announcement is going out over my blog as it did last year, the folks at Party with Palermo will be folks who are plugged into the Microsoft developer community:  conference speakers, Microsofties, MVPs, user group leaders, INETA leaders and others bloggers/blog readers.  Here are the details:
Date/Time:  Saturday, June 10th @ 7:30PM until late, late, late
Location:  Millennium Bostonian Hotel’s Atrium Lounge (collared shirt required)
Who’s Invited:  Anyone who reads this.  Tell your friends.  Invite anyone and everyone.  Blog that  you will be attending.

At the Atrium Lounge, we’ll have plenty of drinks, and they have a light supper menu if you would like to grab something to eat as well.  The lounge looks on to the Faneuil Hall market place as well, so the hotel is right in the heart of where everything is happening in Boston.

The Atrium Lounge has free WiFi Internet, so pictures could be uploaded in realtime.

IMPORTANT:  I need to know how many people are planning on coming.  Please post a comment or email me through my blog with your name and email address so I can plan and notify you of late-breaking details the week before Tech Ed.

Tech Ed 2006: I’ll be facilitating BoF “Agile Development with .Net” – level 000

If you are going to Tech Ed 2006:

  • Come to Party with Palermo
  • Stop by my Bird’s of a Feather session on “Agile Development with .Net”

The session will be on Tuesday at 7:45PM

This BoF will not seek to convince people on the merits of Agile: there are plenty of print resources that weigh in on that topic.  It will focus on what has been working and what hasn’t for real teams practicing some or many of the Agile practices.  I personally with have some good success stories as well as a few “if we had only. . .” stories.

I hope you will come and share what has/has not been working for your team.

VS 2005 Web Application Projects installed! *breaths a breath of fresh air* – level 100

Upon hearing the announcement that Web Application Projects has been released, I wanted to get EZWeb converted
over as soon as possible (I’m close to making another release). 
I’d been limping along with the default web site option in Whidbey, and
I didn’t like it at all. 

First, you can download the VS 2005 add-in here.  There isn’t an automatic port of a VS 2005 website, but it was easy enough to do.  Here were my steps:

  1. Add new web application project to my solution. 
  2. In Win Explorer, copy the entire contents of my web site project to the web application folder.
  3. Delete my web site folder.
  4. Remove the website from my solution.
  5. Show all files in the web application.
  6. Explicitly include everything except bin and obj
  7. Add any assembly references necessary to the new project.
  8. Set any post-build events that you’ve been jerry-rigging up to this point.
  9. Run a build.  You’ll notice it fails on control declarations in code-behind files.
  10. Right click on the web project and run “Convert to Web Application”.  This adds an explicit partial class to  your code-behinds that hold your control declarations from the markup file.
  11. Run the build again.  It passed for me at this point.  I ran my application, and all was well.
  12. Run all unit tests and integration tests.  They all passed for me.

This project model is so much easier to use for real web applications
(that aren’t just web _sites_).  Kudos to the ASP.NET team for
getting this patch out.

If you are using Resharper 2.0 (beta), you’ll notice a slight
difference in navigating to files.  CTRL+N will locate the ascx.cs
and ascx.designer.cs files since they are C# code files.  To get
to the ascx files, you’ll need to use CTRL+SHIFT+N.

Integration testing demonstrated – level 200

In this
post, I’ll talk about and demonstrate integration testing.  If you are just starting out with integration
testing, you want to test small before you test big.  Full-system tests are good, but if they fail,
they don’t give much of a hint as to where the failure is.  Smaller integration tests will help narrow
the area where the failure lies.

 

A few
rules to live by

                    
An
integration test must be isolated in setup and teardown.  If it requires some data to be in a database,
it must put it there.  Environmental
variables should not cause the test to fail randomly. 

                    
It
must also run fast.  If it is slow, build
time will suffer, and you will run fewer builds – leading to other
problems. 

                    
Integration
tests should be order-independent.  It
should not matter the order you run them. 
They should all pass.

                    
Feel
free to make up rules that objectively result in fewer bugs.

 

Testing
a custom SiteMapProvider

In my
example, I have a custom SiteMapProvider (PageInfoSiteMapProvider).  This site map provider gets it’s data from
inside my EZWeb application, specifically, the IPageConfigProvider interface.  I use StructureMap for service location, so
one of the things that an integration test will validate is that my interface
implementations can be resolved correctly. 
I’m going to focus on an integration test for one method on the site map
provider, FindSiteMapNode(url). 

 

Here
is the constructor and method on my custom site map provider:

        public
PageInfoSiteMapProvider()

        {

            _provider = (IPageConfigProvider) ObjectFactory.GetInstance(typeof (IPageConfigProvider));

            ICurrentContext
context = (ICurrentContext)ObjectFactory.GetInstance(typeof(ICurrentContext));

            IConfigurationSource
config = (IConfigurationSource)ObjectFactory.GetInstance(typeof(IConfigurationSource));

 

            _applicationPath =
context.ApplicationPath;

            _defaultPage = config.DefaultPage;

        }

 

        public override SiteMapNode
FindSiteMapNode(string rawUrl)

        {

            VirtualPath
path = new VirtualPath(rawUrl,
_applicationPath, _defaultPage);

            PageInfo
config = _provider.GetPageConfig(path);

            SiteMapNode
node = MakeNodeFromPageInfo(config);

            return
node;

        }

 

This is
simple enough.  The site map provider is
just a wrapper around the interface call. 
Notice in the constructor, that I’m using a call to StructureMap’s
ObjectFactory class to resolve the interfaces that I need.  I need the current HttpContext and some stuff
in the web.config file.  Obvious in my
integration test I don’t have the ASP.NET runtime, and I don’t have the
web.config file, so I’ll need to simulate thing (mock, stub, fake, whatever you
want to call it).  In my integration
test, I’m going to have to use fake implementations of these interfaces.

 

Here
is the integration test fixture that tests this provider all the way down to
the point where it reads the data from the xml file on the disk. 
I’ve chosen this scope because it’s not too large, and it’s
not too small.

    [TestFixture]

    public class PageInfoSiteMapProviderTester

    {

        [SetUp]

        public void Setup()

        {

            IConfigurationSource
source = new TestingConfigurationSource();

            ICurrentContext
context = new TestingCurrentContext(source);

 

            ObjectFactory.InjectStub(typeof(IConfigurationSource),
source);

            ObjectFactory.InjectStub(typeof(ICurrentContext),
context);

        }

       

        [Test]

        public void ShouldGetRootSiteMapNode()

        {

            string
xmlFileContext = @”<?xml
version=””1.0″”
encoding=””utf-16″”?>

                <PageInfo
xmlns:xsi=””http://www.w3.org/2001/XMLSchema-instance””
xmlns:xsd=””http://www.w3.org/2001/XMLSchema””>

                 
<VirtualPath>/</VirtualPath>

                  <Title>My home
page</Title>

                  <Template />

                  <Theme />

                  <Plugin />

                 
<HasParent>false</HasParent>

                  <Children />

                  <Links />

                  <Editors />

                </PageInfo>”;

 

            string
fileName = FilePageConfigProvider._fileName;

            string
fileSubDir = FilePageConfigProvider._filesDir;

 

            string
fileDirectory = Environment.CurrentDirectory + “\” + fileSubDir;

            string
path = fileDirectory + “\” +
fileName;

 

            FileHelper
helper = new FileHelper();

            helper.SaveFileContents(path,
xmlFileContext);

           

            PageInfoSiteMapProvider
provider = new PageInfoSiteMapProvider();

            SiteMapNode
node = provider.FindSiteMapNode(“/mywebapplication/default.aspx”);

           

            Assert.AreEqual(“My home page”, node.Title);

            Assert.AreEqual(“/myWebApplication/Default.aspx”,
node.Url);

            Assert.AreEqual(“/”, node.Key);

        }

    }

 

This is
my entire integration test to make sure that the SiteMapNode object is put
together correctly. Notice that I have data setup with the xml file.  Then I call the provider and assert on the
results.

 

Faking
the “cruise missile” with StructureMap

If my
code was in charge of launching a cruise missile correctly, then I would have
to fake out the cruise missile when testing my code.  In fact, my code might not ever run in its
true environment until the world plunged into war again.  On a small scale, I have to fake the two
interfaces that are not reproduceable in my test context.  Direct your attention to the Setup
method.  You’ll notice that I’m creating
two fake instances and instructing StructureMap to “InjectStub”.  Because of this, when my code asks for an
instance of one of those interfaces, the class I created in Setup will be
returned.

 

Here
are the stub classes

    public class TestingCurrentContext
: CurrentContext

    {

        public
TestingCurrentContext(IConfigurationSource
source) : base(source) { }

 

        public override string
MapPath(string path)

        {

            string
executingDir = Environment.CurrentDirectory;

            string
combinedPath = executingDir + “\”
+ path;

            return
combinedPath;

        }

 

        public override string
ApplicationPath

        {

            get

            {

                return
“/myWebApplication”;

            }

        }

    }

 

    public class TestingConfigurationSource
: ConfigurationSource

    {

        public override string
ClientFilesPath

        {

            get

            {

                return
@””;

            }

        }

 

        public override string
DefaultPage

        {

            get

            {

                return
“Default.aspx”;

            }

        }

    }

 

These
classes are simple enough.  They merely
return expected environmental settings so that I can test my code.

 

Integration
testing is hard at first

If your
style of coding isn’t loosely coupled, then it will be difficult to do
automated integration testing.  Seams
must exist in the code where fake implementation can be inserted.  In my case, I had a web.config file and the
HttpContext of the web application that get in the way.  I stub these out for my test.  My tools list for integration testing is:

                    
NUnit
for organizing and running the tests.

                    
StructureMap
for resolving interfaces and for stubbing interfaces at hard boundaries.

 

My way
or the highway

Just kidding.  I’m not saying that this
is the “golden” way of doing integration testing.  There are many ways, and that’s why software
engineering is engineering and not assembly-line work.  The above approach has worked well for me,
and I put interfaces where they make sense (everywhere) in my code to maintain
flexibility.  I’m open for critique or
questions.

VS 2003 web projects model now available in VS 2005 – level 200

One of the biggest criticizms of VS 2005 was the radical change in the way web applications had to be set up.  From the folks doing more simple websites, this change was welcome, but the folks doing complex web applications, this change caused a bit of trouble.  It’s clear that some folks like the new way, and some folks like the way VS 2003 handled it (minus the mandatory control declarations).

Scott Guthrie has just announced the release of the Web Application Projects add-in for VS 2005 that brings the VS 2003 model to Whidbey.  It’s a simple install for VS 2005, and the project type is immediately available.   I’ll be installing and using it shortly, so I’ll be back with a personal review.

The word is that this will be included in VS 2005 SP1 as well.