/// <summary>
        /// Run the task.
        /// </summary>
        /// <param name="result"></param>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Running CodeItRight analysis");

            // Run the executable
            var info          = this.CreateProcessInfo(result);
            var processResult = this.TryToRun(info, result);

            // Need to start a new result as CodeItRight returns the number of violation
            processResult = new ProcessResult(
                processResult.StandardOutput,
                processResult.StandardError,
                processResult.ExitCode,
                processResult.TimedOut,
                processResult.ExitCode < 0);
            result.AddTaskResult(new ProcessTaskResult(processResult));
            if (processResult.TimedOut)
            {
                result.AddTaskResult(MakeTimeoutBuildResult(info));
            }

            if (processResult.Succeeded)
            {
                var xmlFile = result.BaseFromWorkingDirectory("codeitright.xml");
                result.AddTaskResult(
                    fileSystem.GenerateTaskResultFromFile(xmlFile, true));
            }

            // Check the failure threshold
            var failed = !processResult.Succeeded;

            if (!failed && (this.FailureThreshold != Severity.None))
            {
                var xmlFile  = result.BaseFromWorkingDirectory("codeitright.xml");
                var document = new XmlDocument();
                if (this.fileSystem.FileExists(xmlFile))
                {
                    using (var stream = this.fileSystem.OpenInputStream(xmlFile))
                    {
                        document.Load(stream);
                    }

                    for (var level = (int)Severity.CriticalError; level >= (int)this.FailureThreshold; level--)
                    {
                        failed = CodeItRightTask.CheckReportForSeverity(document, (Severity)level);
                        if (failed)
                        {
                            break;
                        }
                    }
                }
            }

            return(!failed);
        }
        public void RunsWithDefaultParameters()
        {
            var result = GenerateResultMock();
            var executablePath = "SubMain.CodeItRight.Cmd";
            var executor = GenerateExecutorMock(
                executablePath,
                "/quiet /severityThreshold:\"None\" /out:\"" + Path.Combine(defaultWorkingDir, "codeitright.xml") +
                "\" /Solution:\"" + Path.Combine(defaultWorkingDir, "test.sln") + "\"",
                defaultWorkingDir,
                600000);
            var fileSystemMock = this.InitialiseFileSystemMock(defaultWorkingDir);
            var task = new CodeItRightTask(executor, fileSystemMock)
            {
                Solution = "test.sln"
            };

            Expect.Call(result.Status).PropertyBehavior();
            mocks.ReplayAll();
            result.Status = IntegrationStatus.Unknown;
            task.Run(result);
            mocks.VerifyAll();
        }
        public void RunFailsWithoutProjectOrSolution()
        {
            var result = GenerateResultMock();
            var executablePath = "SubMain.CodeItRight.Cmd";
            var executor = GenerateExecutorMock(
                executablePath,
                "/quiet /severityThreshold:\"None\" /out:\"" + Path.Combine(defaultWorkingDir, "codeitright.xml") +
                "\" /Project:\"" + Path.Combine(defaultWorkingDir, "test.csproj") +
                "\" /outxsl:\"" + Path.Combine(defaultWorkingDir, "test.xsl") +
                "\" /crdata:\"" + Path.Combine(defaultWorkingDir, "test.crdata") +
                "\" /profile:\"profile\"",
                defaultWorkingDir,
                600000);
            var fileSystemMock = this.InitialiseFileSystemMock(defaultWorkingDir);
            var task = new CodeItRightTask(executor, fileSystemMock);

            Expect.Call(result.Status).PropertyBehavior();
            mocks.ReplayAll();
            result.Status = IntegrationStatus.Unknown;
            Assert.Throws<CruiseControlException>(() => task.Run(result));
        }
        public void RunsWithFullParameters()
        {
            var result = GenerateResultMock();
            var executablePath = "SubMain.CodeItRight.Cmd";
            var executor = GenerateExecutorMock(
                executablePath,
                "/quiet /severityThreshold:\"None\" /out:\"" + Path.Combine(defaultWorkingDir, "codeitright.xml") +
                "\" /Project:\"" + Path.Combine(defaultWorkingDir, "test.csproj") +
                "\" /outxsl:\"" + Path.Combine(defaultWorkingDir, "test.xsl") + 
                "\" /crdata:\"" + Path.Combine(defaultWorkingDir, "test.crdata") + 
                "\" /profile:\"profile\"",
                defaultWorkingDir,
                600000);
            var fileSystemMock = this.InitialiseFileSystemMock(defaultWorkingDir);
            var task = new CodeItRightTask(executor, fileSystemMock)
            {
                Project = "test.csproj",
                CRData = "test.crdata",
                Xsl = "test.xsl",
                Profile = "profile"
            };

            Expect.Call(result.Status).PropertyBehavior();
            mocks.ReplayAll();
            result.Status = IntegrationStatus.Unknown;
            task.Run(result);
            mocks.VerifyAll();
        }