Exemplo n.º 1
0
        public async Task GetFoldersAsObservableStaticMethodAsync()
        {
            var    sys            = new MemoryFileSystemFake();
            string foundFilePath1 = PortablePath.Combine("A");
            string foundFilePath2 = PortablePath.Combine("A", "B");
            string foundFilePath3 = PortablePath.Combine("A", "C");

            sys.AddFilesAndFolders(x => x
                                   .Folder("A", a => a
                                           .Folder("B", b => b)
                                           .Folder("C", c => c)));

            IObservable <string> filesObservable = await sys.GetFoldersAsObservableAsync(@"**\*");

            List <string> files = new List <string>();

            filesObservable
            .Finally(() =>
            {
                Assert.That(files.Count, Is.EqualTo(3));
                Assert.That(files, Has.Member(foundFilePath1));
                Assert.That(files, Has.Member(foundFilePath2));
                Assert.That(files, Has.Member(foundFilePath3));
            })
            .Subscribe(filePath => files.Add(filePath));
        }
Exemplo n.º 2
0
        public async Task GetFilesStaticMethod()
        {
            var          sys            = new MemoryFileSystemFake();
            const string foundFileName  = "IncludedFile.Txt";
            string       foundFilePath2 = PortablePath.Combine("A", foundFileName);
            string       foundFilePath3 = PortablePath.Combine("A", "B", foundFileName);
            string       foundFilePath4 = PortablePath.Combine("A", "C", foundFileName);

            sys.AddFilesAndFolders(x => x
                                   .File(foundFileName)
                                   .Folder("A", a => a
                                           .File(foundFileName)
                                           .Folder("B", b => b
                                                   .File(foundFileName))
                                           .Folder("C", c => c
                                                   .File(foundFileName))));

            List <string> files = (await sys.GetFilesAsync(@"**\*")).ToList();

            Assert.That(files.Count, Is.EqualTo(4));
            Assert.That(files, Has.Member(foundFileName));
            Assert.That(files, Has.Member(foundFilePath2));
            Assert.That(files, Has.Member(foundFilePath3));
            Assert.That(files, Has.Member(foundFilePath4));
        }
