Ejemplo n.º 1
0
        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));
                }
            }
        }
Ejemplo n.º 2
0
        public static void TestArchiveInfoNullParams(
            ArchiveInfo archiveInfo,
            string dirA,
            string dirB,
            string[] files)
        {
            Exception caughtEx = null;

            try
            {
                archiveInfo.PackFiles(null, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(null, files, new string[] { });
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentOutOfRangeException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFileSet(dirA, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(null, files, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(FileNotFoundException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(dirA, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(dirA, files, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);

            caughtEx = null;
            try
            {
                archiveInfo.CopyTo(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.CopyTo(null, true);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.MoveTo(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.GetFiles(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFile(null, "test.txt");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFile("test.txt", null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(null, dirB, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, null, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, dirB, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, dirB, new string[] { });
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentOutOfRangeException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFileSet(null, dirB);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
        }