コード例 #1
0
        private ImmutableArray <Diagnostic> RunDiagnostics([NotNull] AnalyzerTestContext context)
        {
            DocumentWithSpans documentWithSpans = TestHelpers.GetDocumentAndSpansFromMarkup(context.MarkupCode,
                                                                                            context.LanguageName, context.References, context.FileName);

            ImmutableArray <Diagnostic> diagnostics =
                GetDiagnosticsForDocument(documentWithSpans.Document)
                .OrderBy(d => d.Location.SourceSpan)
                .ToImmutableArray();
            ImmutableArray <TextSpan> spans = documentWithSpans.TextSpans.OrderBy(s => s).ToImmutableArray();

            diagnostics.Should().HaveCount(spans.Length);

            for (int index = 0; index < diagnostics.Length; index++)
            {
                Diagnostic diagnostic = diagnostics[index];
                TextSpan   span       = spans[index];

                diagnostic.Id.Should().Be(DiagnosticId);
                diagnostic.Location.IsInSource.Should().BeTrue();
                diagnostic.Location.SourceSpan.Should().Be(span);
            }

            return(diagnostics);
        }
コード例 #2
0
        private AnalysisResult GetAnalysisResult([NotNull] AnalyzerTestContext context, [NotNull][ItemNotNull] string[] messages)
        {
            DocumentWithSpans documentWithSpans = DocumentFactory.GetDocumentWithSpansFromMarkup(context);

            IList <Diagnostic>        diagnostics = GetSortedAnalyzerDiagnostics(context, documentWithSpans);
            ImmutableArray <TextSpan> spans       = documentWithSpans.TextSpans.OrderBy(s => s).ToImmutableArray();

            return(new AnalysisResult(diagnostics, spans, messages));
        }
コード例 #3
0
        private IList <Diagnostic> GetSortedAnalyzerDiagnostics([NotNull] AnalyzerTestContext context,
                                                                [NotNull] DocumentWithSpans documentWithSpans)
        {
            IEnumerable <Diagnostic> diagnostics = EnumerateDiagnosticsForDocument(documentWithSpans.Document,
                                                                                   context.ValidationMode, context.DiagnosticsCaptureMode, context.Options).Where(d => d.Id == DiagnosticId);

            if (context.DiagnosticsCaptureMode == DiagnosticsCaptureMode.RequireInSourceTree)
            {
                diagnostics = diagnostics.OrderBy(d => d.Location.SourceSpan);
            }

            return(diagnostics.ToImmutableArray());
        }