public void GetEnabledAnalyzers_ReturnsEmptyList_WhenDiagnosticsAreDisabled()
        {
            var sut         = new SymbolicExecutionAnalyzerFactory();
            var diagnostics = new Dictionary <string, ReportDiagnostic>
            {
                { EmptyNullableValueAccess, ReportDiagnostic.Suppress },
                { ObjectsShouldNotBeDisposedMoreThanOnce, ReportDiagnostic.Suppress },
                { EmptyCollectionsShouldNotBeEnumerated, ReportDiagnostic.Suppress }
            }.ToImmutableDictionary();
            var context          = CreateSyntaxNodeAnalysisContext(diagnostics);
            var analyzers        = sut.GetEnabledAnalyzers(context).ToList();
            var enabledAnalyzers =
                analyzers
                .SelectMany(analyzer => analyzer.SupportedDiagnostics.Select(descriptor => descriptor.Id))
                .ToList();

            CollectionAssert.AreEquivalent(new List <string>(), enabledAnalyzers);
        }
Ejemplo n.º 2
0
        public void GetEnabledAnalyzers_ReturnsDiagnostic_WhenEnabled(ReportDiagnostic reportDiagnostic)
        {
            var sut         = new SymbolicExecutionAnalyzerFactory();
            var diagnostics = new Dictionary <string, ReportDiagnostic>
            {
                { EmptyNullableValueAccess, reportDiagnostic },
                { ObjectsShouldNotBeDisposedMoreThanOnce, ReportDiagnostic.Suppress },
                { EmptyCollectionsShouldNotBeEnumerated, ReportDiagnostic.Suppress },
                { ConditionEvaluatesToConstantBug, ReportDiagnostic.Suppress },
                { ConditionEvaluatesToConstantCodeSmell, ReportDiagnostic.Suppress },
                { InvalidCastToInterface, ReportDiagnostic.Suppress },
                { NullPointerDereference, ReportDiagnostic.Suppress }
            }.ToImmutableDictionary();
            var context          = CreateSyntaxNodeAnalysisContext(diagnostics);
            var analyzers        = sut.GetEnabledAnalyzers(context).ToList();
            var enabledAnalyzers =
                analyzers
                .SelectMany(analyzer => analyzer.SupportedDiagnostics.Select(descriptor => descriptor.Id))
                .ToList();

            CollectionAssert.AreEquivalent(enabledAnalyzers, new[] { EmptyNullableValueAccess });
        }