示例#1
0
        public void InstantiateDiags_MultipleAssemblies_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string exampleAnalyzer1DllPath = typeof(ExampleAnalyzer1.CSharpAnalyzer).Assembly.Location;
            string nonAnalyzerAssemblyPath = this.GetType().Assembly.Location;
            string exampleAnalyzer2DllPath = typeof(ExampleAnalyzer2.ExampleAnalyzer2).Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp,
                                                                                     exampleAnalyzer1DllPath,
                                                                                     nonAnalyzerAssemblyPath,
                                                                                     exampleAnalyzer2DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.ConfigurableAnalyzer));
            Assert_AnalyzerNotPresent(result, typeof(ExampleAnalyzer1.AbstractAnalyzer)); // not expecting abstract analyzers

            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer2.ExampleAnalyzer2));

            Assert.AreEqual(3, result.Count(), "Unexpected number of C# analyzers returned");
        }
示例#2
0
        public void InstantiateDiags_MultipleAssemblies_AnalyzersFound()
        {
            // This test expects that we can load analyzers from multiple paths at once.
            // SFSRAP-26: We should be able to load analyzers compiled using both Roslyn 1.1 and 1.0
            // (RoslynAnalyzer34 and RoslynAnalyzer10, respectively)

            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string RoslynAnalyzer34DllPath = typeof(RoslynAnalyzer34.CSharpAnalyzer).Assembly.Location;
            string nonAnalyzerAssemblyPath = GetType().Assembly.Location;
            //string roslynAnalyzer10DllPath = typeof(RoslynAnalyzer10.ExampleAnalyzer2).Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp,
                                                                                     RoslynAnalyzer34DllPath,
                                                                                     nonAnalyzerAssemblyPath /*,
                                                                                                              * roslynAnalyzer10DllPath*/);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.ConfigurableAnalyzer));
            Assert_AnalyzerIsPresent(result, "RoslynAnalyzer34.InternalAnalyzer");

            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer34.AbstractAnalyzer)); // not expecting abstract analyzers

            //Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer10.ExampleAnalyzer2));

            result.Should().HaveCount(4, "Unexpected number of C# analyzers returned");
        }
        public void ScanDirectory_MultipleAnalyzerAssemblies()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string testDirectoryPath = Path.Combine(TestContext.DeploymentDirectory, "twoAnalyzers");

            string exampleAnalyzer1Path = Path.Combine(testDirectoryPath, "ExampleAnalyzer1.dll");
            Assert.IsTrue(File.Exists(exampleAnalyzer1Path), "Test setup error: expected assembly does not exist: {0}", exampleAnalyzer1Path);
            string exampleAnalyzer2Path = Path.Combine(testDirectoryPath, "ExampleAnalyzer2.dll");
            Assert.IsTrue(File.Exists(exampleAnalyzer2Path), "Test setup error: expected assembly does not exist: {0}", exampleAnalyzer2Path);

            // Act
            IEnumerable<DiagnosticAnalyzer> csharpDiagnostics = scanner.InstantiateDiagnostics(testDirectoryPath, LanguageNames.CSharp);
            IEnumerable<DiagnosticAnalyzer> vbDiagnostics = scanner.InstantiateDiagnostics(testDirectoryPath, LanguageNames.VisualBasic);

            // Assert
            // ConfigurableAnalyzer is both C# and VB, so should appear in both
            Assert.AreEqual(3, csharpDiagnostics.Count(), "Expecting 3 C# analyzers");
            Assert.AreEqual(2, vbDiagnostics.Count(), "Expecting 2 VB analyzers");

            // Using name comparison because type comparison fails if the types are from assemblies with different paths (even if copied)
            // Loaded from ExampleAnalyzer1.dll
            Assert_AnalyzerIsPresent(csharpDiagnostics, "ExampleAnalyzer1.CSharpAnalyzer");
            Assert_AnalyzerIsPresent(csharpDiagnostics, "ExampleAnalyzer1.ConfigurableAnalyzer");
            Assert_AnalyzerNotPresent(csharpDiagnostics, "ExampleAnalyzer1.AbstractAnalyzer");

            Assert_AnalyzerIsPresent(vbDiagnostics, "ExampleAnalyzer1.VBAnalyzer");
            Assert_AnalyzerIsPresent(vbDiagnostics, "ExampleAnalyzer1.ConfigurableAnalyzer");
            Assert_AnalyzerNotPresent(vbDiagnostics, "ExampleAnalyzer1.AbstractAnalyzer");

            // Loaded from ExampleAnalyzer2.dll
            Assert_AnalyzerIsPresent(csharpDiagnostics, "ExampleAnalyzer2.ExampleAnalyzer2");
        }
