public AlertViewComponent(IDataService dataService,IOptions<ThresholdOptions> thresholdOptions )
 {
     this.dataService = dataService;
     this.thresholdOptions = thresholdOptions.Value;
 }
Beispiel #2
0
 public AlertViewComponent(ISensorDataService sensorDataService, IOptions <ThresholdOptions> thresholdConfig)
 {
     this.sensorDataService = sensorDataService;
     this.thresholdConfig   = thresholdConfig.Value;
 }
Beispiel #3
0
            public static JsonReportComponent FromProjectComponent(IReadOnlyInputComponent component, ThresholdOptions thresholdOptions)
            {
                var report = new JsonReportComponent
                {
                    Name            = component.Name,
                    DetectedMutants = component.DetectedMutants.Count(),
                    TotalMutants    = component.TotalMutants.Count(),
                    KilledMutants   = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Killed).Count(),
                    SurvivedMutants = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Survived).Count(),
                    SkippedMutants  = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Skipped).Count(),
                    TimeoutMutants  = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Timeout).Count(),
                    CompileErrors   = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.BuildError).Count(),
                    MutationScore   = component.GetMutationScore(),
                    ThresholdHigh   = thresholdOptions.ThresholdHigh,
                    ThresholdLow    = thresholdOptions.ThresholdLow,
                    ThresholdBreak  = thresholdOptions.ThresholdBreak,
                };

                report.PossibleMutants = report.TotalMutants + report.SkippedMutants;

                if (report.MutationScore >= report.ThresholdHigh)
                {
                    report.Health = "ok";
                }
                else if (report.MutationScore <= report.ThresholdBreak)
                {
                    report.Health = "danger";
                }
                else
                {
                    report.Health = "warning";
                }

                if (component is FolderComposite folderComponent)
                {
                    foreach (var child in folderComponent.Children)
                    {
                        report.ChildResults.Add(FromProjectComponent(child, thresholdOptions));
                    }
                }
                else if (component is FileLeaf fileComponent)
                {
                    report.Source = fileComponent.SourceCode;
                    foreach (var mutant in fileComponent.Mutants)
                    {
                        var jsonMutant = new JsonMutant
                        {
                            Id          = mutant.Id,
                            MutatorName = mutant.Mutation.DisplayName,
                            Replacement = mutant.Mutation.ReplacementNode.ToFullString(),
                            Span        = new[] { mutant.Mutation.OriginalNode.SpanStart, mutant.Mutation.OriginalNode.Span.End },
                            Status      = StrykerStatusToMutationStatus(mutant.ResultStatus)
                        };

                        report.Mutants.Add(jsonMutant);
                    }
                }
                else
                {
                    throw new System.Exception("Unknown IReadOnlyInputComponent implementation");
                }

                return(report);
            }