public void AnalyzerOptionsArePassedToAllAnalyzers()
        {
            var             text    = new StringText(string.Empty, encodingOpt: null);
            AnalyzerOptions options = new AnalyzerOptions
                                      (
                new[] { new TestAdditionalText("myfilepath", text) }.ToImmutableArray <AdditionalText>()
                                      );

            var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode);
            var analyzer    = new OptionsDiagnosticAnalyzer <SyntaxKind>(options);

            compilation.GetAnalyzerDiagnostics(new[] { analyzer }, options);
            analyzer.VerifyAnalyzerOptions();
        }
        public void AnalyzerOptionsArePassedToAllAnalyzers()
        {
            AnalyzerOptions options = new AnalyzerOptions
                                      (
                new[] { new AdditionalFileStream("myfilepath") },
                new Dictionary <string, string> {
                { "optionName", "optionValue" }
            }
                                      );

            var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.Experimental));
            var analyzer    = new OptionsDiagnosticAnalyzer <SyntaxKind>(options);

            compilation.GetCSharpAnalyzerDiagnostics(new[] { analyzer }, options);
            analyzer.VerifyAnalyzerOptions();
        }
예제 #3
0
        public void AnalyzerOptionsArePassedToAllAnalyzers()
        {
            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromFile(TestResource.AllInOneCSharpCode, TestOptions.Regular))
            {
                var currentProject = workspace.CurrentSolution.Projects.Single();

                var additionalDocId = DocumentId.CreateNewId(currentProject.Id);
                var newSln          = workspace.CurrentSolution.AddAdditionalDocument(additionalDocId, "add.config", SourceText.From("random text"));
                currentProject = newSln.Projects.Single();
                var             additionalDocument = currentProject.GetAdditionalDocument(additionalDocId);
                AdditionalText  additionalStream   = new AdditionalTextDocument(additionalDocument.GetDocumentState());
                AnalyzerOptions options            = new AnalyzerOptions(ImmutableArray.Create(additionalStream));
                var             analyzer           = new OptionsDiagnosticAnalyzer <SyntaxKind>(expectedOptions: options);

                var sourceDocument = currentProject.Documents.Single();
                DiagnosticProviderTestUtilities.GetAllDiagnostics(analyzer, sourceDocument, new Text.TextSpan(0, sourceDocument.GetTextAsync().Result.Length));
                analyzer.VerifyAnalyzerOptions();
            }
        }
예제 #4
0
        public async Task AnalyzerOptionsArePassedToAllAnalyzers()
        {
            using var workspace = TestWorkspace.CreateCSharp(TestResource.AllInOneCSharpCode, TestOptions.Regular, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService);

            var additionalDocId   = DocumentId.CreateNewId(workspace.CurrentSolution.Projects.Single().Id);
            var additionalText    = new TestAdditionalText("add.config", SourceText.From("random text"));
            var options           = new AnalyzerOptions(ImmutableArray.Create <AdditionalText>(additionalText));
            var analyzer          = new OptionsDiagnosticAnalyzer <SyntaxKind>(expectedOptions: options);
            var analyzerReference = new AnalyzerImageReference(ImmutableArray.Create <DiagnosticAnalyzer>(analyzer));

            workspace.TryApplyChanges(workspace.CurrentSolution
                                      .WithAnalyzerReferences(new[] { analyzerReference })
                                      .AddAdditionalDocument(additionalDocId, "add.config", additionalText.GetText() !));

            var sourceDocument = workspace.CurrentSolution.Projects.Single().Documents.Single();
            await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(workspace, sourceDocument, new TextSpan(0, sourceDocument.GetTextAsync().Result.Length));

            analyzer.VerifyAnalyzerOptions();
        }
        public void AnalyzerOptionsArePassedToAllAnalyzers()
        {
            var text = new StringText(string.Empty, encodingOpt: null);
            AnalyzerOptions options = new AnalyzerOptions
            (
                new[] { new TestAdditionalText("myfilepath", text) }.ToImmutableArray<AdditionalText>()
            );

            var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode);
            var analyzer = new OptionsDiagnosticAnalyzer<SyntaxKind>(options);
            compilation.GetAnalyzerDiagnostics(new[] { analyzer }, options);
            analyzer.VerifyAnalyzerOptions();
        }
        public void AnalyzerOptionsArePassedToAllAnalyzers()
        {
            AnalyzerOptions options = new AnalyzerOptions
            (
                new[] { new AdditionalFileStream("myfilepath") },
                new Dictionary<string, string> { { "optionName", "optionValue" } }
            );

            var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.Experimental));
            var analyzer = new OptionsDiagnosticAnalyzer<SyntaxKind>(options);
            compilation.GetCSharpAnalyzerDiagnostics(new[] { analyzer }, options);
            analyzer.VerifyAnalyzerOptions();
        }