public void MethodShouldBeNamedAccordingToSynchronicity(string tasksVersion) =>
 Verifier.VerifyAnalyzer(@"TestCases\MethodShouldBeNamedAccordingToSynchronicity.cs",
                         new MethodShouldBeNamedAccordingToSynchronicity(),
                         additionalReferences:
                         MetadataReferenceFacade.GetSystemThreadingTasksExtensions(tasksVersion)
                         .Union(MetadataReferenceFacade.GetSystemComponentModelPrimitives())
                         .Union(NuGetMetadataReference.MicrosoftAspNetSignalRCore()));
Ejemplo n.º 2
0
 public void SonarAnalysis_ByDefault_ExecuteRule()
 {
     foreach (var testCase in TestCases)
     {
         // ToDo: We test that a rule is enabled only by checking the issues are reported
         Verifier.VerifyAnalyzer(testCase.Path,
                                 testCase.Analyzer,
                                 ParseOptionsHelper.FromCSharp8,
                                 additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
     }
 }
Ejemplo n.º 3
0
        public void SonarAnalysis_WhenReportDiagnosticActionNotNull_AllowToContolWhetherOrNotToReport()
        {
            try
            {
                SonarAnalysisContext.ReportDiagnostic = context =>
                {
                    if (context.Diagnostic.Id != AnonymousDelegateEventUnsubscribe.DiagnosticId)
                    {
                        // Verifier expects all diagnostics to increase the counter in order to check that all rules call the
                        // extension method and not the direct `ReportDiagnostic`.
                        DiagnosticVerifier.SuppressionHandler.IncrementReportCount(context.Diagnostic.Id);
                        context.ReportDiagnostic(context.Diagnostic);
                    }
                };

                // Because the Verifier sets the SonarAnalysisContext.ShouldDiagnosticBeReported delegate we end up in a case
                // where the Debug.Assert of the AnalysisContextExtensions.ReportDiagnostic() method will raise.
                using (new AssertIgnoreScope())
                {
                    foreach (var testCase in TestCases)
                    {
                        if (testCase.Analyzer is AnonymousDelegateEventUnsubscribe)
                        {
                            Verifier.VerifyNoIssueReported(testCase.Path,
                                                           testCase.Analyzer,
                                                           ParseOptionsHelper.FromCSharp8,
                                                           additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
                        }
                        else
                        {
                            Verifier.VerifyAnalyzer(testCase.Path,
                                                    testCase.Analyzer,
                                                    ParseOptionsHelper.FromCSharp8,
                                                    additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
                        }
                    }
                }
            }
            finally
            {
                SonarAnalysisContext.ReportDiagnostic = null;
            }
        }
Ejemplo n.º 4
0
        public void SonarAnalysis_WhenShouldAnalysisBeDisabledReturnsTrue_NoIssueReported()
        {
            SonarAnalysisContext.ShouldExecuteRegisteredAction = (diags, tree) => false;

            try
            {
                foreach (var testCase in TestCases)
                {
                    // ToDo: We should find a way to ack the fact the action was not run
                    Verifier.VerifyNoIssueReported(testCase.Path,
                                                   testCase.Analyzer,
                                                   ParseOptionsHelper.FromCSharp8,
                                                   additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
                }
            }
            finally
            {
                SonarAnalysisContext.ShouldExecuteRegisteredAction = null;
            }
        }
Ejemplo n.º 5
0
 public void GetHashCodeEqualsOverride_CSharp9() =>
 Verifier.VerifyAnalyzerFromCSharp9Library(@"TestCases\GetHashCodeEqualsOverride.CSharp9.cs",
                                           new GetHashCodeEqualsOverride(),
                                           additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
Ejemplo n.º 6
0
 public void LiteralsShouldNotBePassedAsLocalizedParameters_CSharp9() =>
 Verifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs",
                                           new LiteralsShouldNotBePassedAsLocalizedParameters(),
                                           additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
 public void NonFlagsEnumInBitwiseOperation() =>
 Verifier.VerifyAnalyzer(@"TestCases\NonFlagsEnumInBitwiseOperation.cs",
                         new NonFlagsEnumInBitwiseOperation(),
                         additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives());
 private static IEnumerable <MetadataReference> GetAdditionalReferences() =>
 MetadataReferenceFacade.GetSystemNetHttp().Concat(MetadataReferenceFacade.GetSystemComponentModelPrimitives());