コード例 #1
0
        public void DoubleStarWithFilePattern()
        {
            var files = DataFactory.CreateFiles("C:/file0.log",
                                                "C:/root/file1.log",
                                                "C:/root/a/file2.log",
                                                "C:/root/a/b/file3.txt",
                                                "C:/root/a/b/file4.log",
                                                "C:/root/a/b/c/file5.log",
                                                "C:/root/a/b/c/file6.txt",
                                                "C:/root/a/d/file7.log").ToList();

            var mock = FileSystemMock.Create();
            files.ForEach(mock.BaseFileSystemHelper.AddFile);

            const string pattern = "C:/root/**/*.log";
            var fileSystemHelper = new FileSystemHelper(mock.Object);
            var actual = fileSystemHelper.FindFilesWildcard(pattern);
            var expected = new List<string>
            {
                //"C:/file0.log",
                "C:/root/file1.log",
                "C:/root/a/file2.log",
                //"C:/root/a/b/file3.txt",
                "C:/root/a/b/file4.log",
                "C:/root/a/b/c/file5.log",
                //"C:/root/a/b/c/file6.txt",
                "C:/root/a/d/file7.log",
            }.OrderBy(new PathSorter()).ToList();

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void Archive()
        {
            const string archiveFileName        = "archive.zip";
            const string archiveRootFolder      = "C:/io_testing";
            const string archiveOutputPath      = archiveRootFolder + "/" + archiveFileName;
            const string archiveFolder          = archiveRootFolder + "/files";
            const string fileName1              = archiveFolder + "/file1.txt";
            const string fileName2              = archiveFolder + "/file2.txt";
            const string fileName3              = archiveFolder + "/subfolder/file3.txt";

            var files = DataFactory.CreateFiles(fileName1,
                                                fileName2,
                                                fileName3).ToList();
            
            var fileSystem = new FileSystem();
            var directoryManager = new FileSystemHelper(fileSystem);
            if (fileSystem.DirExists(archiveRootFolder))
                fileSystem.DeleteDir(archiveRootFolder, true);
            files.ForEach(directoryManager.AddFile);
            var sut = new ZipFileCompressorMock(fileSystem);

            sut.CreateFromDirectory(archiveFolder, archiveOutputPath);

            Assert.IsTrue(fileSystem.FileExists(archiveOutputPath));
            
            var file = directoryManager.GetFile(archiveOutputPath);
            Assert.AreEqual(archiveFileName, file.Name);
            Assert.AreEqual(archiveOutputPath, file.Path);
            //Assert.IsInstanceOfType(file, typeof(ZipFileMock));
            //var zipFile = (ZipFileMock)file;
            //Assert.AreEqual(files.Count, zipFile.FileCount);
        }
コード例 #3
0
        public void GetStructure_WindowsUsersFolder()
        {
            const string dirPath = "C:/Users";
            var fileSystem = new FileSystem();
            var sut = new FileSystemHelper(fileSystem);
            var structure = sut.GetStructure(dirPath);

            Assert.IsNotNull(structure);
            Assert.AreEqual(1, structure.Count);
            Assert.IsTrue(structure.ContainsKey(dirPath));
        }
コード例 #4
0
        public void ArchiveAndUnarchive()
        {
            const string archiveFileName        = "archive.zip";
            const string archiveRootFolder      = "C:/io_testing";
            const string archiveOutputPath      = archiveRootFolder + "/" + archiveFileName;
            const string archiveFolder          = archiveRootFolder + "/files";
            const string fileName1              = archiveFolder + "/file1.txt";
            const string fileName2              = archiveFolder + "/file2.txt";
            const string fileName3              = archiveFolder + "/subfolder/file3.txt";

            var files = DataFactory.CreateFiles(fileName1,
                                                fileName2,
                                                fileName3).ToList();

            var fileSystem = new FileSystem();
            var directoryManager = new FileSystemHelper(fileSystem);
            if (fileSystem.DirExists(archiveRootFolder))
                fileSystem.DeleteDir(archiveRootFolder, true);
            files.ForEach(directoryManager.AddFile);
            var sut = new ZipFileCompressorMock(fileSystem);

            var zipFile = sut.CreateFromDirectory(archiveFolder, archiveOutputPath);
            Assert.IsTrue(fileSystem.FileExists(archiveOutputPath));

            //var file = directoryManager.GetFile(archiveOutputPath);
            //Assert.AreEqual(archiveFileName, file.Name);
            //Assert.AreEqual(archiveOutputPath, file.Path);
            //Assert.IsInstanceOfType(file, typeof(ZipFileMock));
            //var zipFile = (ZipFileMock)file;

            Assert.AreEqual(files.Count, zipFile.FileCount);


            const string unarchiveOutputFolder = archiveRootFolder + "/output";

            var i = 0;
            //var extractedFiles = ZipFileMock.Unarchive(file.Bytes, unarchiveOutputFolder);
            var extractedFiles = sut.ExtractToDirectory(archiveOutputPath, unarchiveOutputFolder);
            foreach (var extractedFile in extractedFiles)
            {
                var f = files[i++];
                var relativePath = PathHelper.Subtract(f.Path, archiveFolder);
                var expectedPath = PathHelper.Combine(unarchiveOutputFolder, relativePath);
                Assert.AreEqual(expectedPath, extractedFile.Path);
                Assert.AreEqual(f.Name, extractedFile.Name);
                Assert.AreEqual(f.Content, extractedFile.Content);
            }
        }
コード例 #5
0
 public ZipFileCompressorMock(IFileSystem fileSystem)
 {
     _fileSystem = fileSystem;
     _fileSystemHelper = new FileSystemHelper(_fileSystem);
 }
コード例 #6
0
        public void CopyDir()
        {
            const string sourceDirName          = "C:/root/a";
            const string targetDirName          = "C:/root/x";
            const bool overwrite                = true;

            var files = DataFactory.CreateFiles("C:/file0.log",
                                                "C:/root/file1.log",
                                                "C:/root/a/file2.log",
                                                "C:/root/a/b/file3.txt",
                                                "C:/root/a/b/file4.log",
                                                "C:/root/a/b/c/file5.log",
                                                "C:/root/a/b/c/file6.txt",
                                                "C:/root/a/b/c/assembly.dll",
                                                "C:/root/a/d/file7.log").ToList();

            var mock = FileSystemMock.Create();
            files.ForEach(mock.BaseFileSystemHelper.AddFile);

            var fileSystemHelper = new FileSystemHelper(mock.Object);
            fileSystemHelper.CopyDir(sourceDirName, targetDirName, overwrite);

            var actual = fileSystemHelper.FindFilesWildcard("C:/**");

            var expected = new List<string>
            {
                "C:/file0.log",
                "C:/root/file1.log",
                "C:/root/a/file2.log",
                "C:/root/a/b/file3.txt",
                "C:/root/a/b/file4.log",
                "C:/root/a/b/c/file5.log",
                "C:/root/a/b/c/file6.txt",
                "C:/root/a/b/c/assembly.dll",
                "C:/root/a/d/file7.log",

                "C:/root/x/file2.log",
                "C:/root/x/b/file3.txt",
                "C:/root/x/b/file4.log",
                "C:/root/x/b/c/file5.log",
                "C:/root/x/b/c/file6.txt",
                "C:/root/x/b/c/assembly.dll",
                "C:/root/x/d/file7.log",
            }.OrderBy(new PathSorter()).ToList();

            Assert.AreEqual(expected.Count, actual.Count);
            CollectionAssert.AreEqual(expected, actual);
        }