private async Task ExecuteProjectsAnalysisImplAsync(IList <ProjectData> projects, ProjectsAnalysisStat statistics, String appPath, IConfigDataProvider configDataProvider)
        {
            await OutputHelper.OutputMessageAsync(ServiceProvider, $"Source code analysis for {statistics.TargetType} named \"{statistics.ProjectNames}\" is started");

            foreach (ProjectData project in projects)
            {
                String target = project.FileName;
                if (String.Equals(project.LanguageId, LanguageCSharpId))
                {
                    String          configPath  = ConfigFinder.FindConfig(configDataProvider, target);
                    OutputLevel     outputLevel = configDataProvider.GetOutputLevel();
                    ExecutionResult result      = await ExecutionHelper.ExecuteSourceCodeAnalysisAsync(appPath, target, configPath, outputLevel);

                    if (result.ExitCode == 0)
                    {
                        ++statistics.SuccessCount;
                    }
                    else
                    {
                        ++statistics.FailedCount;
                    }
                    await OutputHelper.OutputTargetAnalysisResultAsync(ServiceProvider, result, target, "project");
                }
                else
                {
                    ++statistics.SkippedCount;
                    await OutputHelper.OutputMessageAsync(ServiceProvider, $"Project \"{target}\" can't be processed due to unsupported language");
                }
            }
            await OutputHelper.OutputMessageAsync(ServiceProvider, $"Source code analysis for {statistics.TargetType} named \"{statistics.ProjectNames}\" is finished");

            await UIHelper.ShowProjectsSummaryAsync(_package, statistics);
        }
        public void GetConfigFilePath_ConfigFileNotFound_ShouldThrowFileNotFoundException()
        {
            //arrange
            Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>();
            Mock <DTE>          dteMock                   = new Mock <DTE>();
            Mock <Solution>     solutionMock              = new Mock <Solution>();
            Mock <ProjectItem>  projectProjectItemMock    = new Mock <ProjectItem>();
            Mock <Project>      projectMock               = new Mock <Project>();
            Mock <ProjectItems> projectItemsMock          = new Mock <ProjectItems>();
            Mock <ProjectItem>  configFileProjectItemMock = new Mock <ProjectItem>();

            string configFileName = "wrongFileName";
            string configFilePath = "testConfigFilePath";
            string templateFile   = "testTemplateFilePath";

            serviceProviderMock.Setup(serviceProvider => serviceProvider.GetService(It.IsAny <Type>()))
            .Returns(dteMock.Object);
            dteMock.SetupGet(dte => dte.Solution).Returns(solutionMock.Object);
            solutionMock.Setup(solution => solution.FindProjectItem(templateFile)).Returns(projectProjectItemMock.Object);
            projectProjectItemMock.SetupGet(projectItem => projectItem.ContainingProject).Returns(projectMock.Object);
            projectMock.SetupGet(project => project.ProjectItems).Returns(projectItemsMock.Object);
            projectItemsMock.Setup(projectItems => projectItems.GetEnumerator())
            .Returns(new ProjectItem[] { configFileProjectItemMock.Object }.GetEnumerator());
            configFileProjectItemMock.SetupGet(configFileProjectItem => configFileProjectItem.Name).Returns(configFileName);
            configFileProjectItemMock.Setup(configFileProjectItem => configFileProjectItem.get_FileNames(0))
            .Returns(configFilePath);

            //act
            Action act = () => ConfigFinder.GetConfigFilePath(serviceProviderMock.Object, templateFile);

            //assert
            act.Should().ThrowExactly <FileNotFoundException>();
        }
