public void GetDirectories_GreedyThenWordThenGreedy() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools"); this.GetFakeDirectory("tools", "frobuscator").GetDirectories("tests", SIO.SearchOption.TopDirectoryOnly).Returns(new[] { this.GetFakeDirectory("tools", "frobuscator", "tests") }); this.GetFakeDirectory("tools", "metamorphosator").GetDirectories("tests", SIO.SearchOption.TopDirectoryOnly).Returns(new[] { this.GetFakeDirectory("tools", "metamorphosator", "tests") }); var expected = new[] { this.GetFakeDirectory("tools", "frobuscator", "tests"), this.GetFakeDirectory("tools", "frobuscator", "tests", "abc"), this.GetFakeDirectory("tools", "frobuscator", "tests", "def"), this.GetFakeDirectory("tools", "metamorphosator", "tests"), this.GetFakeDirectory("tools", "metamorphosator", "tests", "v1"), this.GetFakeDirectory("tools", "metamorphosator", "tests", "v1", "tmp"), this.GetFakeDirectory("tools", "metamorphosator", "tests", "v2") }; var actual = finder.GetDirectories(baseDir, "**/tests/**"); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories("*", SIO.SearchOption.AllDirectories); this.GetFakeDirectory("tools", "frobuscator").Received().GetDirectories("tests", SIO.SearchOption.TopDirectoryOnly); this.GetFakeDirectory("tools", "metamorphosator").Received().GetDirectories("tests", SIO.SearchOption.TopDirectoryOnly); this.GetFakeDirectory("tools", "frobuscator", "tests").Received().GetDirectories("*", SIO.SearchOption.AllDirectories); this.GetFakeDirectory("tools", "metamorphosator", "tests").Received().GetDirectories("*", SIO.SearchOption.AllDirectories); }
public void GetDirectories_PatternIsEmpty() { var directory = Substitute.For <IDirectory>(); var sut = new DirectoryFinder(Substitute.For <IFileSystem>()); var directories = sut.GetDirectories(directory, string.Empty); Assert.That(directories, Has.Count.EqualTo(1)); Assert.That(directories.First(), Is.EqualTo(directory)); }
public void GetDirectories_WordWithWildcard_NoMatch(string pattern) { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools"); var result = finder.GetDirectories(baseDir, pattern); Assert.That(result, Is.Empty); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories(pattern, SIO.SearchOption.TopDirectoryOnly); }
public void GetDirectories_Parent() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools", "frobuscator"); var expected = new[] { this.GetFakeDirectory("tools") }; var actual = finder.GetDirectories(baseDir, "../"); CollectionAssert.AreEquivalent(expected, actual); baseDir.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); }
public void GetDirectories_Greedy_Tools() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools"); var expected = this.fakedDirectories.Values.Select(x => x.FullName).Where(x => x != GetRoot()); var result = finder.GetDirectories(baseDir, "**"); var actual = result.Select(x => x.FullName); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories("*", SIO.SearchOption.AllDirectories); this.GetFakeDirectory("tools", "frobuscator").DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); this.GetFakeDirectory("tools", "metamorphosator").DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); }
public void GetDirectories_Asterisk_Tools() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools"); var expected = new[] { CombinePath(baseDir.FullName, "metamorphosator"), CombinePath(baseDir.FullName, "frobuscator") }; var result = finder.GetDirectories(baseDir, "*"); var actual = result.Select(x => x.FullName); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories("*", SIO.SearchOption.TopDirectoryOnly); this.GetFakeDirectory("tools", "frobuscator").DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); this.GetFakeDirectory("tools", "metamorphosator").DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); }
public void GetDirectories_WordWithWildcard_MultipleMatches(string pattern) { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools", "metamorphosator", "tests"); baseDir.GetDirectories(pattern, SIO.SearchOption.TopDirectoryOnly).Returns(new IDirectory[] { this.GetFakeDirectory("tools", "metamorphosator", "tests", "v1"), this.GetFakeDirectory("tools", "metamorphosator", "tests", "v2") }); var expected = new[] { CombinePath(baseDir.FullName, "v1"), CombinePath(baseDir.FullName, "v2") }; var result = finder.GetDirectories(baseDir, pattern); var actual = result.Select(x => x.FullName); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories(pattern, SIO.SearchOption.TopDirectoryOnly); }
/// <summary> /// Find candidate extension assemblies starting from a /// given base directory. /// </summary> /// <param name="startDir"></param> private void FindExtensionAssemblies(DirectoryInfo startDir) { // First check the directory itself ProcessAddinsFiles(startDir, false); // Use any packages directory we find as well var packageDir = DirectoryFinder.GetPackageDirectory(startDir); if (packageDir != null) { foreach (var dir in DirectoryFinder.GetDirectories(packageDir, "NUnit.Extension.*/**/tools/")) { ProcessDirectory(dir, false); } } }
public void GetDirectories_MultipleComponents_AllDirectories(string pattern) { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.fakedDirectories[GetRoot()]; var expected = this.fakedDirectories.Values.Where(x => x != baseDir); var actual = finder.GetDirectories(baseDir, pattern); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories("*", SIO.SearchOption.AllDirectories); foreach (var dir in this.fakedDirectories.Values.Where(x => x != baseDir)) { dir.Received().GetDirectories("*", SIO.SearchOption.TopDirectoryOnly); } }
public void GetDirectories_ParentThenParentThenWordThenWord() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools", "frobuscator", "tests"); this.GetFakeDirectory("tools").GetDirectories("metamorphosator", SIO.SearchOption.TopDirectoryOnly).Returns(new[] { this.GetFakeDirectory("tools", "metamorphosator") }); this.GetFakeDirectory("tools", "metamorphosator").GetDirectories("addins", SIO.SearchOption.TopDirectoryOnly).Returns(new[] { this.GetFakeDirectory("tools", "metamorphosator", "addins") }); var expected = new[] { this.GetFakeDirectory("tools", "metamorphosator", "addins") }; var actual = finder.GetDirectories(baseDir, "../../metamorphosator/addins"); CollectionAssert.AreEquivalent(expected, actual); baseDir.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Parent.Parent.Received().GetDirectories("metamorphosator", SIO.SearchOption.TopDirectoryOnly); this.GetFakeDirectory("tools", "metamorphosator").Received().GetDirectories("addins", SIO.SearchOption.TopDirectoryOnly); }
/// <summary> /// Process a .addins type file. The file contains one entry per /// line. Each entry may be a directory to scan, an assembly /// path or a wildcard pattern used to find assemblies. Blank /// lines and comments started by # are ignored. /// </summary> private void ProcessAddinsFile(DirectoryInfo baseDir, string fileName, bool fromWildCard) { log.Info("Processing file " + fileName); using (var rdr = new StreamReader(fileName)) { while (!rdr.EndOfStream) { var line = rdr.ReadLine(); if (line == null) { break; } line = line.Split(new char[] { '#' })[0].Trim(); if (line == string.Empty) { continue; } if (Path.DirectorySeparatorChar == '\\') { line = line.Replace(Path.DirectorySeparatorChar, '/'); } bool isWild = fromWildCard || line.Contains("*"); if (line.EndsWith("/")) { foreach (var dir in DirectoryFinder.GetDirectories(baseDir, line)) { ProcessDirectory(dir, isWild); } } else { foreach (var file in DirectoryFinder.GetFiles(baseDir, line)) { ProcessCandidateAssembly(file.FullName, isWild); } } } } }
/// <summary> /// Process a .addins type file. The file contains one entry per /// line. Each entry may be a directory to scan, an assembly /// path or a wildcard pattern used to find assemblies. Blank /// lines and comments started by # are ignored. /// </summary> private void ProcessAddinsFile(DirectoryInfo baseDir, string fileName) { log.Info("Processing file " + fileName); using (var rdr = new StreamReader(fileName)) { while (!rdr.EndOfStream) { var line = rdr.ReadLine(); if (line == null) { break; } line = line.Split(new char[] { '#' })[0].Trim(); if (line == string.Empty) { continue; } if (Path.DirectorySeparatorChar == '\\') { line = line.Replace(Path.DirectorySeparatorChar, '/'); } if (line.EndsWith("/")) { foreach (var dir in DirectoryFinder.GetDirectories(baseDir, line)) { FindExtensionsInDirectory(dir); } } else { foreach (var file in DirectoryFinder.GetFiles(baseDir, line)) { FindExtensionsInAssembly(file.FullName, true); } } } } }
public void GetDirectories_MultipleComponents_MultipleMatches(string pattern) { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools", "metamorphosator"); var testsDir = this.GetFakeDirectory("tools", "metamorphosator", "tests"); var baseDirContent = new[] { testsDir }; var testsDirContent = new[] { this.GetFakeDirectory("tools", "metamorphosator", "tests", "v1"), this.GetFakeDirectory("tools", "metamorphosator", "tests", "v2") }; baseDir.GetDirectories("tests", SIO.SearchOption.TopDirectoryOnly).Returns(baseDirContent); baseDir.GetDirectories("te*", SIO.SearchOption.TopDirectoryOnly).Returns(baseDirContent); baseDir.GetDirectories("t?sts", SIO.SearchOption.TopDirectoryOnly).Returns(baseDirContent); testsDir.GetDirectories("v*", SIO.SearchOption.TopDirectoryOnly).Returns(testsDirContent); testsDir.GetDirectories("*", SIO.SearchOption.TopDirectoryOnly).Returns(testsDirContent); testsDir.GetDirectories("v?", SIO.SearchOption.TopDirectoryOnly).Returns(testsDirContent); var expected = new[] { CombinePath(baseDir.FullName, "tests", "v1"), CombinePath(baseDir.FullName, "tests", "v2") }; var result = finder.GetDirectories(baseDir, pattern); var actual = result.Select(x => x.FullName); CollectionAssert.AreEquivalent(expected, actual); }
public void GetDirectories_Greedy_Metamorphosator() { var finder = new DirectoryFinder(this.fileSystem); var baseDir = this.GetFakeDirectory("tools", "metamorphosator"); var expected = new[] { CombinePath(baseDir.FullName), CombinePath(baseDir.FullName, "addins"), CombinePath(baseDir.FullName, "tests"), CombinePath(baseDir.FullName, "tests", "v1"), CombinePath(baseDir.FullName, "tests", "v1", "tmp"), CombinePath(baseDir.FullName, "tests", "v2"), CombinePath(baseDir.FullName, "addins", "morph"), CombinePath(baseDir.FullName, "addins", "empty") }; var result = finder.GetDirectories(baseDir, "**"); var actual = result.Select(x => x.FullName); CollectionAssert.AreEquivalent(expected, actual); baseDir.Parent.DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); baseDir.Received().GetDirectories("*", SIO.SearchOption.AllDirectories); this.GetFakeDirectory("tools", "frobuscator").DidNotReceive().GetDirectories(Arg.Any <string>(), Arg.Any <SIO.SearchOption>()); }
public void GetFiles_PatternIsNull() { var finder = new DirectoryFinder(Substitute.For <IFileSystem>()); Assert.That(() => finder.GetDirectories(Substitute.For <IDirectory>(), null), Throws.ArgumentNullException.With.Message.Contains(" pattern ")); }
public void GetDirectories_StartDirectoryIsNull() { var finder = new DirectoryFinder(Substitute.For <IFileSystem>()); Assert.That(() => finder.GetDirectories((IDirectory)null, "notused"), Throws.ArgumentNullException.With.Message.Contains(" startDirectory ")); }
public void GetDirectories(string pattern, int count) { var dirList = DirectoryFinder.GetDirectories(_baseDir, pattern); Assert.That(dirList.Count, Is.EqualTo(count)); }