提交 4941c8a4 编写于 作者: C Cyrus Najmabadi

Make more tests async.

上级 916276a4
......@@ -40,7 +40,7 @@ protected override ParseOptions GetScriptOptions()
optionsService.UpdatedSignature = updatedSignature;
var codeIssueOrRefactoring = GetCodeRefactoring(workspace);
TestActions(workspace, expectedCode, index, codeIssueOrRefactoring.Actions.ToList(),
await TestActionsAsync(workspace, expectedCode, index, codeIssueOrRefactoring.Actions.ToList(),
conflictSpans: null, renameSpans: null, warningSpans: null, compareTokens: true);
}
}
......
......@@ -193,7 +193,7 @@ protected async Task<IList<CodeAction>> GetCodeActionsAsync(TestWorkspace worksp
ApplyOptionsToWorkspace(workspace, options);
var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey);
TestActions(
await TestActionsAsync(
workspace, expected, index,
actions,
conflictSpans, renameSpans, warningSpans,
......@@ -201,14 +201,14 @@ protected async Task<IList<CodeAction>> GetCodeActionsAsync(TestWorkspace worksp
}
}
protected Tuple<Solution, Solution> TestActions(
protected Task<Tuple<Solution, Solution>> TestActionsAsync(
TestWorkspace workspace, string expected,
int index, IList<CodeAction> actions,
IList<TextSpan> conflictSpans, IList<TextSpan> renameSpans, IList<TextSpan> warningSpans,
bool compareTokens)
{
var operations = VerifyInputsAndGetOperations(index, actions);
return TestOperations(workspace, expected, operations.ToList(), conflictSpans, renameSpans, warningSpans, compareTokens, expectedChangedDocumentId: null);
return TestOperationsAsync(workspace, expected, operations.ToList(), conflictSpans, renameSpans, warningSpans, compareTokens, expectedChangedDocumentId: null);
}
private static bool IsWorkspaceElement(string text)
......@@ -216,7 +216,7 @@ private static bool IsWorkspaceElement(string text)
return text.TrimStart('\r', '\n', ' ').StartsWith("<Workspace>", StringComparison.Ordinal);
}
protected Tuple<Solution, Solution> TestOperations(
protected async Task<Tuple<Solution, Solution>> TestOperationsAsync(
TestWorkspace workspace,
string expectedText,
IList<CodeActionOperation> operations,
......@@ -232,7 +232,7 @@ private static bool IsWorkspaceElement(string text)
if (IsWorkspaceElement(expectedText))
{
VerifyAgainstWorkspaceDefinition(expectedText, newSolution);
await VerifyAgainstWorkspaceDefinitionAsync(expectedText, newSolution);
return Tuple.Create(oldSolution, newSolution);
}
......@@ -277,9 +277,9 @@ private static Document GetDocumentToVerify(DocumentId expectedChangedDocumentId
return document;
}
private static void VerifyAgainstWorkspaceDefinition(string expectedText, Solution newSolution)
private static async Task VerifyAgainstWorkspaceDefinitionAsync(string expectedText, Solution newSolution)
{
using (var expectedWorkspace = TestWorkspaceFactory.CreateWorkspace(expectedText))
using (var expectedWorkspace = await TestWorkspaceFactory.CreateWorkspaceAsync(expectedText))
{
var expectedSolution = expectedWorkspace.CurrentSolution;
Assert.Equal(expectedSolution.Projects.Count(), newSolution.Projects.Count());
......
......@@ -401,7 +401,7 @@ protected async Task TestEquivalenceKeyAsync(string initialMarkup, string equiva
if (!isNewFile)
{
oldSolutionAndNewSolution = TestOperations(
oldSolutionAndNewSolution = await TestOperationsAsync(
testState.Workspace, expected, operations,
conflictSpans: null, renameSpans: null, warningSpans: null,
compareTokens: false, expectedChangedDocumentId: testState.ExistingDocument.Id);
......@@ -422,7 +422,7 @@ protected async Task TestEquivalenceKeyAsync(string initialMarkup, string equiva
if (checkIfUsingsIncluded)
{
Assert.NotNull(expectedTextWithUsings);
TestOperations(testState.Workspace, expectedTextWithUsings, operations,
await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operations,
conflictSpans: null, renameSpans: null, warningSpans: null, compareTokens: false,
expectedChangedDocumentId: testState.InvocationDocument.Id);
}
......
......@@ -95,7 +95,7 @@ protected override bool IsEndOfFileToken(SyntaxToken token)
return token.Kind() == SyntaxKind.EndOfFileToken;
}
protected override SyntaxNode AddGlobalSuppressMessageAttribute(SyntaxNode newRoot, ISymbol targetSymbol, Diagnostic diagnostic, Workspace workspace, CancellationToken cancellationToken)
protected override async Task<SyntaxNode> AddGlobalSuppressMessageAttributeAsync(SyntaxNode newRoot, ISymbol targetSymbol, Diagnostic diagnostic, Workspace workspace, CancellationToken cancellationToken)
{
var compilationRoot = (CompilationUnitSyntax)newRoot;
var isFirst = !compilationRoot.AttributeLists.Any();
......@@ -103,7 +103,7 @@ protected override SyntaxNode AddGlobalSuppressMessageAttribute(SyntaxNode newRo
SyntaxFactory.TriviaList(SyntaxFactory.Comment(GlobalSuppressionsFileHeaderComment)) :
default(SyntaxTriviaList);
var attributeList = CreateAttributeList(targetSymbol, diagnostic, leadingTrivia: leadingTriviaForAttributeList, needsLeadingEndOfLine: !isFirst);
attributeList = (AttributeListSyntax)Formatter.Format(attributeList, workspace, cancellationToken: cancellationToken);
attributeList = (AttributeListSyntax)await Formatter.FormatAsync(attributeList, workspace, cancellationToken: cancellationToken).ConfigureAwait(false);
return compilationRoot.AddAttributeLists(attributeList);
}
......
......@@ -26,7 +26,7 @@ protected override async Task<Document> GetChangedSuppressionDocumentAsync(Cance
var workspace = suppressionsDoc.Project.Solution.Workspace;
var suppressionsRoot = await suppressionsDoc.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var semanticModel = await suppressionsDoc.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
suppressionsRoot = Fixer.AddGlobalSuppressMessageAttribute(suppressionsRoot, _targetSymbol, _diagnostic, workspace, cancellationToken);
suppressionsRoot = await Fixer.AddGlobalSuppressMessageAttributeAsync(suppressionsRoot, _targetSymbol, _diagnostic, workspace, cancellationToken).ConfigureAwait(false);
return suppressionsDoc.WithSyntaxRoot(suppressionsRoot);
}
......
......@@ -106,7 +106,7 @@ protected override async Task<Document> GetChangedSuppressionDocumentAsync(Cance
foreach (var diagnostic in diagnostics)
{
Contract.ThrowIfFalse(!diagnostic.IsSuppressed);
suppressionsRoot = Fixer.AddGlobalSuppressMessageAttribute(suppressionsRoot, targetSymbol, diagnostic, workspace, cancellationToken);
suppressionsRoot = await Fixer.AddGlobalSuppressMessageAttributeAsync(suppressionsRoot, targetSymbol, diagnostic, workspace, cancellationToken).ConfigureAwait(false);
}
}
......
......@@ -42,7 +42,7 @@ public bool CanBeSuppressedOrUnsuppressed(Diagnostic diagnostic)
protected abstract Task<SyntaxTriviaList> CreatePragmaDisableDirectiveTriviaAsync(Diagnostic diagnostic, Func<SyntaxNode, Task<SyntaxNode>> formatNode, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine);
protected abstract Task<SyntaxTriviaList> CreatePragmaRestoreDirectiveTriviaAsync(Diagnostic diagnostic, Func<SyntaxNode, Task<SyntaxNode>> formatNode, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine);
protected abstract SyntaxNode AddGlobalSuppressMessageAttribute(SyntaxNode newRoot, ISymbol targetSymbol, Diagnostic diagnostic, Workspace workspace, CancellationToken cancellationToken);
protected abstract Task<SyntaxNode> AddGlobalSuppressMessageAttributeAsync(SyntaxNode newRoot, ISymbol targetSymbol, Diagnostic diagnostic, Workspace workspace, CancellationToken cancellationToken);
protected abstract string DefaultFileExtension { get; }
protected abstract string SingleLineCommentStart { get; }
......
......@@ -119,7 +119,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Suppression
Return token.Kind = SyntaxKind.EndOfFileToken
End Function
Protected Overrides Function AddGlobalSuppressMessageAttribute(newRoot As SyntaxNode, targetSymbol As ISymbol, diagnostic As Diagnostic, workspace As Workspace, cancellationToken As CancellationToken) As SyntaxNode
Protected Overrides Async Function AddGlobalSuppressMessageAttributeAsync(newRoot As SyntaxNode, targetSymbol As ISymbol, diagnostic As Diagnostic, workspace As Workspace, cancellationToken As CancellationToken) As Task(Of SyntaxNode)
Dim compilationRoot = DirectCast(newRoot, CompilationUnitSyntax)
Dim isFirst = Not compilationRoot.Attributes.Any()
Dim attributeList = CreateAttributeList(targetSymbol, diagnostic)
......@@ -130,7 +130,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Suppression
attributeStatement = attributeStatement.WithLeadingTrivia(attributeStatement.GetLeadingTrivia.Add(SyntaxFactory.ElasticCarriageReturnLineFeed))
End If
attributeStatement = CType(Formatter.Format(attributeStatement, workspace, cancellationToken:=cancellationToken), AttributesStatementSyntax)
attributeStatement = CType(Await Formatter.FormatAsync(attributeStatement, workspace, cancellationToken:=cancellationToken).ConfigureAwait(False), AttributesStatementSyntax)
Dim leadingTrivia = If(isFirst AndAlso Not compilationRoot.HasLeadingTrivia,
SyntaxFactory.TriviaList(SyntaxFactory.CommentTrivia(GlobalSuppressionsFileHeaderComment)),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册