コード例 #1
0
        protected override async Task VerifyAsync(string source, string language, DiagnosticAnalyzer[] analyzers, DiagnosticDescription[] expectedDiagnostics, Action <Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = true, string rootNamespace = null)
        {
            using (var workspace = await CreateWorkspaceFromFileAsync(source, language, rootNamespace))
            {
                var documentId = workspace.Documents[0].Id;
                var document   = workspace.CurrentSolution.GetDocument(documentId);
                var span       = (await document.GetSyntaxRootAsync()).FullSpan;

                var actualDiagnostics = new List <Diagnostic>();
                foreach (var analyzer in analyzers)
                {
                    actualDiagnostics.AddRange(
                        await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(analyzer, document, span, onAnalyzerException, logAnalyzerExceptionAsDiagnostics));
                }

                actualDiagnostics.Verify(expectedDiagnostics);
            }
        }