public void TestFindFilesWildcardRelativeDirectory(string filePath, string fileMask, string expectedFileNames, int expectedFileCount)
        {
            // Get the full path to the LinuxTestFiles directory, 3 levels up from the cpuinfo test file
            var cpuInfoFile = FileRefs.GetTestFile(filePath);

            var currentDirectory = cpuInfoFile.Directory;

            if (currentDirectory == null)
            {
                Assert.Fail("Cannot determine the parent directory of " + cpuInfoFile.FullName);
            }

            for (var parentCount = 1; parentCount < 3; parentCount++)
            {
                var parentCandidate = currentDirectory.Parent;
                if (parentCandidate == null)
                {
                    Assert.Fail("Cannot determine the parent directory of " + currentDirectory.FullName);
                }

                currentDirectory = parentCandidate;
            }

            TestFindFilesWildcardWork(currentDirectory.FullName, fileMask, expectedFileNames, true, expectedFileCount);
        }
示例#2
0
        public void TestGZipCompressExplicitDirectory(string filePath, bool includeMetadata, long expectedSizeBytes)
        {
            var fileToCompress = FileRefs.GetTestFile(filePath);

            var tempDirectoryPath = Path.GetTempPath();
            var startTime         = DateTime.UtcNow;

            if (includeMetadata)
            {
                Console.WriteLine("Compressing {0} using GZipCompressWithMetadata to create a .gz file in {1}", fileToCompress, tempDirectoryPath);
                PRISM.FileTools.GZipCompressWithMetadata(fileToCompress, tempDirectoryPath);
            }
            else
            {
                Console.WriteLine("Compressing {0} using GZipCompress to create a .gz file in {1}", fileToCompress, tempDirectoryPath);
                PRISM.FileTools.GZipCompress(fileToCompress, tempDirectoryPath);
            }

            var procTimeSeconds = DateTime.UtcNow.Subtract(startTime).TotalSeconds;

            var compressedFile = new FileInfo(Path.Combine(tempDirectoryPath, fileToCompress.Name + ".gz"));

            if (!compressedFile.Exists)
            {
                Assert.Fail("Compressed file not found: " + compressedFile.FullName);
            }

            Console.WriteLine("Compressed {0} in {1:F1} seconds to create {2}", fileToCompress, procTimeSeconds, compressedFile.FullName);
            Console.WriteLine(".gz file size: {0:#,###} bytes", compressedFile.Length);

            // Validate the newly created .gz file, then delete it and delete the validated round-robin file
            ValidateGZipFile(fileToCompress, compressedFile, tempDirectoryPath, expectedSizeBytes, includeMetadata, true);
        }
示例#3
0
        public void TestGZipCompressDefaultName(string filePath, bool includeMetadata, long expectedSizeBytes)
        {
            var fileToCompressRemote = FileRefs.GetTestFile(filePath);

            var tempDirectoryPath   = Path.GetTempPath();
            var fileToCompressLocal = new FileInfo(Path.Combine(tempDirectoryPath, fileToCompressRemote.Name));

            fileToCompressRemote.CopyTo(fileToCompressLocal.FullName, true);

            var startTime = DateTime.UtcNow;

            if (includeMetadata)
            {
                Console.WriteLine("Compressing {0} using GZipCompressWithMetadata", fileToCompressLocal);
                PRISM.FileTools.GZipCompressWithMetadata(fileToCompressLocal);
            }
            else
            {
                Console.WriteLine("Compressing {0} using GZipCompress", fileToCompressLocal);
                PRISM.FileTools.GZipCompress(fileToCompressLocal);
            }

            var procTimeSeconds = DateTime.UtcNow.Subtract(startTime).TotalSeconds;

            var compressedFile = new FileInfo(Path.Combine(tempDirectoryPath, fileToCompressLocal.Name + ".gz"));

            if (!compressedFile.Exists)
            {
                Assert.Fail("Compressed file not found: " + compressedFile.FullName);
            }

            Console.WriteLine("Compressed {0} in {1:F1} seconds to create {2}", fileToCompressLocal, procTimeSeconds, compressedFile.FullName);
            Console.WriteLine(".gz file size: {0:#,###} bytes", compressedFile.Length);

            PRISM.ProgRunner.SleepMilliseconds(250);

            // Rename the file that we just compressed
            // This is required to avoid collisions when we call ValidateGZipFile

            var movedFileToCompress = new FileInfo(fileToCompressLocal.FullName + ".original");

            if (File.Exists(movedFileToCompress.FullName))
            {
                File.Delete(movedFileToCompress.FullName);
            }

            File.Move(fileToCompressLocal.FullName, movedFileToCompress.FullName);

            // Refresh movedFileToCompress but do not refresh fileToCompressLocal (since we only want movedFileToCompress to end in .original)
            movedFileToCompress.Refresh();

            // Validate the newly created .gz file, then delete it and delete the validated round-robin file
            ValidateGZipFile(fileToCompressLocal, compressedFile, tempDirectoryPath, expectedSizeBytes, includeMetadata, false);

            movedFileToCompress.Delete();
        }
 private FileInfo VerifyTestFile(string filePath)
 {
     return(FileRefs.GetTestFile(filePath));
 }