Exemple #3
0
        public void FindDirectoryFileConfig()
        {
            const String        someRepoPath                 = "C:\\SomeRepo";
            const String        someRepoConfigDirPath        = "C:\\Configs\\SomeRepoConfig";
            const String        someRepoConfigFilePath       = "C:\\Configs\\SomeRepoConfig\\porter.config";
            const String        someProjectPath              = "C:\\SomeRepo\\SomeProject";
            const String        someSubprojectPath           = "C:\\SomeRepo\\SomeProject\\SomeSubproject";
            const String        someSubprojectConfigDirPath  = "C:\\Configs\\SomeRepoConfig\\SomeSubprojectConfig";
            const String        someSubprojectConfigFilePath = "C:\\Configs\\SomeRepoConfig\\SomeSubprojectConfig\\porter.config";
            IList <SourceEntry> entries = new List <SourceEntry>
            {
                new SourceEntry(someRepoPath, someRepoConfigDirPath),
                new SourceEntry(someRepoPath, someRepoConfigFilePath),
                new SourceEntry(someProjectPath, ""),
                new SourceEntry(someSubprojectPath, someSubprojectConfigFilePath),
                new SourceEntry(someSubprojectPath, someSubprojectConfigDirPath),
                new SourceEntry("C:\\OtherRepo", "C:\\Configs\\OtherRepoConfig"),
                new SourceEntry("C:\\OtherRepo", "C:\\Configs\\OtherRepoConfig\\porter.config")
            };
            IConfigDataProvider configDataProvider = new ReadOnlyConfigDataProvider("C:\\AppSomeLocation", OutputLevel.Error, entries);

            Assert.AreEqual(someRepoConfigDirPath, ConfigFinder.FindConfig(configDataProvider, someRepoPath));
            Assert.AreEqual("", ConfigFinder.FindConfig(configDataProvider, someProjectPath));
            Assert.AreEqual(someSubprojectConfigFilePath, ConfigFinder.FindConfig(configDataProvider, someSubprojectPath));
            Assert.AreEqual(someRepoConfigDirPath, ConfigFinder.FindConfig(configDataProvider, someRepoPath + "\\OtherProject"));
            Assert.AreEqual("", ConfigFinder.FindConfig(configDataProvider, someProjectPath + "\\OtherSubproject"));
            Assert.AreEqual(someSubprojectConfigFilePath, ConfigFinder.FindConfig(configDataProvider, someSubprojectPath + "\\SomeInnerSubproject"));
            Assert.AreEqual("", ConfigFinder.FindConfig(configDataProvider, "C:\\AnotherRepo"));
        }
        public void GetConfigFilePath_ShouldReturnConfigFile()
        {
            //arrange
            Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>();
            Mock <DTE>          dteMock                   = new Mock <DTE>();
            Mock <Solution>     solutionMock              = new Mock <Solution>();
            Mock <ProjectItem>  projectProjectItemMock    = new Mock <ProjectItem>();
            Mock <Project>      projectMock               = new Mock <Project>();
            Mock <ProjectItems> projectItemsMock          = new Mock <ProjectItems>();
            Mock <ProjectItem>  configFileProjectItemMock = new Mock <ProjectItem>();

            string configFileName = "app.config";
            string configFilePath = "testConfigFilePath";
            string templateFile   = "testTemplateFilePath";

            serviceProviderMock.Setup(serviceProvider => serviceProvider.GetService(It.IsAny <Type>()))
            .Returns(dteMock.Object);
            dteMock.SetupGet(dte => dte.Solution).Returns(solutionMock.Object);
            solutionMock.Setup(solution => solution.FindProjectItem(templateFile)).Returns(projectProjectItemMock.Object);
            projectProjectItemMock.SetupGet(projectItem => projectItem.ContainingProject).Returns(projectMock.Object);
            projectMock.SetupGet(project => project.ProjectItems).Returns(projectItemsMock.Object);
            projectItemsMock.Setup(projectItems => projectItems.GetEnumerator())
            .Returns(new ProjectItem[] { configFileProjectItemMock.Object }.GetEnumerator());
            configFileProjectItemMock.SetupGet(configFileProjectItem => configFileProjectItem.Name).Returns(configFileName);
            configFileProjectItemMock.Setup(configFileProjectItem => configFileProjectItem.get_FileNames(0))
            .Returns(configFilePath);

            //act
            string configFileResult = ConfigFinder.GetConfigFilePath(serviceProviderMock.Object, templateFile);

            //assert
            configFileResult.Should().NotBeNull();
            configFileResult.Should().Be(configFilePath);
        }
        public void GetConfigFilePath_ServiceProviderIsNull_ShouldThrowArgumentNullException()
        {
            //arrange
            string templateFile = "testTemplateFile";

            //act
            Action act = () => ConfigFinder.GetConfigFilePath(null, templateFile);

            //assert
            act.Should().ThrowExactly <ArgumentNullException>();
        }
        public void GetConfigFilePath_TemplateFileIsNull_ShouldThrowArgumentException()
        {
            //arrange
            Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>();
            string templateFile = null;

            //act
            Action act = () => ConfigFinder.GetConfigFilePath(serviceProviderMock.Object, templateFile);

            //assert
            act.Should().ThrowExactly <ArgumentException>();
        }
Exemple #7
0
        private async Task ExecuteSolutionAnalysisImplAsync(String target, String appPath, IConfigDataProvider configDataProvider)
        {
            await OutputHelper.OutputMessageAsync(ServiceProvider, $"Source code analysis for solution named \"{target}\" is started");

            String          configPath  = ConfigFinder.FindConfig(configDataProvider, target);
            OutputLevel     outputLevel = configDataProvider.GetOutputLevel();
            ExecutionResult result      = await ExecutionHelper.ExecuteSourceCodeAnalysisAsync(appPath, target, configPath, outputLevel);

            await OutputHelper.OutputTargetAnalysisResultAsync(ServiceProvider, result, target, "solution");

            await OutputHelper.OutputMessageAsync(ServiceProvider, $"Source code analysis for solution named \"{target}\" is finished");

            await UIHelper.ShowSolutionSummaryAsync(_package, result, target);
        }
Exemple #8
0
        public static IShowCommitsForBuildCoordinator Create(IConsole console)
        {
            // poor-man's IoC
            var configFinder      = new ConfigFinder(console);
            var requestFactory    = new SecureWebRequestFactory(console);
            var tfsConfig         = configFinder.GetConfig <ITfsConfig>("TFS");
            var gitLabConfig      = configFinder.GetConfig <IGitLabConfig>("GitLab");
            var infoFinder        = new BuildInfoFinder(console, tfsConfig, requestFactory);
            var gitLabUrlLauncher = new GitLabUrlLauncher(gitLabConfig);

            return(new ShowCommitsForBuildCoordinator(
                       infoFinder,
                       gitLabUrlLauncher
                       ));
        }