示例#4
0
        public void InstantiateDiags_CSharp_NoFiles()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp /* no files */);

            // Assert
            result.Should().NotBeNull("Not expecting InstantiateDiagnostics to return null");
            result.Any().Should().BeFalse("Not expecting any diagnostics to have been found");
        }
        public void InstantiateDiags_CSharp_NoFiles()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp /* no files */);

            // Assert
            Assert.IsNotNull(result, "Not expecting InstantiateDiagnostics to return null");
            Assert.IsFalse(result.Any(), "Not expecting any diagnostics to have been found");
        }
示例#6
0
        public void InstantiateDiags_VB_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string RoslynAnalyzer34DllPath = typeof(RoslynAnalyzer34.CSharpAnalyzer).Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.VisualBasic, RoslynAnalyzer34DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.VBAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.ConfigurableAnalyzer));
            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer34.AbstractAnalyzer)); // not expecting abstract analyzers

            result.Count().Should().Be(2, "Expecting 2 VB analyzers");
        }
示例#7
0
        public void InstantiateDiags_VB_NoAnalyzers()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string corLibDllPath = typeof(object).Assembly.Location;
            string thisDllPath   = GetType().Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.VisualBasic,
                                                                                     corLibDllPath,
                                                                                     thisDllPath);

            // Assert
            result.Should().NotBeNull("Not expecting InstantiateDiagnostics to return null");
            result.Any().Should().BeFalse("Not expecting any diagnostics to have been found");
        }
        public void InstantiateDiags_VB_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string roslynAnalyzer11DllPath = typeof(RoslynAnalyzer11.CSharpAnalyzer).Assembly.Location;

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.VisualBasic, roslynAnalyzer11DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.VBAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.ConfigurableAnalyzer));
            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer11.AbstractAnalyzer)); // not expecting abstract analyzers

            Assert.AreEqual(2, result.Count(), "Expecting 2 VB analyzers");
        }
        public void InstantiateDiags_VB_NoAnalyzers()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string corLibDllPath = typeof(object).Assembly.Location;
            string thisDllPath = this.GetType().Assembly.Location;

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.VisualBasic,
                corLibDllPath,
                thisDllPath);

            // Assert
            Assert.IsNotNull(result, "Not expecting InstantiateDiagnostics to return null");
            Assert.IsFalse(result.Any(), "Not expecting any diagnostics to have been found");
        }
示例#10
0
        public void InstantiateDiags_CSharp_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string exampleAnalyzer1DllPath = typeof(ExampleAnalyzer1.CSharpAnalyzer).Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp, exampleAnalyzer1DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.ConfigurableAnalyzer));
            Assert_AnalyzerNotPresent(result, typeof(ExampleAnalyzer1.AbstractAnalyzer)); // not expecting abstract analyzers

            Assert.AreEqual(2, result.Count(), "Expecting 2 C# analyzers");
        }
        public void ScanDirectoryWithNoAnalyzerAssemblies()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            // place a single assembly in the test directory, that does not have any analyzers in it
            string noAnalyzerAssemblyPath = typeof(DiagnosticAssemblyScannerTests).Assembly.Location;
            string testDirectoryPath = TestUtils.CreateTestDirectory(this.TestContext);
            string testAssemblyPath = Path.Combine(testDirectoryPath, Path.GetFileName(noAnalyzerAssemblyPath));
            File.Copy(noAnalyzerAssemblyPath, testAssemblyPath);

            // Act
            IEnumerable<DiagnosticAnalyzer> csharpDiagnostics = scanner.InstantiateDiagnostics(testDirectoryPath, LanguageNames.CSharp);
            IEnumerable<DiagnosticAnalyzer> vbDiagnostics = scanner.InstantiateDiagnostics(testDirectoryPath, LanguageNames.VisualBasic);

            // Assert
            Assert.AreEqual(0, csharpDiagnostics.Count(), "No analyzers should have been detected");
            Assert.AreEqual(0, vbDiagnostics.Count(), "No analyzers should have been detected");
        }
