Example #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 CreateFromPathWithCustomSettingsForSingleFileProject()
        {
            var expectedProject = new Project(SingleFileProjectPath, new List <string> {
                FirstFile
            }, Settings);

            this.fileSystemHandler.Setup(f => f.IsDirectory(SingleFileProjectPath)).Returns(false);

            var factory = new ProjectFactory(this.fileSystemHandler.Object);

            var project = factory.CreateFromPathWithCustomSettings(SingleFileProjectPath, Settings, new [] { IgnoredPath });

            this.AssertProjectsAreEqual(expectedProject, project);
        }
        public void CreateFromPathWithCustomSettingsForMultiFileProject()
        {
            var expectedProject = new Project(MultiFileProjectPath, new List <string> {
                FirstFile, SecondFile
            }, Settings);

            this.fileSystemHandler.Setup(f => f.IsDirectory(MultiFileProjectPath)).Returns(true);

            this.fileSystemHandler.Setup(f => f.GetAllSourceCodeFiles(MultiFileProjectPath))
            .Returns(new List <string> {
                FirstFile, SecondFile
            });

            var factory = new ProjectFactory(this.fileSystemHandler.Object);

            var project = factory.CreateFromPathWithCustomSettings(MultiFileProjectPath, Settings, new [] { IgnoredPath });

            this.AssertProjectsAreEqual(expectedProject, project);
        }