Ejemplo n.º 1
0
        private static int Analyze(string settings, string projectPath, string[] ignoredPaths)
        {
            var fileSystemHandler = new FileSystemHandler();
            var outputWriter = new StandardOutputWriter();

            if (false == fileSystemHandler.Exists(settings))
            {
                outputWriter.WriteLineWithSeparator("Given settings file does not exist. Exiting...", string.Empty);

                return SettingsFileDoesNotExistErrorCode;
            }

            if (false == fileSystemHandler.Exists(projectPath))
            {
                outputWriter.WriteLineWithSeparator("Given path to analyze does not exist. Exiting...", string.Empty);

                return InvalidPathToAnalyzeErrorCode;
            }

            var analyzer = new StyleCopAnalyzer();
            var projectFactory = new ProjectFactory(new FileSystemHandler());
            var project = projectFactory.CreateFromPathWithCustomSettings(projectPath, settings, ignoredPaths);
            var violations = analyzer.GetViolationsFromProject(project);

            var renderer = new ConsoleRenderer(outputWriter);

            renderer.RenderViolationList(violations);

            if (violations.Empty)
            {
                return NoViolationsFound;
            }

            return ViolationsFound;
        }
        public void OutputsOnlySummaryWhenNoViolationFound()
        {
            var outputWriter = new Mock<IOutputWriter>();

            var renderer = new ConsoleRenderer(outputWriter.Object);

            renderer.RenderViolationList(WithNoViolation());

            outputWriter.Verify(o => o.WriteLine("StyleCop.Baboon by Nelson Senna."), Times.Once);
            outputWriter.Verify(o => o.WriteLineWithSeparator("No violations found! Great job!", string.Empty), Times.Once);
        }
        public void RenderViolationList()
        {
            var expectedViolationMessage = "Line 666: [SA666] You can't do this.";

            var outputWriter = new Mock<IOutputWriter>();

            var renderer = new ConsoleRenderer(outputWriter.Object);

            renderer.RenderViolationList(WithOneViolation());

            outputWriter.Verify(o => o.WriteLine("StyleCop.Baboon by Nelson Senna."), Times.Once);
            outputWriter.Verify(o => o.WriteLineWithSeparator("File: Test.cs", string.Empty), Times.Once);
            outputWriter.Verify(o => o.WriteColoredLine(expectedViolationMessage, ConsoleColor.DarkRed), Times.Once);
            outputWriter.Verify(o => o.WriteLine("Violations found: 1"), Times.Once);
            outputWriter.Verify(o => o.WriteLineWithSeparator("Files analyzed: 1, Total violations: 1", string.Empty), Times.Once);
        }