private static void VerifyFixAll(CodeFixRunner runner, Document[] documents, string[] newSources, FixAllScope fixAllScope, int?codeFixIndex, bool allowNewCompilerDiagnostics)
        {
            var solution    = documents.First().Project.Solution;
            var newSolution = runner.ApplyFixAll(solution, fixAllScope, allowNewCompilerDiagnostics, codeFixIndex ?? 0);

            VerifyDocuments(newSolution, documents, newSources);
        }
        private void VerifyFix(
            string language,
            DiagnosticAnalyzer analyzerOpt,
            CodeFixProvider codeFixProvider,
            string[] oldSources,
            string[] newSources,
            int?codeFixIndex,
            bool allowNewCompilerDiagnostics,
            bool onlyFixFirstFixableDiagnostic,
            bool allowUnsafeCode,
            TestValidationMode validationMode,
            ReferenceFlags referenceFlags = ReferenceFlags.None)
        {
            var runner = new CodeFixRunner(analyzerOpt, codeFixProvider, validationMode);

            Assert.True(oldSources.Length == newSources.Length, "Length of expected and actual sources arrays must match.");
            Document[] documents = CreateDocuments(oldSources, language, referenceFlags, allowUnsafeCode: allowUnsafeCode);

            var      project = documents.First().Project;
            Solution newSolution;

            if (onlyFixFirstFixableDiagnostic)
            {
                newSolution = runner.ApplySingleFix(project, ImmutableArray <TestAdditionalDocument> .Empty, codeFixIndex ?? 0);
            }
            else
            {
                newSolution = runner.ApplyFixesOneByOne(project.Solution, ImmutableArray <TestAdditionalDocument> .Empty, allowNewCompilerDiagnostics, codeFixIndex ?? 0);
            }

            VerifyDocuments(newSolution, documents, newSources);
        }
        private void VerifyFixAll(
            string language,
            DiagnosticAnalyzer analyzerOpt,
            CodeFixProvider codeFixProvider,
            string[] oldSources,
            string[] newSources,
            FixAllScope fixAllScope,
            int?codeFixIndex,
            bool allowNewCompilerDiagnostics,
            bool allowUnsafeCode,
            TestValidationMode validationMode)
        {
            var runner = new CodeFixRunner(analyzerOpt, codeFixProvider, validationMode);

            Assert.True(oldSources.Length == newSources.Length, "Length of expected and actual sources arrays must match.");
            Document[] documents = CreateDocuments(oldSources, language, allowUnsafeCode: allowUnsafeCode);
            VerifyFixAll(runner, documents, newSources, fixAllScope, codeFixIndex, allowNewCompilerDiagnostics);
        }
        private void VerifyFixAll(
            string language,
            DiagnosticAnalyzer analyzerOpt,
            CodeFixProvider codeFixProvider,
            string[] oldSources,
            string[] newSources,
            bool allowNewCompilerDiagnostics,
            bool allowUnsafeCode,
            TestValidationMode validationMode)
        {
            var runner = new CodeFixRunner(analyzerOpt, codeFixProvider, validationMode);

            Assert.True(oldSources.Length == newSources.Length, "Length of expected and actual sources arrays must match.");
            Document[] documents = CreateDocuments(oldSources, language, allowUnsafeCode: allowUnsafeCode);
            var        solution  = documents.First().Project.Solution;

            solution = runner.ApplyFixAll(solution, ImmutableArray <TestAdditionalDocument> .Empty, allowNewCompilerDiagnostics);
            VerifyDocuments(solution, documents, newSources);
        }
        protected void VerifyAdditionalFileFix(
            string language,
            DiagnosticAnalyzer analyzerOpt,
            CodeFixProvider codeFixProvider,
            string source,
            IEnumerable <TestAdditionalDocument> additionalFiles,
            TestAdditionalDocument newAdditionalFileToVerify,
            int?codeFixIndex = null,
            bool allowNewCompilerDiagnostics   = false,
            bool onlyFixFirstFixableDiagnostic = false,
            TestValidationMode validationMode  = DefaultTestValidationMode)
        {
            Document document = CreateDocument(source, language);

            if (additionalFiles != null)
            {
                var project = document.Project;
                foreach (var additionalFile in additionalFiles)
                {
                    project = project.AddAdditionalDocument(additionalFile.Name, additionalFile.GetText(), filePath: additionalFile.Path).Project;
                }

                document = project.GetDocument(document.Id);
            }

            var additionalFileName = newAdditionalFileToVerify.Name;
            var additionalFileText = newAdditionalFileToVerify.GetText().ToString();

            Solution newSolution;
            var      runner = new CodeFixRunner(analyzerOpt, codeFixProvider, DefaultTestValidationMode);

            if (onlyFixFirstFixableDiagnostic || codeFixIndex.HasValue)
            {
                newSolution = runner.ApplySingleFix(document.Project, additionalFiles, codeFixIndex.HasValue ? codeFixIndex.Value : 0, fixableDiagnosticIndex: 0);
            }
            else
            {
                newSolution = runner.ApplyFixesOneByOne(document.Project.Solution, additionalFiles, allowNewCompilerDiagnostics);
            }

            Assert.Equal(additionalFileText, GetActualTextForNewDocument(newSolution.GetDocument(document.Id), newAdditionalFileToVerify.Name).ToString());
        }