Exemplo n.º 3
0
        public async Task CaseInsensitiveFileMatch()
        {
            var          sys            = new MemoryFileSystemFake();
            const string foundFileName  = "IncludedFile.txt";
            string       foundFilePath2 = PortablePath.Combine("A", foundFileName);
            string       foundFilePath3 = PortablePath.Combine("B", foundFileName);
            string       foundFilePath4 = PortablePath.Combine("B", "C", foundFileName);

            sys.AddFilesAndFolders(x => x
                                   .File(foundFileName)
                                   .Folder("A", a => a
                                           .File("ExcludedFile.txt")
                                           .File(foundFileName))
                                   .Folder("B", b => b
                                           .File(foundFileName)
                                           .File("ExcludedFile.txt")
                                           .Folder("C", c => c
                                                   .File(foundFileName)
                                                   .File("ExcludedFile.txt")
                                                   ))
                                   .Folder("Z", z => z
                                           .File("ExcludedFile.txt")));
            var fs = new FileSet(sys, "/");

            fs.Include(@"**\" + foundFileName.ToLower());
            List <string> files = (await fs.GetFilesAsync()).ToList();

            Assert.That(files.Count, Is.EqualTo(4));
            Assert.That(files, Has.Member(foundFileName));
            Assert.That(files, Has.Member(foundFilePath2));
            Assert.That(files, Has.Member(foundFilePath3));
            Assert.That(files, Has.Member(foundFilePath4));
        }
Exemplo n.º 4
0
        public async Task IncludeAllFoldersInTree()
        {
            var          sys = new MemoryFileSystemFake();
            const string folderNameToFind1 = "Folder1";
            const string folderNameToFind2 = "Folder2";
            const string folderNameToFind3 = "Folder3";
            const string folderNameToFind4 = "Folder4";
            const string folderNameToFind5 = "Folder5";
            string       folderPathToFind3 = PortablePath.Combine(folderNameToFind2, folderNameToFind3);
            string       folderPathToFind4 = PortablePath.Combine(folderNameToFind2, folderNameToFind4);

            sys.AddFilesAndFolders(x => x
                                   .Folder(folderNameToFind1, a => a)
                                   .Folder(folderNameToFind2, a => a
                                           .Folder(folderNameToFind3, b => b)
                                           .Folder(folderNameToFind4, b => b))
                                   .Folder(folderNameToFind5, c => c));
            var fs = new FileSet(sys, "/");

            fs.Include(@"**\*");
            List <string> files = (await fs.GetFoldersAsync()).ToList();

            Assert.That(files.Count, Is.EqualTo(5));
            Assert.That(files, Has.Member(folderNameToFind1));
            Assert.That(files, Has.Member(folderNameToFind2));
            Assert.That(files, Has.Member(folderPathToFind3));
            Assert.That(files, Has.Member(folderPathToFind4));
            Assert.That(files, Has.Member(folderNameToFind5));
        }
Exemplo n.º 5
0
        public async Task GetFoldersWithBaseFolderStaticMethod()
        {
            var    sys            = new MemoryFileSystemFake();
            string foundFilePath1 = PortablePath.Combine("B");
            string foundFilePath2 = PortablePath.Combine("C");

            sys.AddFilesAndFolders(x => x
                                   .Folder("A", a => a
                                           .Folder("B", b => b)
                                           .Folder("C", c => c)));

            List <string> files = (await sys.GetFoldersAsync(@"**\*", basePath: @"\A")).ToList();

            Assert.That(files.Count, Is.EqualTo(2));
            Assert.That(files, Has.Member(foundFilePath1));
            Assert.That(files, Has.Member(foundFilePath2));
        }
Exemplo n.º 6
0
        public async Task CaseInsensitiveFolderMatchGettingFolders()
        {
            var          sys              = new MemoryFileSystemFake();
            const string ignoredFileName  = "IncludedFile.Txt";
            string       foundFolderPath1 = PortablePath.Combine("A", "zxcASDFqwe");
            string       foundFolderPath2 = PortablePath.Combine("A", "qweASDFzxc");
            string       foundFolderPath3 = PortablePath.Combine("C", "zxcASDFqwe");
            string       foundFolderPath4 = PortablePath.Combine("C", "zxcASDFqwe", "zzzASDFzzz");
            string       foundFolderPath5 = PortablePath.Combine("C", "zxcASDFqwe", "qweASDFzxc");

            sys.AddFilesAndFolders(x => x
                                   .File(ignoredFileName)
                                   .Folder("A", a => a
                                           .File(ignoredFileName)
                                           .Folder("zxcASDFqwe", zxc => zxc
                                                   .File(ignoredFileName))
                                           .Folder("B", b => b
                                                   .File(ignoredFileName))
                                           .Folder("qweASDFzxc", qwe => qwe
                                                   .File(ignoredFileName)))
                                   .Folder("C", c => c
                                           .File(ignoredFileName)
                                           .Folder("zxcASDFqwe", zxc => zxc
                                                   .File(ignoredFileName)
                                                   .Folder("zzzASDFzzz", zzz => zzz
                                                           .File(ignoredFileName))
                                                   .Folder("D", d => d
                                                           .File(ignoredFileName))
                                                   .Folder("qweASDFzxc", qwe => qwe
                                                           .File(ignoredFileName))))
                                   .Folder("Z", z => z
                                           .File("ExcludedFile.txt")));
            var fs = new FileSet(sys, "/");

            fs.Include(@"**\*asdf*");
            List <string> folders = (await fs.GetFoldersAsync()).ToList();

            Assert.That(folders.Count, Is.EqualTo(5));
            Assert.That(folders, Has.Member(foundFolderPath1));
            Assert.That(folders, Has.Member(foundFolderPath2));
            Assert.That(folders, Has.Member(foundFolderPath3));
            Assert.That(folders, Has.Member(foundFolderPath4));
            Assert.That(folders, Has.Member(foundFolderPath5));
        }
Exemplo n.º 7
0
        public async Task MatchOnFolderAfterStarStarWithAnotherStarStar()
        {
            var          sys             = new MemoryFileSystemFake();
            const string folderToMatchOn = "FolderToMatchOn";
            const string foundFileName1  = "IncludedFile.1zz";
            const string foundFileName2  = "IncludedFile.2zz";
            const string foundFileName3  = "IncludedFile.3zz";
            const string foundFileName4  = "IncludedFile.4zz";
            string       foundFilePath1  = PortablePath.Combine("B", "C", folderToMatchOn, foundFileName1);
            string       foundFilePath2  = PortablePath.Combine("B", "C", folderToMatchOn, "D", foundFileName2);
            string       foundFilePath3  = PortablePath.Combine("B", "C", folderToMatchOn, "D", "E", foundFileName3);
            string       foundFilePath4  = PortablePath.Combine("B", "C", folderToMatchOn, "F", foundFileName4);

            sys.AddFilesAndFolders(x => x
                                   .Folder("A", a => a
                                           .File("ExcludedFile.txt"))
                                   .Folder("B", b => b
                                           .File("ExcludedFile.xzz")
                                           .Folder("C", c => c
                                                   .Folder(folderToMatchOn, d => d
                                                           .File(foundFileName1)
                                                           .Folder("D", e => e
                                                                   .File("ExcludedFile.a1z")
                                                                   .File(foundFileName2)
                                                                   .Folder("E", f => f
                                                                           .File(foundFileName3)))
                                                           .Folder("F", f => f
                                                                   .File("ExcludedFile.txt")
                                                                   .File(foundFileName4))
                                                           .File("AnotherExcludedFile.txt")
                                                           )))
                                   .Folder("Z", z => z
                                           .File("ExcludedFile.txt")));
            var fs = new FileSet(sys, "/");

            fs.Include(@"**\" + folderToMatchOn + @"\**\*.?zz");
            List <string> files = (await fs.GetFilesAsync()).ToList();

            Assert.That(files.Count, Is.EqualTo(4));
            Assert.That(files, Has.Member(foundFilePath1));
            Assert.That(files, Has.Member(foundFilePath2));
            Assert.That(files, Has.Member(foundFilePath3));
            Assert.That(files, Has.Member(foundFilePath4));
        }
Exemplo n.º 8
0
        public async Task BasePathSupportsDotDotAndDotFolders()
        {
            var          sys           = new MemoryFileSystemFake();
            const string foundFileName = "IncludedFile.Txt";

            sys.AddFilesAndFolders(x => x
                                   .File(foundFileName)
                                   .Folder("A", a => a
                                           .File(foundFileName)
                                           .Folder("B", b => b
                                                   .File(foundFileName))
                                           .Folder("C", c => c
                                                   .File(foundFileName)))
                                   .Folder("D", d => d
                                           .File(foundFileName)
                                           .Folder("E", e => e
                                                   .File(foundFileName))
                                           .Folder("F", f => f
                                                   .File(foundFileName)))
                                   .Folder("G", g => g
                                           .File(foundFileName)));
            var fs1 = new FileSet(sys, @"A\C\..\B\..\..\.\D\E\.\..\.\F");

            fs1.Include(@"*");
            List <string> files = (await fs1.GetFilesAsync()).ToList();

            Assert.That(files.Count, Is.EqualTo(1));
            Assert.That(files, Has.Member(foundFileName));

            string foundFilePath1 = PortablePath.Combine("E", foundFileName);
            string foundFilePath2 = PortablePath.Combine("F", foundFileName);
            var    fs2            = new FileSet(sys, @"A\C\..\B\..\..\.\D\E\.\..\.");

            fs2.Include(@"*\*");
            files = (await fs2.GetFilesAsync()).ToList();

            Assert.That(files.Count, Is.EqualTo(2));
            Assert.That(files, Has.Member(foundFilePath1));
            Assert.That(files, Has.Member(foundFilePath2));
        }