Exemplo n.º 1
0
 public void DoNotCallExitMethods()
 {
     Verifier.VerifyAnalyzer(@"TestCases\DoNotCallExitMethods.cs",
                             new DoNotCallExitMethods(),
                             null,
                             AssemblyReference.FromFramework("System.Windows.Forms.dll"));
 }
Exemplo n.º 2
0
 public void WcfNonVoidOneWay()
 {
     Verifier.VerifyAnalyzer(
         @"TestCases\WcfNonVoidOneWay.cs",
         new WcfNonVoidOneWay(),
         additionalReferences: AssemblyReference.FromFramework("System.ServiceModel.dll"));
 }
Exemplo n.º 3
0
 public void WcfMissingContractAttribute()
 {
     Verifier.VerifyAnalyzer(
         @"TestCases\WcfMissingContractAttribute.cs",
         new WcfMissingContractAttribute(),
         additionalReferences: AssemblyReference.FromFramework("System.ServiceModel.dll"));
 }
 public void DoNotUseIif_CodeFix()
 {
     Verifier.VerifyCodeFix(
         @"TestCases\DoNotUseIif.vb",
         @"TestCases\DoNotUseIif.Fixed.vb",
         new SonarAnalyzer.Rules.VisualBasic.DoNotUseIif(),
         new SonarAnalyzer.Rules.VisualBasic.DoNotUseIifCodeFixProvider(),
         additionalReferences: AssemblyReference.FromFramework("Microsoft.VisualBasic.dll"));
 }
Exemplo n.º 5
0
 public void ShouldImplementExportedInterfaces_Partial()
 {
     Verifier.VerifyAnalyzer(new[]
     {
         @"TestCases\ShouldImplementExportedInterfaces_Part1.cs",
         @"TestCases\ShouldImplementExportedInterfaces_Part2.cs",
     },
                             new ShouldImplementExportedInterfaces(),
                             additionalReferences: AssemblyReference.FromFramework("System.ComponentModel.Composition.dll"));
 }
Exemplo n.º 6
0
 public void MarkWindowsFormsMainWithStaThread()
 {
     Verifier.VerifyAnalyzer(@"TestCases\MarkWindowsFormsMainWithStaThread.cs",
                             new MarkWindowsFormsMainWithStaThread(),
                             additionalReferences: AssemblyReference.FromFramework("System.Windows.Forms.dll"));
 }
Exemplo n.º 7
0
 public void LdapConnectionsShouldBeSecure()
 {
     Verifier.VerifyAnalyzer(@"TestCases\LdapConnectionShouldBeSecure.cs",
                             new LdapConnectionShouldBeSecure(),
                             additionalReferences: AssemblyReference.FromFramework("System.DirectoryServices.dll"));
 }
Exemplo n.º 8
0
 public void CookiesShouldNotContainSensitiveData()
 {
     Verifier.VerifyAnalyzer(@"TestCases\CookieShouldNotContainSensitiveData.cs",
                             new CookieShouldNotContainSensitiveData(),
                             additionalReferences: AssemblyReference.FromFramework("System.Web.dll"));
 }
Exemplo n.º 9
0
 public void TypesShouldNotExtendOutdatedBaseTypes()
 {
     Verifier.VerifyAnalyzer(@"TestCases\TypesShouldNotExtendOutdatedBaseTypes.cs",
                             new TypesShouldNotExtendOutdatedBaseTypes(),
                             additionalReferences: AssemblyReference.FromFramework("System.Xml.dll"));
 }
 public void ConstructorArgumentValueShouldExist()
 {
     Verifier.VerifyAnalyzer(@"TestCases\ConstructorArgumentValueShouldExist.cs",
                             new ConstructorArgumentValueShouldExist(),
                             additionalReferences: AssemblyReference.FromFramework("System.Xaml.dll"));
 }
Exemplo n.º 11
0
        public void Compile()
        {
            using (var workspace = new AdhocWorkspace())
            {
                var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp)
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll")))
                               .AddDocument("test", SymbolHelperTest.TestInput);
                var compilation = document.Project.GetCompilationAsync().Result;
                var tree        = compilation.SyntaxTrees.First();
                semanticModel = compilation.GetSemanticModel(tree);

                baseClassDeclaration = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>()
                                       .First(m => m.Identifier.ValueText == "Base");
                derivedClassDeclaration1 = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>()
                                           .First(m => m.Identifier.ValueText == "Derived1");
                derivedClassDeclaration2 = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>()
                                           .First(m => m.Identifier.ValueText == "Derived2");
            }
        }
