Comparing XML Strings in Unit Tests

Comparing two XML strings is painful.  So of course, my current project required me to come up with a way to do it in .NET.  I could only use version 2.0 of the framework, and I didn’t want to add more dependencies to solution that already has plenty (which ruled out XML Diff and Patch).  So far, I’ve come up with the following bit of code:

The validationXml contains a string representation of the XML being validated against.  It also means I only have to create one instance of XmlDocument.  After creating an XPathNavigator on the XmlDocument being compared,  an XPathExpression for the subset of XmlDocument being validated, and an XPathIterator, it can be called.

The “params” keyword makes the last argument optional, so it can contain zero or more names of XML elements to ignore when deciding whether or not to call an Assert.  I’m still figuring out how to optimize this, but I think it’s a good start.

Converting File URIs to Paths

I spent most of this morning looking for a replacement to Application.ExecutablePath.  The reason for this was because certain unit tests that depended on this code failed when a used any test runner other than the NUnit GUI.  When using test runners like ReSharper and TestDriven.NET, Application.ExecutablePath returned the executable of the test runner, instead of the DLL being tested.

Assembly.GetExecutingAssembly().CodeBase returned a file URI with the DLL I wanted, but subsequent code which used the value threw an exception because it didn’t accept file URIs.  This made it necessary to convert the file URI into a regular path.  I haven’t found a .NET Framework method that does this yet, but the following code seems to do the trick:


private static string ConvertUriToPath(string fileName)
{
fileName = fileName.Replace("file:///", "");
fileName = fileName.Replace("/", "\");
return fileName;
}

It’s morning again in America

The U.S. is certainly a different place today than it was yesterday.  The commentary I’ve seen that sums up best just how different things are is this Tom Toles cartoon of Obama walking into the White House beneath these words:

We hold these truths to be self-evident, that all men are created equal.

Yesterday, America proved that we really believe this.

Election Day

I got in line a little over 30 minutes after the polls opened. According to the poll worker who came out to see how everyone is doing, the line was out the door by 6 am (1 hour before the polls officially opened).

My first clue as to how long this would take was the amount of cars parked everywhere. Every spot that isn’t marked handicapped is full. Every curb is full. People are double-parked. The loading dock on the side of the school even has cars and SUVs in it.

Update: Around 90 minutes after I got in line, I finally got to vote.  The line was still outside of the school when I left.