Ejemplo n.º 1
0
        public void PostProc_ExecutionFailsIfCodeCoverageFails()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.CodeCoverage.InitialiseValueToReturn = true;
            context.CodeCoverage.ProcessValueToReturn    = false;

            // Act
            var success = Execute(context);

            // Assert
            success.Should().BeFalse("Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteCalled();
            context.Scanner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 2
0
        public void PostProc_WhenNoSettingInFileAndCommandLineArg_Fail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.AdditionalConfig = new List <ConfigSetting>();
            context.Scanner.ValueToReturn   = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            // Act
            var success = Execute(context, args: "/d:sonar.login=foo");

            // Assert
            success.Should().BeFalse();
            context.Logger.AssertErrorLogged(CredentialsErrorMessage);

            context.CodeCoverage.AssertInitialisedNotCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Scanner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 3
0
        private static bool Execute(PostProcTestContext context, params string[] args)
        {
            var proc    = new MSBuildPostProcessor(context.CodeCoverage, context.Scanner, context.ReportBuilder, context.Logger, context.TargetsUninstaller.Object);
            var success = proc.Execute(args, context.Config, context.Settings);

            return(success);
        }
        public void PostProc_ExecutionSucceedsIfCoverageNotInitialised()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            context.CodeCoverage.InitialiseValueToReturn = false;
            context.Runner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Runner.ValueToReturn.RanToCompletion = true;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsTrue(success, "Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Runner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-runner fails

            CollectionAssert.AreEqual(new string[] { }, context.Runner.SuppliedCommandLineArgs.ToArray(), "Unexpected command line args passed to the sonar-runner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
        private static bool Execute(PostProcTestContext context, params string[] args)
        {
            MSBuildPostProcessor proc = new MSBuildPostProcessor(context.CodeCoverage, context.Runner, context.ReportBuilder);
            bool success = proc.Execute(args, context.Config, context.Settings, context.Logger);

            return(success);
        }
Ejemplo n.º 6
0
        private void DummyPostProcessorExecute(string[] args, AnalysisConfig config, ITeamBuildSettings settings)
        {
            var context = new PostProcTestContext(TestContext);
            var proc    = new MSBuildPostProcessor(context.CodeCoverage, context.Scanner, context.ReportBuilder, context.Logger, context.TargetsUninstaller.Object);

            proc.Execute(args, config, settings);
        }
Ejemplo n.º 7
0
        public void PostProc_ExecutionSucceeds()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Scanner.ValueToReturn.RanToCompletion = true;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsTrue(success, "Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteCalled();
            context.Scanner.AssertExecuted();

            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-scanner fails

            CollectionAssert.AreEqual(new string[] { "-Dsonar.scanAllFiles=true" }, context.Scanner.SuppliedCommandLineArgs.ToArray(), "Unexpected command line args passed to the sonar-scanner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets(context.Logger));
        }
Ejemplo n.º 8
0
        public void PostProc_ExecutionFailsIfSonarScannerFails()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult
            {
                RanToCompletion = false
            };

            // Act
            var success = Execute(context);

            // Assert
            success.Should().BeFalse("Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.Scanner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-scanner fails

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
        public void PostProc_NoProjectsToAnalyze_NoExecutionTriggered()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarConfigDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Scanner.ValueToReturn               = true;
            context.TfsProcessor.ValueToReturn          = true;

            // Act
            var success = Execute_WithNoProject(context, true);

            // Assert
            success.Should().BeFalse("Expecting post-processor to have failed");

            context.TfsProcessor.AssertNotExecuted();
            context.Scanner.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 10
0
        public void PostProc_ExecutionSucceedsIfCoverageNotInitialised()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.CodeCoverage.InitialiseValueToReturn = false;
            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            // Act
            var success = Execute(context);

            // Assert
            success.Should().BeTrue("Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Scanner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-scanner fails

            context.Scanner.SuppliedCommandLineArgs.Should().Equal(
                new string[] { "-Dsonar.scanAllFiles=true" },
                "Unexpected command line args passed to the sonar-scanner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
        public void PostProc_ExecutionSucceedsWithErrorLogs()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarConfigDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Scanner.ValueToReturn               = true;
            context.TfsProcessor.ValueToReturn          = true;
            context.Scanner.ErrorToLog = "Errors";

            // Act
            var success = Execute(context, true);

            // Assert
            success.Should().BeTrue("Expecting post-processor to have succeeded");

            context.Scanner.AssertExecuted();

            context.Scanner.SuppliedCommandLineArgs.Should().Equal(
                new string[] { "-Dsonar.scanAllFiles=true" },
                "Unexpected command line args passed to the sonar-scanner");

            context.Logger.AssertErrorsLogged(1);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
        private void DummyPostProcessorExecute(string[] args, AnalysisConfig config, ITeamBuildSettings settings)
        {
            var context = new PostProcTestContext(TestContext);
            var sonarProjectPropertiesValidator = new Mock <ISonarProjectPropertiesValidator>();

            var proc = new MSBuildPostProcessor(context.Scanner, context.Logger, context.TargetsUninstaller.Object, context.TfsProcessor, sonarProjectPropertiesValidator.Object);

            proc.Execute(args, config, settings);
        }
Ejemplo n.º 13
0
        public void PostProc_ValidArgsPassedThrough()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;
            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            var suppliedArgs = new string[]
            {
                "/d:sonar.jdbc.password=dbpwd",
                "/d:sonar.jdbc.username=dbuser",
                "/d:sonar.password=\"my pwd\"",
                "/d:sonar.login=login"
            };

            var expectedArgs = new string[]
            {
                "-Dsonar.jdbc.password=dbpwd",
                "-Dsonar.jdbc.username=dbuser",
                "-Dsonar.password=\"my pwd\"",
                "-Dsonar.login=login",
                "-Dsonar.scanAllFiles=true"
            };

            // Act
            var success = Execute(context, suppliedArgs);

            // Assert
            success.Should().BeTrue("Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.CodeCoverage.AssertInitializedCalled();
            context.Scanner.AssertExecuted();
            context.ReportBuilder.AssertExecuted();


            context.Scanner.SuppliedCommandLineArgs.Should().Equal(
                expectedArgs,
                "Unexpected command line args passed to the sonar-scanner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
        public void PostProc_ValidArgsPassedThrough()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;
            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarConfigDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Scanner.ValueToReturn               = true;
            context.TfsProcessor.ValueToReturn          = true;

            var suppliedArgs = new string[]
            {
                "/d:sonar.jdbc.password=dbpwd",
                "/d:sonar.jdbc.username=dbuser",
                "/d:sonar.password=\"my pwd\"",
                "/d:sonar.login=login"
            };

            var expectedArgs = new string[]
            {
                "-Dsonar.jdbc.password=dbpwd",
                "-Dsonar.jdbc.username=dbuser",
                "-Dsonar.password=\"my pwd\"",
                "-Dsonar.login=login",
                "-Dsonar.scanAllFiles=true"
            };

            // Act
            var success = Execute(context, true, suppliedArgs);

            // Assert
            success.Should().BeTrue("Expecting post-processor to have succeeded");

            context.Scanner.AssertExecuted();

            context.Scanner.SuppliedCommandLineArgs.Should().Equal(
                expectedArgs,
                "Unexpected command line args passed to the sonar-scanner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 15
0
        public void PostProc_ValidArgsPassedThrough()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            string[] suppliedArgs = new string[]
            {
                "/d:sonar.jdbc.password=dbpwd",
                "/d:sonar.jdbc.username=dbuser",
                "/d:sonar.password=\"my pwd\"",
                "/d:sonar.login=login"
            };

            string[] expectedArgs = new string[]
            {
                "-Dsonar.jdbc.password=dbpwd",
                "-Dsonar.jdbc.username=dbuser",
                "-Dsonar.password=\"my pwd\"",
                "-Dsonar.login=login",
                "-Dsonar.scanAllFiles=true"
            };

            // Act
            bool success = Execute(context, suppliedArgs);

            // Assert
            Assert.IsTrue(success, "Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.CodeCoverage.AssertInitializedCalled();
            context.Scanner.AssertExecuted();
            context.ReportBuilder.AssertExecuted();

            CollectionAssert.AreEqual(expectedArgs, context.Scanner.SuppliedCommandLineArgs.ToArray(), "Unexpected command line args passed to the sonar-runner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets(context.Logger));
        }
Ejemplo n.º 16
0
        public void PostProc_WhenSettingInFileAndCommandLineArg_DoesNotFail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;
            context.Scanner.ValueToReturn = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            // Act
            var success = Execute(context, args: "/d:sonar.login=foo");

            // Assert
            success.Should().BeTrue();
            context.Logger.AssertErrorDoesNotExist(CredentialsErrorMessage);
        }
Ejemplo n.º 17
0
        public void PostProc_WhenNoSettingInFileAndNoCommandLineArg_DoesNotFail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.AdditionalConfig = new List <ConfigSetting>();
            context.Scanner.ValueToReturn   = new ProjectInfoAnalysisResult
            {
                RanToCompletion = true
            };

            // Act
            var success = Execute(context, args: new string[0]);

            // Assert
            success.Should().BeTrue();
            context.Logger.AssertErrorDoesNotExist(CredentialsErrorMessage);
        }
        public void PostProc_WhenNoSettingInFileAndNoCommandLineArg_DoesNotFail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarConfigDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Config.AdditionalConfig             = new List <ConfigSetting>();
            context.Scanner.ValueToReturn               = true;

            // Act
            var success = Execute(context, true, args: new string[0]);

            // Assert
            success.Should().BeTrue();
            context.Logger.AssertErrorDoesNotExist(CredentialsErrorMessage);
        }
        public void PostProc_WhenSettingInFileAndCommandLineArg_DoesNotFail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;
            context.Config.SonarConfigDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Scanner.ValueToReturn               = true;

            // Act
            var success = Execute(context, true, args: "/d:sonar.login=foo");

            // Assert
            success.Should().BeTrue();
            context.Logger.AssertErrorDoesNotExist(CredentialsErrorMessage);
        }
        public void PostProc_FailsOnInvalidArgs()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            // Act
            bool success = Execute(context, "/d:sonar.foo=bar");

            // Assert
            Assert.IsFalse(success, "Expecting post-processor to have failed");

            context.CodeCoverage.AssertInitialisedNotCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Runner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(1);
            context.Logger.AssertWarningsLogged(0);
        }
Ejemplo n.º 21
0
        public void PostProc_WhenSettingInFileButNoCommandLineArg_Fail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;
            context.Config.SonarQubeHostUrl    = "http://sonarqube.com";
            context.Config.SonarQubeHostUrl    = "http://sonarqube.com";
            context.TfsProcessor.ValueToReturn = false;

            // Act
            var success = Execute(context, true, args: new string[0]);

            // Assert
            success.Should().BeFalse();
            context.Logger.AssertErrorLogged(CredentialsErrorMessage);

            context.TfsProcessor.AssertNotExecuted();
            context.Scanner.AssertNotExecuted();
        }
        public void PostProc_ExecutionFailsIfSonarRunnerFails()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);
            context.Runner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Runner.ValueToReturn.RanToCompletion = false;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsFalse(success, "Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.Runner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-runner fails

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
        public void PostProc_ExecutionFailsIfCodeCoverageFails()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);
            context.CodeCoverage.InitialiseValueToReturn = true;
            context.CodeCoverage.ProcessValueToReturn = false;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsFalse(success, "Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteCalled();
            context.Runner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
Ejemplo n.º 24
0
        public void PostProc_WhenSettingInFileButNoCommandLineArg_Fail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.HasBeginStepCommandLineCredentials = true;

            // Act
            var success = Execute(context, args: new string[0]);

            // Assert
            success.Should().BeFalse();
            context.Logger.AssertErrorLogged(CredentialsErrorMessage);

            context.CodeCoverage.AssertInitialisedNotCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Scanner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 25
0
        public void PostProc_FailsOnInvalidArgs()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.TfsProcessor.ValueToReturn          = false;
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;

            // Act
            var success = Execute(context, true, "/d:sonar.foo=bar");

            // Assert
            success.Should().BeFalse("Expecting post-processor to have failed");

            context.TfsProcessor.AssertNotExecuted();
            context.Scanner.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(1);
            context.Logger.AssertWarningsLogged(0);
        }
        public void PostProc_ExecutionFailsIfSonarRunnerFails()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            context.Runner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Runner.ValueToReturn.RanToCompletion = false;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsFalse(success, "Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.Runner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-runner fails

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
Ejemplo n.º 27
0
        public void PostProc_FailsOnInvalidArgs()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            // Act
            var success = Execute(context, "/d:sonar.foo=bar");

            // Assert
            success.Should().BeFalse("Expecting post-processor to have failed");

            context.CodeCoverage.AssertInitialisedNotCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Scanner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(1);
            context.Logger.AssertWarningsLogged(0);

            // Verify that the method was called at least once
            context.TargetsUninstaller.Verify(m => m.UninstallTargets());
        }
Ejemplo n.º 28
0
        public void PostProc_WhenNoSettingInFileAndCommandLineArg_Fail()
        {
            // Arrange
            var context = new PostProcTestContext(TestContext);

            context.Config.SonarOutputDir               = Environment.CurrentDirectory;
            context.Config.SonarQubeHostUrl             = "http://sonarqube.com";
            context.Config.SonarScannerWorkingDirectory = Environment.CurrentDirectory;
            context.Config.AdditionalConfig             = new List <ConfigSetting>();
            context.Scanner.ValueToReturn               = true;
            context.TfsProcessor.ValueToReturn          = false;

            // Act
            var success = Execute(context, true, args: "/d:sonar.login=foo");

            // Assert
            success.Should().BeFalse();
            context.Logger.AssertErrorLogged(CredentialsErrorMessage);

            context.TfsProcessor.AssertNotExecuted();
            context.Scanner.AssertNotExecuted();
        }
        public void PostProc_ExecutionFailsIfCodeCoverageFails()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            context.CodeCoverage.InitialiseValueToReturn = true;
            context.CodeCoverage.ProcessValueToReturn    = false;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsFalse(success, "Not expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteCalled();
            context.Runner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
        public void PostProc_ExecutionSucceeds()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);
            context.Runner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Runner.ValueToReturn.RanToCompletion = true;

            // Act
            bool success = Execute(context);

            // Assert
            Assert.IsTrue(success, "Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertInitializedCalled();
            context.CodeCoverage.AssertExecuteCalled();
            context.Runner.AssertExecuted();
            context.ReportBuilder.AssertExecuted(); // should be called even if the sonar-runner fails

            CollectionAssert.AreEqual(new string[] { }, context.Runner.SuppliedCommandLineArgs.ToArray(), "Unexpected command line args passed to the sonar-runner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
        private bool Execute(PostProcTestContext context, bool propertyWriteSucceeded, params string[] args)
        {
            var sonarProjectPropertiesValidator = new Mock <ISonarProjectPropertiesValidator>();

            IEnumerable <string> expectedValue;

            sonarProjectPropertiesValidator
            .Setup(propValidator => propValidator.AreExistingSonarPropertiesFilesPresent(It.IsAny <string>(), It.IsAny <ICollection <ProjectData> >(), out expectedValue)).Returns(false);

            var proc = new MSBuildPostProcessor(context.Scanner, context.Logger, context.TargetsUninstaller.Object, context.TfsProcessor, sonarProjectPropertiesValidator.Object);

            var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext, Guid.NewGuid().ToString());

            var projectInfo = TestUtils.CreateProjectWithFiles(TestContext, "withFiles1", testDir);

            List <ProjectData> listOfProjects = new List <ProjectData>();

            listOfProjects.Add(new ProjectData(ProjectInfo.Load(projectInfo)));

            IEnumerable <ProjectData> expectedListOfProjects = listOfProjects;

            var propertiesFileGenerator = Mock.Of <IPropertiesFileGenerator>();

            Mock.Get(propertiesFileGenerator).Setup(m => m.TryWriteProperties(It.IsAny <PropertiesWriter>(), out expectedListOfProjects)).Returns(propertyWriteSucceeded);

            var projectInfoAnalysisResult = new ProjectInfoAnalysisResult();

            projectInfoAnalysisResult.Projects.AddRange(listOfProjects);
            projectInfoAnalysisResult.RanToCompletion        = true;
            projectInfoAnalysisResult.FullPropertiesFilePath = Path.Combine(testDir, "sonar-project.properties");

            Mock.Get(propertiesFileGenerator).Setup(m => m.GenerateFile()).Returns(projectInfoAnalysisResult);
            proc.SetPropertiesFileGenerator(propertiesFileGenerator);
            var success = proc.Execute(args, context.Config, context.Settings);

            return(success);
        }
 private static bool Execute(PostProcTestContext context, params string[] args)
 {
     MSBuildPostProcessor proc = new MSBuildPostProcessor(context.CodeCoverage, context.Runner, context.ReportBuilder);
     bool success = proc.Execute(args, context.Config, context.Settings, context.Logger);
     return success;
 }
        public void PostProc_ValidArgsPassedThrough()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);
            context.Runner.ValueToReturn = new ProjectInfoAnalysisResult();
            context.Runner.ValueToReturn.RanToCompletion = true;

            string[] suppliedArgs = new string[]
            {
                "/d:sonar.jdbc.password=dbpwd",
                "/d:sonar.jdbc.username=dbuser",
                "/d:sonar.password=\"my pwd\"",
                "/d:sonar.login=login"
            };

            string[] expectedArgs = new string[]
            {
                "-Dsonar.jdbc.password=dbpwd",
                "-Dsonar.jdbc.username=dbuser",
                "-Dsonar.password=\"my pwd\"",
                "-Dsonar.login=login"
            };

            // Act
            bool success = Execute(context, suppliedArgs);

            // Assert
            Assert.IsTrue(success, "Expecting post-processor to have succeeded");

            context.CodeCoverage.AssertExecuteCalled();
            context.CodeCoverage.AssertInitializedCalled();
            context.Runner.AssertExecuted();
            context.ReportBuilder.AssertExecuted();

            CollectionAssert.AreEqual(expectedArgs, context.Runner.SuppliedCommandLineArgs.ToArray(), "Unexpected command line args passed to the sonar-runner");

            context.Logger.AssertErrorsLogged(0);
            context.Logger.AssertWarningsLogged(0);
        }
        public void PostProc_FailsOnInvalidArgs()
        {
            // Arrange
            PostProcTestContext context = new PostProcTestContext(this.TestContext);

            // Act
            bool success = Execute(context, "/d:sonar.foo=bar");

            // Assert
            Assert.IsFalse(success, "Expecting post-processor to have failed");

            context.CodeCoverage.AssertInitialisedNotCalled();
            context.CodeCoverage.AssertExecuteNotCalled();
            context.Runner.AssertNotExecuted();
            context.ReportBuilder.AssertNotExecuted();

            context.Logger.AssertErrorsLogged(1);
            context.Logger.AssertWarningsLogged(0);
        }