The Artima Developer Community
Sponsored Link

.NET Buzz Forum
FileAssert - comparing 2 binary files using NUnit

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Darrell Norton

Posts: 876
Nickname: dnorton
Registered: Mar, 2004

Darrell Norton is a consultant for CapTech Ventures.
FileAssert - comparing 2 binary files using NUnit Posted: Jul 20, 2004 12:39 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Darrell Norton.
Original Post: FileAssert - comparing 2 binary files using NUnit
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Darrell Norton
Latest Posts From Darrell Norton's Blog

Advertisement

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.


This Blog Hosted On: http://www.DotNetJunkies.com/

Read: FileAssert - comparing 2 binary files using NUnit

Topic: I, Robot Digs at WindowsUpdate? Previous Topic   Next Topic Topic: Download MSDN Magazine

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use