Exemplo n.º 1
0
        /// <summary>
        /// Called to test a C# DiagnosticAnalyzer when applied on the inputted strings as a source
        /// Note: input a DiagnosticResult for each Diagnostic expected
        /// </summary>
        /// <param name="sources">An array of strings to create source documents from to run the analyzers on</param>
        /// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
        protected void VerifyDiagnostic(string[] sources, DiagnosticResult[] expected)
        {
            var actual = _diagnosticAnalyzer.GetSortedDiagnostics(sources, LanguageNames.CSharp);
            var result = _diagnosticAnalyzer.VerifyDiagnosticResults(actual, expected);

            result.Success.ShouldBe(true, result.ErrorMessage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// General method that gets a collection of actual diagnostics found in the source after the analyzer is run,
        /// then verifies each of them.
        /// </summary>
        /// <param name="sources">An array of strings to create source documents from to run the analyzers on</param>
        /// <param name="language">The language of the classes represented by the source strings</param>
        /// <param name="analyzer">The analyzer to be run on the source code</param>
        /// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
        private static void InvokeAnalyzerAndVerifyDiagnostics(
            string[] sources,
            string language,
            DiagnosticAnalyzer analyzer,
            params DiagnosticResult[] expected)
        {
            var diagnostics = analyzer.GetSortedDiagnostics(language, sources);

            DiagnosticsVerifier.VerifyResults(diagnostics, analyzer, expected);
        }