private void HasDiagnostic(Document document, string diagnosticId, IDiagnosticLocator locator)
        {
            var reporteddiagnostics = GetDiagnostics(document).Where(d => locator.Match(d.Location)).ToArray();
            var matchedDiagnostics  = reporteddiagnostics.Count(d => d.Id == diagnosticId);

            if (matchedDiagnostics == 0)
            {
                throw RoslynTestKitException.DiagnosticNotFound(diagnosticId, locator, reporteddiagnostics);
            }
        }
        protected void NoDiagnostic(Document document, string diagnosticId, IDiagnosticLocator locator = null)
        {
            var diagnostics = GetDiagnostics(document);

            if (locator != null)
            {
                diagnostics = diagnostics.Where(x => locator.Match(x.Location)).ToImmutableArray();
            }
            var unexpectedDiagnostics = diagnostics.Where(d => d.Id == diagnosticId).ToList();

            if (unexpectedDiagnostics.Count > 0)
            {
                throw RoslynTestKitException.UnexpectedDiagnostic(unexpectedDiagnostics);
            }
        }
        private IEnumerable <Diagnostic> GetReportedDiagnostics(Document document, IDiagnosticLocator locator)
        {
            var allReportedDiagnostics = GetAllReportedDiagnostics(document);

            foreach (var diagnostic in allReportedDiagnostics)
            {
                if (locator.Match(diagnostic.Location))
                {
                    yield return(diagnostic);
                }
                else if (ThrowsWhenInputDocumentContainsError && diagnostic.Severity == DiagnosticSeverity.Error)
                {
                    throw new InvalidOperationException($"Input document contains unexpected error: {diagnostic.GetMessage()}");
                }
            }
        }
 private IEnumerable <Diagnostic> GetReportedDiagnostics(Document document, IDiagnosticLocator locator)
 {
     return(GetAllReportedDiagnostics(document).Where(d => locator.Match(d.Location)));
 }
Пример #5
0
 private static IEnumerable <Diagnostic> GetReportedDiagnostics(Document document, IDiagnosticLocator locator)
 {
     return(document.GetSemanticModelAsync().Result.GetDiagnostics().Where(d => locator.Match(d.Location)));
 }