Beispiel #1
0
        public void ExcludingSystem_WillNotShowNSystem()
        {
            const string dll = "system.core";
            // check it's found:
            var logger = Substitute.For <ILogger>();
            var thisProjectbasePath = Path.Combine(GetProjectDir(), "../../..");
            var sut    = new DependencyCrawler(logger);
            var result = sut.Crawl(thisProjectbasePath);

            if (!result.References.Any(r => r.Name.IndexOf(dll, StringComparison.InvariantCultureIgnoreCase) > -1))
            {
                Assert.Inconclusive(dll + " is not used - so this test is no good!");
            }
            // This is only to ensure the dll is really referenced!!!


            var settings = Substitute.For <ICrawlerSettings>();

            settings.LibraryNameExcludesRegex.Returns(new[] {
                new Regex(dll, RegexOptions.IgnoreCase | RegexOptions.Compiled)
            });
            sut    = new DependencyCrawler(logger, settings);
            result = sut.Crawl(thisProjectbasePath);
            result.References.Any(r => r.Name.IndexOf(dll, StringComparison.InvariantCultureIgnoreCase) > -1).Should().Be(false);
        }
Beispiel #2
0
        public void GivenOnlyOneSolution_TheSolutionWillBeParsed()
        {
            var logger = Substitute.For <ILogger>();
            var thisProjectbasePath = Path.Combine(GetProjectDir(), "../../..");
            var settings            = Substitute.For <ICrawlerSettings>();

            settings.PathExcludesRegex.Returns(new[] {
                new Regex("^((?!Crawler.sln).)*$", RegexOptions.IgnoreCase | RegexOptions.Compiled) //negative lookahead - exclude everything but crawler.sln
            });
            var sut    = new DependencyCrawler(logger, settings);
            var result = sut.Crawl(thisProjectbasePath);

            result.Projects.Count().Should().Be(0, "No project matches crawler.sln");
            result.Solutions.Count().Should().Be(1, "only crawler.sln matches crawler.sln");
            result.Solutions.Single().Path.EndsWith("crawler.sln", System.StringComparison.InvariantCultureIgnoreCase);
        }
Beispiel #3
0
        public void CrawlingThisStructure_CrawlerReferencesContractsAsProjectRef()
        {
            var logger = Substitute.For <ILogger>();
            var thisProjectbasePath = Path.Combine(GetProjectDir(), "../../..");
            var crawlerProjectPath  = Path.GetFullPath(Path.Combine(GetProjectDir(), "../Crawler/Crawler.csproj"));

            File.Exists(crawlerProjectPath).Should().BeTrue("It's a prerequisite this project exists");

            var sut    = new DependencyCrawler(logger);
            var actual = sut.Crawl(thisProjectbasePath);

            var crawlerProj = actual.Projects.Single(x => x.Path.Equals(crawlerProjectPath, StringComparison.InvariantCultureIgnoreCase));

            crawlerProj.LibraryReferences.FirstOrDefault(l => l.HintPath.Contains($"{typeof(ICrawler).Assembly.GetName().Name}.dll"))
            .Should().BeNull("the dll should no longer be there");

            crawlerProj.ProjectReferences.FirstOrDefault(p => Path.GetFileName(p.Path).Equals("Contracts.csproj", StringComparison.InvariantCultureIgnoreCase))
            .Should().NotBeNull("the project is now referenced");
        }
Beispiel #4
0
        public void CrawlingThisStructure_GetsNoErrors()
        {
            var logger = Substitute.For <ILogger>();
            var thisProjectbasePath = Path.Combine(GetProjectDir(), "../../..");
            var sut    = new DependencyCrawler(logger);
            var result = sut.Crawl(thisProjectbasePath);

            var thisSolution = Path.GetFileNameWithoutExtension(Directory.GetFiles(Path.Combine(GetProjectDir(), "../"), "*.sln").Single());

            result.Solutions.FirstOrDefault(x => x.Name.Equals(thisSolution)).Should().NotBeNull("this Solution");

            var thisProjectOutPath = Path.Combine(
                Path.GetFullPath(Path.Combine(GetProjectDir(), "bin/debug")),
                $"{GetType().Assembly.GetName().Name}.dll");
            var allOutPaths = result.Projects.SelectMany(p => p.OutputPaths);

            allOutPaths.FirstOrDefault(x => x.Equals(thisProjectOutPath, StringComparison.InvariantCultureIgnoreCase))
            .Should().NotBeNull("this project");
        }
Beispiel #5
0
        static int Main(string[] args)
        {
            var showHelp    = false;
            var verbose     = false;
            var startFolder = string.Empty;
            var targetFile  = string.Empty;
            var appName     = Path.GetFileName(typeof(Program).Assembly.Location);

            var p = new OptionSet()
            {
                { "f|folder=", "the {FOLDER} to start the crawl.",
                  f => startFolder = f },
                { "t|target", "the {TARGET} to write the dot into",
                  t => targetFile = t },
                { "v|verbose", "print verbose messages",
                  v => verbose = v != null },
                { "h|help", "show this message and exit",
                  h => showHelp = h != null },
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Error.WriteLine($"{appName}: {e.Message}");
                Console.Error.WriteLine($"Try '{appName} --help' for more information.");
                return(99);
            }

            if (showHelp)
            {
                p.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (string.IsNullOrEmpty(startFolder))
            {
                Console.Error.WriteLine($"folder is needed.");
                Console.Error.WriteLine($"Try '{appName} --help' for more information.");
                return(99);
            }

            if (!Directory.Exists(startFolder))
            {
                Console.Error.WriteLine($"The folder {startFolder} does not exist.");
                return(99);
            }

            if (!string.IsNullOrEmpty(targetFile) && File.Exists(targetFile))
            {
                Console.Error.WriteLine($"The output-file {targetFile} already exist.");
                return(99);
            }
            var logger   = new ConsoleLogger(verbose);
            var settings = new CrawlerSettings();
            var crawler  = new DependencyCrawler(logger, settings);
            var result   = crawler.Crawl(startFolder);
            var dot      = GenerateDotFile(result);

            TextWriter output;

            if (!string.IsNullOrEmpty(targetFile))
            {
                output = new StreamWriter(targetFile, false, Encoding.Unicode);
            }
            else
            {
                output = Console.Out;
                logger.Verbose("Output:");
            }

            using (output)
            {
                output.Write(dot);
            }

            return(0);
        }