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));
        }
        private IList <Diagnostic> GetSortedAnalyzerDiagnostics([NotNull] AnalyzerTestContext context,
                                                                [NotNull] DocumentWithSpans documentWithSpans)
        {
            IEnumerable <Diagnostic> diagnostics =
                EnumerateDiagnosticsForDocument(documentWithSpans.Document, context.ValidationMode,
                                                context.DiagnosticsCaptureMode).Where(d => d.Id == DiagnosticId);

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

            return(diagnostics.ToImmutableArray());
        }