public Test()
            {
                SolutionTransforms.Add((solution, projectId) =>
                {
                    var parseOptions = (CSharpParseOptions)solution.GetProject(projectId) !.ParseOptions !;
                    solution         = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion));

                    var compilationOptions = solution.GetProject(projectId) !.CompilationOptions !;
                    compilationOptions     = compilationOptions.WithSpecificDiagnosticOptions(compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
                    solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);

                    var(analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
                    if (analyzerConfigSource is object)
                    {
                        foreach (var id in solution.ProjectIds)
                        {
                            var documentId = DocumentId.CreateNewId(id, ".editorconfig");
                            solution       = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
                        }
                    }

#if !CODE_STYLE
                    var options = solution.Options;
                    foreach (var(key, value) in remainingOptions)
                    {
                        options = options.WithChangedOption(key, value);
                    }

                    solution = solution.WithOptions(options);
#endif

                    return(solution);
                });
            }
Ejemplo n.º 2
0
            public Test()
            {
                MarkupOptions = Testing.MarkupOptions.UseFirstDescriptor;

                SolutionTransforms.Add((solution, projectId) =>
                {
                    var parseOptions = (VisualBasicParseOptions)solution.GetProject(projectId) !.ParseOptions !;
                    solution         = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion));

                    var(analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
                    if (analyzerConfigSource is object)
                    {
                        foreach (var id in solution.ProjectIds)
                        {
                            var documentId = DocumentId.CreateNewId(id, ".editorconfig");
                            solution       = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
                        }
                    }

#if !CODE_STYLE
                    var options = solution.Options;
                    foreach (var(key, value) in remainingOptions)
                    {
                        options = options.WithChangedOption(key, value);
                    }

                    solution = solution.WithOptions(options);
#endif

                    return(solution);
                });
            }
Ejemplo n.º 3
0
        internal void Apply()
        {
            var(analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(_defaultFileExt, EditorConfig, Options);
            if (analyzerConfigSource is not null)
            {
                if (_analyzerConfigIndex is null)
                {
                    _analyzerConfigIndex = _test.TestState.AnalyzerConfigFiles.Count;
                    _test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", analyzerConfigSource));
                }
                else
                {
                    _test.TestState.AnalyzerConfigFiles[_analyzerConfigIndex.Value] = ("/.editorconfig", analyzerConfigSource);
                }
            }
            else if (_analyzerConfigIndex is { } index)
            {
                _analyzerConfigIndex = null;
                _test.TestState.AnalyzerConfigFiles.RemoveAt(index);
            }

            var solutionTransformIndex = _remainingOptionsSolutionTransform is not null?_test.SolutionTransforms.IndexOf(_remainingOptionsSolutionTransform) : -1;

            if (remainingOptions is not null)
            {
                // Generate a new solution transform
                _remainingOptionsSolutionTransform = (solution, projectId) =>
                {
#if !CODE_STYLE
                    var options = solution.Options;
                    foreach (var(key, value) in remainingOptions)
                    {
                        options = options.WithChangedOption(key, value);
                    }

                    solution = solution.WithOptions(options);
#endif

                    return(solution);
                };

                if (solutionTransformIndex < 0)
                {
                    _test.SolutionTransforms.Add(_remainingOptionsSolutionTransform);
                }
                else
                {
                    _test.SolutionTransforms[solutionTransformIndex] = _remainingOptionsSolutionTransform;
                }
            }
            else if (_remainingOptionsSolutionTransform is not null)
            {
                _test.SolutionTransforms.Remove(_remainingOptionsSolutionTransform);
                _remainingOptionsSolutionTransform = null;
            }
        }