At the beginning of this month I blogged about the Code of the Month. For July the program we are looking at is NUnit. As part of the code reading, I wrote an extension (sort of) that compares two files to determine if they are equal. The code uses NUnit internally, calling Assert.Fail if the files are not equal.
The FileAssert class has two basic methods for comparing files. One method takes in two FileStreams, with an optional overload for the message if the test should fail.
static public void AreEqual(FileStream expected, FileStream actual, string message)
The other method takes two FileInfo objects, again with a message overload.
static public void AreEqual(FileInfo expected, FileInfo actual, string message)
I tried to match the NUnit coding and commenting style as much as possible. All XML comments are included (the file is C#). And of course I wrote unit tests for everything! I tested this on files as large as 189MB. On my 2.8ghz machine with 512MB RAM, the comparison took under 4 seconds. A 10MB file comparison took under a half-second.
You can download this, and other extensions coming soon, from the NUnitExtensions workspace on GotDotNet.