public static void TestTruncatedArchive( ArchiveInfo archiveInfo, Type expectedExceptionType) { for (long len = archiveInfo.Length - 1; len >= 0; len--) { string testArchive = String.Format("{0}.{1:d06}", archiveInfo.FullName, len); if (File.Exists(testArchive)) { File.Delete(testArchive); } archiveInfo.CopyTo(testArchive); using (FileStream truncateStream = File.Open(testArchive, FileMode.Open, FileAccess.ReadWrite)) { truncateStream.SetLength(len); } ArchiveInfo testArchiveInfo = (ArchiveInfo)archiveInfo.GetType() .GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { testArchive }); Exception caughtEx = null; try { testArchiveInfo.GetFiles(); } catch (Exception ex) { caughtEx = ex; } File.Delete(testArchive); if (caughtEx != null) { Assert.IsInstanceOfType(caughtEx, expectedExceptionType, String.Format("Caught exception listing archive truncated to {0}/{1} bytes", len, archiveInfo.Length)); } } }