提交 52b465d7 编写于 作者: C Cyrus Najmabadi

Remove blocking calls from tests.

上级 6ff4eecc
......@@ -21,7 +21,7 @@ protected async Task ExpectExtractMethodToFailAsync(string codeWithMarker, bool
{
var testDocument = workspace.Documents.First();
var textSpan = testDocument.SelectedSpans.Single();
var treeAfterExtractMethod = ExtractMethod(workspace, testDocument, succeed: false, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
var treeAfterExtractMethod = await ExtractMethodAsync(workspace, testDocument, succeed: false, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
}
}
......@@ -37,7 +37,7 @@ protected async Task ExpectExtractMethodToFailAsync(string codeWithMarker, bool
var testDocument = workspace.Documents.Single();
var subjectBuffer = testDocument.TextBuffer;
var tree = ExtractMethod(workspace, testDocument, succeed: false, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
var tree = await ExtractMethodAsync(workspace, testDocument, succeed: false, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
using (var edit = subjectBuffer.CreateEdit())
{
......@@ -53,10 +53,10 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
{
using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromLinesAsync(codeWithMarker))
{
Assert.NotNull(Record.Exception(() =>
Assert.NotNull(await Record.ExceptionAsync(async () =>
{
var testDocument = workspace.Documents.Single();
var tree = ExtractMethod(workspace, testDocument);
var tree = await ExtractMethodAsync(workspace, testDocument);
}));
}
}
......@@ -74,7 +74,7 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
var testDocument = workspace.Documents.Single();
var subjectBuffer = testDocument.TextBuffer;
var tree = ExtractMethod(workspace, testDocument, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
var tree = await ExtractMethodAsync(workspace, testDocument, allowMovingDeclaration: allowMovingDeclaration, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct);
using (var edit = subjectBuffer.CreateEdit())
{
......@@ -93,7 +93,7 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
}
}
protected static SyntaxNode ExtractMethod(
protected static async Task<SyntaxNode> ExtractMethodAsync(
TestWorkspace workspace,
TestHostDocument testDocument,
bool succeed = true,
......@@ -107,7 +107,7 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, allowMovingDeclaration)
.WithChangedOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language, dontPutOutOrRefOnStruct);
var semanticDocument = SemanticDocument.CreateAsync(document, CancellationToken.None).Result;
var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None);
var validator = new CSharpSelectionValidator(semanticDocument, testDocument.SelectedSpans.Single(), options);
var selectedCode = validator.GetValidSelectionAsync(CancellationToken.None).Result;
......@@ -120,11 +120,11 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
// extract method
var extractor = new CSharpMethodExtractor((CSharpSelectionResult)selectedCode);
var result = extractor.ExtractMethodAsync(CancellationToken.None).Result;
var result = await extractor.ExtractMethodAsync(CancellationToken.None);
Assert.NotNull(result);
Assert.Equal(succeed, result.Succeeded || result.SucceededWithSuggestion);
return result.Document.GetSyntaxRootAsync().Result;
return await result.Document.GetSyntaxRootAsync();
}
protected async Task TestSelectionAsync(string codeWithMarker, bool expectedFail = false, CSharpParseOptions parseOptions = null)
......@@ -140,9 +140,9 @@ protected async Task TestSelectionAsync(string codeWithMarker, bool expectedFail
var options = document.Project.Solution.Workspace.Options
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, true);
var semanticDocument = SemanticDocument.CreateAsync(document, CancellationToken.None).Result;
var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None);
var validator = new CSharpSelectionValidator(semanticDocument, namedSpans["b"].Single(), options);
var result = validator.GetValidSelectionAsync(CancellationToken.None).Result;
var result = await validator.GetValidSelectionAsync(CancellationToken.None);
Assert.True(expectedFail ? result.Status.Failed() : result.Status.Succeeded());
......@@ -160,8 +160,8 @@ protected async Task IterateAllAsync(string code)
var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);
Assert.NotNull(document);
var semanticDocument = SemanticDocument.CreateAsync(document, CancellationToken.None).Result;
var tree = document.GetSyntaxTreeAsync().Result;
var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None);
var tree = await document.GetSyntaxTreeAsync();
var iterator = tree.GetRoot().DescendantNodesAndSelf().Cast<SyntaxNode>();
var options = document.Project.Solution.Workspace.Options
......@@ -172,7 +172,7 @@ protected async Task IterateAllAsync(string code)
try
{
var validator = new CSharpSelectionValidator(semanticDocument, node.Span, options);
var result = validator.GetValidSelectionAsync(CancellationToken.None).Result;
var result = await validator.GetValidSelectionAsync(CancellationToken.None);
// check the obvious case
if (!(node is ExpressionSyntax) && !node.UnderValidContext())
......
......@@ -47,7 +47,7 @@ protected async Task AssertFormatAsync(string expected, string code, bool debugM
buffer.CurrentSnapshot.GetText());
var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);
var syntaxTree = document.GetSyntaxTreeAsync().Result;
var syntaxTree = await document.GetSyntaxTreeAsync();
var formattingRuleProvider = workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>();
......@@ -119,7 +119,7 @@ protected async Task AssertFormatAsync(string expected, string code, IEnumerable
var buffer = hostdoc.GetTextBuffer();
var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);
var syntaxTree = document.GetSyntaxTreeAsync().Result;
var syntaxTree = await document.GetSyntaxTreeAsync();
// create new buffer with cloned content
var clonedBuffer = EditorFactory.CreateBuffer(
......
......@@ -355,7 +355,7 @@ public void M()
var spans = subjectDocument.SelectedSpans;
var document = workspace.CurrentSolution.Projects.Single().Documents.Single();
var syntaxRoot = document.GetSyntaxRootAsync().Result;
var syntaxRoot = await document.GetSyntaxRootAsync();
var node = Formatter.Format(syntaxRoot, spans, workspace);
Assert.Equal(expected, node.ToFullString());
......@@ -451,7 +451,7 @@ public void M()
workspace.Options = workspace.Options.WithChangedOption(FormattingOptions.AllowDisjointSpanMerging, true);
var document = workspace.CurrentSolution.Projects.Single().Documents.Single();
var syntaxRoot = document.GetSyntaxRootAsync().Result;
var syntaxRoot = await document.GetSyntaxRootAsync();
var node = Formatter.Format(syntaxRoot, spans, workspace);
Assert.Equal(expected, node.ToFullString());
......
......@@ -60,7 +60,7 @@ public class FormatterTestsBase
private static async Task TokenFormatWorkerAsync(TestWorkspace workspace, ITextBuffer buffer, int indentationLine, char ch)
{
Document document = buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().First();
var root = (CompilationUnitSyntax)document.GetSyntaxRootAsync().Result;
var root = (CompilationUnitSyntax)await document.GetSyntaxRootAsync();
var line = root.GetText().Lines[indentationLine];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册