From 52b465d7c8a1be030b8abbf8db43e47a313ed945 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 20 Nov 2015 12:46:32 -0800 Subject: [PATCH] Remove blocking calls from tests. --- .../ExtractMethod/ExtractMethodBase.cs | 28 +++++++++---------- .../Formatting/FormattingEngineTestBase.cs | 4 +-- .../Formatting/FormattingEngineTests.cs | 4 +-- .../Indentation/FormatterTestsBase.cs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs index f0f984930a8..7db8602d96e 100644 --- a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs +++ b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs @@ -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 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(); 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()) diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTestBase.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTestBase.cs index d3373820aa1..a883f6d9e7a 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTestBase.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTestBase.cs @@ -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(); @@ -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( diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index fe8ff53d00c..5d426740bda 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -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()); diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs index 0b9b2baa526..1a980c05a7e 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs @@ -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]; -- GitLab