コード例 #1
0
        public void Setup()
        {
            var analyzerAssemblyPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "Microsoft.CodeAnalysis.CSharp.Features.dll"
                );

            _options = new Options(
                analyzerPath: analyzerAssemblyPath,
                solutionPath: _solutionPath,
                analyzerIds: ImmutableHashSet.Create(AnalyzerName),
                refactoringNodes: ImmutableHashSet <string> .Empty,
                runConcurrent: true,
                reportSuppressedDiagnostics: true,
                applyChanges: false,
                useAll: false,
                iterations: 1,
                usePersistentStorage: false,
                fullSolutionAnalysis: false,
                incrementalAnalyzerNames: ImmutableArray <string> .Empty
                );

            _workspace = AnalyzerRunnerHelper.CreateWorkspace();
            _diagnosticAnalyzerRunner = new DiagnosticAnalyzerRunner(_workspace, _options);

            _ =
                _workspace.OpenSolutionAsync(
                    _solutionPath,
                    progress: null,
                    CancellationToken.None
                    ).Result;
        }
コード例 #2
0
        public async Task TestMethod1()
        {
            const string Test = "";

            var analyzer    = new RoslynAnalyzerTemplateAnalyzer();
            var diagnostics = await DiagnosticAnalyzerRunner.Run(analyzer, Test);

            Assert.AreEqual(0, diagnostics.Length);
        }
コード例 #3
0
        public async Task TestMethod2()
        {
            var analyzer    = new RoslynAnalyzerTemplateAnalyzer();
            var diagnostics = await DiagnosticAnalyzerRunner.Run(analyzer, ReadCodes("TypeName.cs"));

            var actual = diagnostics
                         .Where(x => x.Id != "CS1591") // Ignore "Missing XML comment for publicly visible type or member"
                         .Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
                         .ToArray();

            Assert.AreEqual(1, actual.Length);
            Assert.AreEqual("RoslynAnalyzerTemplate", actual.First().Id);
            Assert.AreEqual("Type name 'TypeName' contains lowercase letters", actual.First().GetMessage());

            LocationAssert.HaveTheSpan(
                new LinePosition(9, 10),
                new LinePosition(9, 18),
                actual.First().Location
                );
        }