Exemplo n.º 12
0
 public void Compile()
 {
     using (var workspace = new AdhocWorkspace())
     {
         var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp)
                        .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll")))
                        .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll")))
                        .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll")))
                        .AddDocument("test", TestInput);
         var compilation = document.Project.GetCompilationAsync().Result;
         var tree        = compilation.SyntaxTrees.First();
         semanticModel = compilation.GetSemanticModel(tree);
         statements    = tree.GetRoot().DescendantNodes()
                         .OfType <MethodDeclarationSyntax>()
                         .First(m => m.Identifier.ValueText == "TestMethod").Body
                         .DescendantNodes()
                         .OfType <StatementSyntax>().ToList();
     }
 }
 public void CookiesShouldBeHttpOnly()
 {
     Verifier.VerifyAnalyzer(@"TestCases\CookieShouldBeHttpOnly.cs",
                             new CookieShouldBeHttpOnly(),
                             additionalReferences: AssemblyReference.FromFramework("System.Web.dll"));
 }
Exemplo n.º 14
0
 public void CollectionPropertiesShouldBeReadOnly()
 {
     Verifier.VerifyAnalyzer(@"TestCases\CollectionPropertiesShouldBeReadOnly.cs",
                             new CollectionPropertiesShouldBeReadOnly(),
                             additionalReferences: AssemblyReference.FromFramework("System.Runtime.Serialization.dll"));
 }
Exemplo n.º 15
0
 public void ReturnEmptyCollectionInsteadOfNull()
 {
     Verifier.VerifyAnalyzer(@"TestCases\ReturnEmptyCollectionInsteadOfNull.cs",
                             new ReturnEmptyCollectionInsteadOfNull(),
                             additionalReferences: AssemblyReference.FromFramework("System.Xml.dll"));
 }
        private static async Task <bool> IsGeneratedAsync(string content, GeneratedCodeRecognizer generatedCodeRecognizer)
        {
            using (var workspace = new AdhocWorkspace())
            {
                var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp)
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll")))
                               .AddDocument("Foo.cs", content);

                var compilation = document.Project.GetCompilationAsync().Result;
                var tree        = await document.GetSyntaxTreeAsync();

                return(tree.IsGenerated(generatedCodeRecognizer, compilation));
            }
        }
        private static void VerifyEmpty(string name, string content, DiagnosticAnalyzer diagnosticAnalyzer)
        {
            using (var workspace = new AdhocWorkspace())
            {
                var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp)
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll")))
                               .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll")))
                               .AddDocument(name, content);

                var compilation = document.Project.GetCompilationAsync().Result;

                var diagnostics = Verifier.GetDiagnostics(compilation, diagnosticAnalyzer);

                diagnostics.Should().HaveCount(0);
            }
        }
 public void DoNotInstantiateSharedClasses_InTest()
 {
     Verifier.VerifyNoIssueReportedInTest(@"TestCases\DoNotInstantiateSharedClasses.cs",
                                          new DoNotInstantiateSharedClasses(),
                                          additionalReferences: AssemblyReference.FromFramework("System.ComponentModel.Composition.dll"));
 }
 public void SetLocaleForDataTypes()
 {
     Verifier.VerifyAnalyzer(@"TestCases\SetLocaleForDataTypes.cs",
                             new SetLocaleForDataTypes(),
                             additionalReferences: AssemblyReference.FromFramework("System.Data.dll"));
 }
Exemplo n.º 20
0
 public void PartCreationPolicyShouldBeUsedWithExportAttribute()
 {
     Verifier.VerifyAnalyzer(@"TestCases\PartCreationPolicyShouldBeUsedWithExportAttribute.cs",
                             new PartCreationPolicyShouldBeUsedWithExportAttribute(),
                             additionalReferences: AssemblyReference.FromFramework("System.ComponentModel.Composition.dll"));
 }