public void EnumerateFiles( [Values( //nameof(FastDirectoryEnumeratorScanner), // causes stackoverflow nameof(FastFileInfoScanner), //nameof(DirectoryEnumerationAsyncScanner), // Had a hardcoded SearchOption.TopDirectoryOnly. but after the fix still has errors nameof(DirectoryTreeWalkerScanner) )] string implementation, [Values( @"c:\program files", @"c:\program files (x86)" )] string path, [Values( @"*.*", @"*.exe", @"*.notexisting" )] string searchPattern ) { // Arrange var sut = ImplementationFactory.CreateInstance(implementation); var referenceImplementation = new BuiltInDirectoryScanner(); // Act var actual = sut.EnumerateFiles(path, searchPattern).ToList(); // Assert var expected = referenceImplementation.EnumerateFiles(path, searchPattern).ToList(); Assert.AreEqual(expected.Count, actual.Count); // TODO: Check filenames, filesizes for equality }
private static void SearchDirectory(ConsoleUI consoleUI) { while (true) { var benchMark = new DirectoryScannerBenchMark(); var implementationProvider = new BenchmarkBasedImplementationProvider(benchMark); consoleUI.DisplayImplementationMenu(implementationProvider); var index = consoleUI.GetMenuChoice(); if (index == 0) { return; } var typeName = implementationProvider.GetImplementations().Keys.OrderBy(k => k).ToArray()[index - 1]; var implementation = ImplementationFactory.CreateInstance(typeName); var rootFolder = consoleUI.GetInput("Please specify root folder", "c:\\program files"); var searchPattern = consoleUI.GetInput("Please specify searchPattern", "*.exe"); Console.WriteLine($"\r\nImplementation:\t{typeName}"); Console.WriteLine($"Root folder:\t{rootFolder}"); Console.WriteLine($"Search pattern:\t{searchPattern}"); var w = new Stopwatch(); w.Start(); var count = implementation.EnumerateFiles(rootFolder, searchPattern).Count(); //Thread.Sleep(1000); w.Stop(); Console.WriteLine($"\r\nFound {count} file(s). Operation took {w.ElapsedMilliseconds} msecs."); Console.WriteLine(@"Press any key to continue"); Console.ReadKey(); } }