示例#12
0
        public void InstantiateDiags_CSharp_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger, TestContext.DeploymentDirectory);

            string RoslynAnalyzer34DllPath = typeof(RoslynAnalyzer34.CSharpAnalyzer).Assembly.Location;

            // Act
            IEnumerable <DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp, RoslynAnalyzer34DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer34.ConfigurableAnalyzer));
            Assert_AnalyzerIsPresent(result, "RoslynAnalyzer34.InternalAnalyzer");

            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer34.AbstractAnalyzer));     // not expecting abstract analyzers
            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer34.UnattributedAnalyzer)); // not expecting analyzers without attributes

            result.Count().Should().Be(3, "Expecting 3 C# analyzers");
        }
        public void InstantiateDiags_CSharp_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger, this.TestContext.DeploymentDirectory);

            string roslynAnalyzer11DllPath = typeof(RoslynAnalyzer11.CSharpAnalyzer).Assembly.Location;

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp, roslynAnalyzer11DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.ConfigurableAnalyzer));
            Assert_AnalyzerIsPresent(result, "RoslynAnalyzer11.InternalAnalyzer");

            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer11.AbstractAnalyzer)); // not expecting abstract analyzers
            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer11.UnattributedAnalyzer)); // not expecting analyzers without attributes

            Assert.AreEqual(3, result.Count(), "Expecting 3 C# analyzers");
        }
        public void InstantiateDiags_MultipleAssemblies_AnalyzersFound()
        {
            // This test expects that we can load analyzers from multiple paths at once.
            // SFSRAP-26: We should be able to load analyzers compiled using both Roslyn 1.1 and 1.0
            // (RoslynAnalyzer11 and RoslynAnalyzer10, respectively)

            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string roslynAnalyzer11DllPath = typeof(RoslynAnalyzer11.CSharpAnalyzer).Assembly.Location;
            string nonAnalyzerAssemblyPath = this.GetType().Assembly.Location;
            string roslynAnalyzer10DllPath = typeof(RoslynAnalyzer10.ExampleAnalyzer2).Assembly.Location;

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp,
                roslynAnalyzer11DllPath,
                nonAnalyzerAssemblyPath,
                roslynAnalyzer10DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer11.ConfigurableAnalyzer));
            Assert_AnalyzerIsPresent(result, "RoslynAnalyzer11.InternalAnalyzer");

            Assert_AnalyzerNotPresent(result, typeof(RoslynAnalyzer11.AbstractAnalyzer)); // not expecting abstract analyzers

            Assert_AnalyzerIsPresent(result, typeof(RoslynAnalyzer10.ExampleAnalyzer2));

            Assert.AreEqual(4, result.Count(), "Unexpected number of C# analyzers returned");
        }
        public void InstantiateDiags_MultipleAssemblies_AnalyzersFound()
        {
            // Arrange
            TestLogger logger = new TestLogger();
            DiagnosticAssemblyScanner scanner = new DiagnosticAssemblyScanner(logger);

            string exampleAnalyzer1DllPath = typeof(ExampleAnalyzer1.CSharpAnalyzer).Assembly.Location;
            string nonAnalyzerAssemblyPath = this.GetType().Assembly.Location;
            string exampleAnalyzer2DllPath = typeof(ExampleAnalyzer2.ExampleAnalyzer2).Assembly.Location;

            // Act
            IEnumerable<DiagnosticAnalyzer> result = scanner.InstantiateDiagnostics(LanguageNames.CSharp,
                exampleAnalyzer1DllPath,
                nonAnalyzerAssemblyPath,
                exampleAnalyzer2DllPath);

            // Assert
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.CSharpAnalyzer));
            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer1.ConfigurableAnalyzer));
            Assert_AnalyzerNotPresent(result, typeof(ExampleAnalyzer1.AbstractAnalyzer)); // not expecting abstract analyzers

            Assert_AnalyzerIsPresent(result, typeof(ExampleAnalyzer2.ExampleAnalyzer2));

            Assert.AreEqual(3, result.Count(), "Unexpected number of C# analyzers returned");
        }