Example #1
0
        public void TestGlobExpressions(string pattern, string positiveMatch, string negativeMatch = null)
        {
            var parser   = new Parser(pattern);
            var segments = parser.ParseTree().Segments;

            var mockFileDatas = new Dictionary <string, MockFileData>();

            if (positiveMatch != null)
            {
                mockFileDatas[Path.Combine(FileSystemRoot, positiveMatch)] = MockFileData.NullObject;
            }

            if (negativeMatch != null)
            {
                mockFileDatas[Path.Combine(FileSystemRoot, negativeMatch)] = MockFileData.NullObject;
            }

            var cache = new MockTraverseOptions(true, true, false, new MockFileSystem(mockFileDatas));

            var root    = new DirectoryInfo(FileSystemRoot);
            var results = PathTraverser.Traverse(root, segments, cache).ToArray();

            if (positiveMatch != null)
            {
                Assert.Single(results);
            }

            if (positiveMatch == null && negativeMatch != null)
            {
                Assert.Empty(results);
            }
        }
Example #2
0
        public void CanAddPaths()
        {
            var windowsPath  = Path.Combine(FileSystemRoot, "Windows");
            var system32Path = Path.Combine(windowsPath, "System32");

            var mockFiles = new Dictionary <string, MockFileData>
            {
                [Path.Combine(windowsPath, "Notepad.exe")]  = MockFileData.NullObject,
                [Path.Combine(windowsPath, "explorer.exe")] = MockFileData.NullObject,
                [Path.Combine(system32Path, "at.exe")]      = MockFileData.NullObject,
            };
            var mockFileSystem = new MockFileSystem(mockFiles);
            var options        = new MockTraverseOptions(false, false, false, mockFileSystem);

            var directories = options.GetDirectories(new DirectoryInfo(FileSystemRoot));

            Assert.Collection(directories, info => Assert.Equal(windowsPath, info.FullName));

            var directories2 = options.GetDirectories(new DirectoryInfo(windowsPath));

            Assert.Collection(directories2, info => Assert.Equal(system32Path, info.FullName));

            var files = options.GetFiles(new DirectoryInfo(windowsPath));

            Assert.Collection(files,
                              info => Assert.Equal(Path.Combine(windowsPath, "Notepad.exe"), info.FullName),
                              info => Assert.Equal(Path.Combine(windowsPath, "explorer.exe"), info.FullName)
                              );
        }
Example #3
0
        public void TestGlobExpressionsWithEmitDirectories(string pattern, string files, string matches)
        {
            var parser   = new Parser(pattern);
            var segments = parser.ParseTree().Segments;

            var mockFileDatas = new Dictionary <string, MockFileData>();

            foreach (var file in files.Split(' '))
            {
                mockFileDatas[Path.Combine(FileSystemRoot, file)] = MockFileData.NullObject;
            }

            var cache = new MockTraverseOptions(false, true, true, new MockFileSystem(mockFileDatas));

            var root        = new DirectoryInfo(FileSystemRoot);
            var results     = PathTraverser.Traverse(root, segments, cache).Select(file => file.FullName.Substring(FileSystemRoot.Length)).OrderBy(x => x).ToArray();
            var fileMatches = matches.Split(' ').Select(x => x.Replace('\\', Path.DirectorySeparatorChar)).OrderBy(x => x).ToArray();

            Assert.Equal(fileMatches, results);
        }
Example #4
0
        public void CanAddPaths()
        {
            var options = new MockTraverseOptions(false, false, false, new MockFileSystem(new Dictionary <string, MockFileData>
            {
                ["c:/Windows/Notepad.exe"]     = MockFileData.NullObject,
                ["c:/Windows/explorer.exe"]    = MockFileData.NullObject,
                ["c:/Windows/System32/at.exe"] = MockFileData.NullObject,
            }));

            var directories = options.GetDirectories(new DirectoryInfo("C:\\"));

            Assert.Collection(directories, info => Assert.Equal("c:\\Windows", info.FullName));

            var directories2 = options.GetDirectories(new DirectoryInfo("C:\\Windows"));

            Assert.Collection(directories2, info => Assert.Equal("c:\\Windows\\System32", info.FullName));

            var files = options.GetFiles(new DirectoryInfo("C:\\Windows"));

            Assert.Collection(files,
                              info => Assert.Equal("c:\\Windows\\Notepad.exe", info.FullName),
                              info => Assert.Equal("c:\\Windows\\explorer.exe", info.FullName)
                              );
        }