public void Exe_PreProc_UrlIsRequired()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);

                MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater();

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "begin");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();

                AssertDirectoryDoesNotExist(binDir);

                logger.AssertErrorLogged(SonarQube.Bootstrapper.Resources.ERROR_Args_UrlRequired);
                logger.AssertErrorsLogged(1);
            }
        }
        public void Exe_PreProc_UrlIsRequired()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);

                MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater();

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "begin");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();

                AssertDirectoryDoesNotExist(binDir);

                logger.AssertErrorLogged(SonarQube.Bootstrapper.Resources.ERROR_Args_UrlRequired);
                logger.AssertErrorsLogged(1);
            }
        }
        public void Exe_PostProc_Succeeds()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);
                Directory.CreateDirectory(binDir);
                DummyExeHelper.CreateDummyPostProcessor(binDir, 0 /* success exit code */);

                MockBuildAgentUpdater mockUpdater = CreateValidUpdater(binDir, "http://h:9000");

                // Act
                TestLogger logger = CheckExecutionSucceeds(mockUpdater, "end", "other params", "yet.more.params");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();
                logger.AssertWarningsLogged(0);

                // The bootstrapper pass through any parameters it doesn't recognise so the post-processor
                // can decide whether to handle them or not
                string logPath = DummyExeHelper.AssertDummyPostProcLogExists(binDir, this.TestContext);
                DummyExeHelper.AssertExpectedLogContents(logPath,
                                                         "other params",
                                                         "yet.more.params");
            }
        }
        public void Exe_PostProc_Fails()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);
                Directory.CreateDirectory(binDir);
                DummyExeHelper.CreateDummyPostProcessor(binDir, 1 /* post-proc fails */);

                MockBuildAgentUpdater mockUpdater = CreateValidUpdater(binDir, "http://h:9000");

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "end");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();
                logger.AssertWarningsLogged(0);

                string logPath = DummyExeHelper.AssertDummyPostProcLogExists(binDir, this.TestContext);
                DummyExeHelper.AssertExpectedLogContents(logPath, null);
            }
        }
        public void Exe_PostProc_ExecutableNotFound_PostProcFails()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                // a non-dummy post-processor is used to check that it fails with the correct error message
                string binDir = CalculateBinDir(rootDir);
                MockBuildAgentUpdater mockUpdater = CreateValidUpdater(binDir, "http://anotherHost");

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "end");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();
                logger.AssertSingleErrorExists(binDir + "\\MSBuild.SonarQube.Internal.PostProcess.exe"); // expect an error message at least containing the
            }
        }
        public void Exe_ParsingFails()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);

                MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater();

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "/d: badkey=123");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();

                AssertDirectoryDoesNotExist(binDir);

                logger.AssertErrorsLogged();
            }
        }
        public void Exe_ParsingFails()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);

                MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater();

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "/d: badkey=123");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();

                AssertDirectoryDoesNotExist(binDir);

                logger.AssertErrorsLogged();
            }
        }