예제 #1
0
        public void CanCreateDiagnosticForAnalyzerLoadFailure(
            AnalyzerLoadFailureEventArgs.FailureErrorCode errorCode,
            [CombinatorialValues(LanguageNames.CSharp, LanguageNames.VisualBasic, null)] string?languageName)
        {
            // One potential value is None, which isn't actually a valid enum value to test.
            if (errorCode == AnalyzerLoadFailureEventArgs.FailureErrorCode.None)
            {
                return;
            }

            var expectsTypeName = errorCode is AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer or
                                  AnalyzerLoadFailureEventArgs.FailureErrorCode.ReferencesFramework;

            const string analyzerTypeName = "AnalyzerTypeName";
            var          eventArgs        = new AnalyzerLoadFailureEventArgs(
                errorCode,
                message: errorCode.ToString(),
                typeNameOpt: expectsTypeName ? analyzerTypeName : null);

            // Ensure CreateAnalyzerLoadFailureDiagnostic doesn't fail when called. We don't assert much about the resulting
            // diagnostic -- this is primarly to ensure we don't forget to update it if a new error code is added.
            var diagnostic = DocumentAnalysisExecutor.CreateAnalyzerLoadFailureDiagnostic(eventArgs, "Analyzer.dll", null, languageName);

            Assert.Equal(languageName, diagnostic.Language);

            if (expectsTypeName)
            {
                Assert.Contains(analyzerTypeName, diagnostic.Message);
            }
            else
            {
                Assert.DoesNotContain(analyzerTypeName, diagnostic.Message);
            }
        }
예제 #2
0
 public static DiagnosticData CreateAnalyzerLoadFailureDiagnostic(AnalyzerLoadFailureEventArgs e, string fullPath, ProjectId?projectId, string?language)
 => DocumentAnalysisExecutor.CreateAnalyzerLoadFailureDiagnostic(e, fullPath, projectId, language);