Exemplo n.º 1
0
        public static async Task <Location> Create()
        {
            var ds = await DiagnosticAnalyzerRunner.Run(
                new NullAnalyzer(),
                ExampleCode.ContainingSyntaxError
                );

            return(ds[0].Location);
        }
Exemplo n.º 2
0
        public async Task WhenGivenAnyCodes_ItShouldGetToCallOperationBlockAction()
        {
            var callCount    = 0;
            var stubAnalyzer = new StubAnalyzer(
                new AnalyzerActions
            {
                OperationBlockAction = _ => callCount++
            }
                );

            await DiagnosticAnalyzerRunner.Run(stubAnalyzer, ExampleCode.DiagnosticsFreeClassLibrary);

            Assert.AreNotEqual(0, callCount);
        }
Exemplo n.º 3
0
        public async Task Format()
        {
            var diagnostics = await DiagnosticAnalyzerRunner.Run(
                new NullAnalyzer(),
                ExampleCode.ContainingSyntaxError
                );

            var actual   = DiagnosticsFormatter.Format(diagnostics);
            var expected =
                @"// /0/Test0.cs(9,1): error CS0116: A namespace cannot directly contain members such as fields or methods
DiagnosticResult.CompilerError(""CS0116"").WithSpan(""/0/Test0.cs"", 9, 1, 9, 6),
";

            Assert.AreEqual(expected, actual);
        }
        public async Task WhenGivenAnyCodes_RecordAllActionHistory()
        {
            var spy     = new SpyAnalyzer();
            var builder = new StringBuilder();
            var failed  = false;

            await DiagnosticAnalyzerRunner.Run(spy, ExampleCode.DiagnosticsFreeClassLibrary);

            if (0 == spy.CodeBlockActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.CodeBlockActionHistory));
            }

            if (0 == spy.CodeBlockStartActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.CodeBlockStartActionHistory));
            }

            if (0 == spy.CompilationActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.CompilationActionHistory));
            }

            if (0 == spy.CompilationStartActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.CompilationStartActionHistory));
            }

            if (0 == spy.OperationActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.OperationActionHistory));
            }

            if (0 == spy.OperationBlockActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.OperationBlockActionHistory));
            }

            if (0 == spy.OperationBlockStartActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.OperationBlockStartActionHistory));
            }

            if (0 == spy.SemanticModelActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.SemanticModelActionHistory));
            }

            if (0 == spy.SymbolActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.SymbolActionHistory));
            }

            if (0 == spy.SymbolStartActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.SymbolStartActionHistory));
            }

            if (0 == spy.SyntaxNodeActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.SyntaxNodeActionHistory));
            }

            if (0 == spy.SyntaxTreeActionHistory.Count)
            {
                failed = true;
                builder.AppendLine(nameof(spy.SyntaxTreeActionHistory));
            }

            Assert.IsFalse(failed, builder.ToString());
        }