private static async Task <string> FixAllInSingleDocumentWorkspaceAsync(string documentText) { using var workspace = TestUtils.CreateSingleDocumentWorkspace(documentText, out var document); var comparer = new SolutionDiagnosticsComparer(document.Project.Solution); var fixedDocument = await SuppressionFixer.FixAllInDocumentAsync(document, comparer, afterRemoval : _ => { }, CancellationToken.None); var fixedText = await fixedDocument.GetTextAsync(); return(fixedText.ToString()); }
private static string RemoveSingleSuppression(string compilationUnit, string syntaxToRemove) { var syntaxRoot = SyntaxFactory.ParseCompilationUnit(compilationUnit); var suppression = SuppressionFixer.FindSuppressions(syntaxRoot) .ShouldHaveSingleItem($"Expected exactly one suppression in the compilation unit."); var removals = SuppressionFixer.GetPotentialRemovals(syntaxRoot, suppression).ToList(); var matchingRemovals = removals.Where(r => r.RemovedText == syntaxToRemove).ToList(); if (matchingRemovals.Count != 1) { Assert.Fail( $"Expected exactly one removal in the compilation unit with the removed text '{syntaxToRemove}', but options were:" + Environment.NewLine + string.Join(Environment.NewLine, removals.Select(r => r.RemovedText))); } return(matchingRemovals.Single().NewRoot.ToFullString()); }