private static FeatureEvidence RunCodeCoverage(CheckConfig checkConfig)
        {
            var codeCoverageEvidence = new FeatureEvidence {
                Feature = Feature.CodeCoverageCheck, HelperMessage = messages.CodeCoverageCheck
            };

            var dotCoverDir    = checkConfig.RunParameters.DotCoverDir;
            var fullReportPath = Path.GetTempFileName();

            var targetWorkingDir = Path.Combine(checkConfig.PathManager.ModifiedTestDirPath, testFolder);

            if (!Directory.Exists(targetWorkingDir))
            {
                codeCoverageEvidence.SetInconclusive(new SimpleEvidenceBuilder($"{testFolder} Directory Not Found"));
                return(codeCoverageEvidence);
            }

            var argument = CreateArgument("C:\\Program Files\\dotnet", targetWorkingDir, fullReportPath);

            new FeatureRunner().Execute(CreateProcessDetails(argument, processName, dotCoverDir));

            var report = ReadReport(fullReportPath);

            File.Delete(fullReportPath);

            try
            {
                var coverage = GetCodeCoverage(report);
                codeCoverageEvidence.FeatureRating = coverage / 100.0;
                var featureImplemented = coverage >= passPercentage;
                var evidence           = $"Code Coverage: {coverage}%";
                if (featureImplemented)
                {
                    codeCoverageEvidence.SetPassed(new SimpleEvidenceBuilder(evidence));
                }
                else
                {
                    codeCoverageEvidence.SetFailed(new SimpleEvidenceBuilder(evidence));
                }
            }
            catch (Exception e)
            {
                codeCoverageEvidence.SetInconclusive(new SimpleEvidenceBuilder(e.ToString()));
            }

            return(codeCoverageEvidence);
        }
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectBuildTask.ContinueWith(task => {
                if (!task.Result.All(evidence => evidence.Passed))
                {
                    var dependencyFailedEvidence = new FeatureEvidence {
                        Feature = Feature.CodeCoverageCheck, HelperMessage = messages.CodeCoverageCheck
                    };
                    dependencyFailedEvidence.SetInconclusive(new SimpleEvidenceBuilder("Project build failed, unable to perform check."));
                    return new List <FeatureEvidence> {
                        dependencyFailedEvidence
                    };
                }

                var codeCoverageEvidence = RunCodeCoverage(checkConfig);
                return new List <FeatureEvidence> {
                    codeCoverageEvidence
                };
            }, TaskContinuationOptions.OnlyOnRanToCompletion));
        }
Esempio n. 3
0
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectRunnerTask.ContinueWith(task =>
            {
                if (!task.Result.All(evidence => evidence.Passed))
                {
                    var dependencyFailedEvidence = new FeatureEvidence {
                        Feature = Feature.UIFeatureImplemented, HelperMessage = messages.UIFeatureImplemented
                    };
                    dependencyFailedEvidence.SetInconclusive(new SimpleEvidenceBuilder("Project failed to run, unable to perform check."));
                    return new List <FeatureEvidence> {
                        dependencyFailedEvidence
                    };
                }

                var port = portTask.Result;

                return ExecuteChecks(port);
            }, TaskContinuationOptions.OnlyOnRanToCompletion));
        }
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectBuilderTask.ContinueWith(buildTask =>
            {
                var projectRunEvidence = new FeatureEvidence {
                    Feature = Feature.ProjectRunner
                };

                if (!buildTask.Result.All(buildEvidence => buildEvidence.Passed))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder("Project build failed, unable to perform check."));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                if (!Directory.Exists(workingDir))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder($"{workingDir} not found"));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                Argument = CreateArgument(workingDir);

                var processDetails = new ProcessDetails(ProcessName, workingDir, Argument);

                var evidence = featureRunner.Execute(processDetails, "Application started. Press Ctrl+C to shut down.", false);
                Output = evidence.Output;
                ErrorOutput = evidence.ErrorOutput;

                const string portKeyword = "Now listening on: ";
                var line = Output.GetLineWithOneKeyword(portKeyword);
                var splitLine = line.Split(portKeyword, StringSplitOptions.None);
                var port = splitLine.Length > 1 ? splitLine[1] : "";

                if (String.IsNullOrEmpty(port))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder(messages.BadPort));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                portCompletionSource.SetResult(port);

                var applicationStarted = ApplicationStarted();

                if (applicationStarted)
                {
                    projectRunEvidence.SetPassed(new SimpleEvidenceBuilder($"Port: {GetPort().Result}"));
                    projectRunEvidence.FeatureRating = 1;
                }
                else
                {
                    projectRunEvidence.SetFailed(new SimpleEvidenceBuilder($"Error Output: {ErrorOutput}"));
                    projectRunEvidence.FeatureRating = 0;
                }

                return new List <FeatureEvidence> {
                    projectRunEvidence
                };
            }, TaskContinuationOptions.OnlyOnRanToCompletion));
        }