From b61d04d134f7d38970cdbc092175d6efc358960d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 20 Nov 2015 13:14:43 -0800 Subject: [PATCH] Make more tests async. --- .../CSharpTest/ExtractMethod/ExtractMethodBase.cs | 2 +- .../CSharpTest/Organizing/OrganizeUsingsTests.cs | 2 +- .../MetadataAsSource/InvalidIdentifierTests.cs | 2 +- .../QuickInfo/SemanticQuickInfoSourceTests.cs | 4 ++-- .../QuickInfo/SyntacticQuickInfoSourceTests.cs | 12 ++++++------ .../TypeInferrer/TypeInferrerTests.Delegate.cs | 4 ++-- .../CSharpTest/TypeInferrer/TypeInferrerTests.cs | 4 ++-- .../Test/QuickInfo/AbstractQuickInfoSourceTests.cs | 4 ++-- .../CodeGeneration/AddImportsTests.vb | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs index 7db8602d96e..2ede71b3485 100644 --- a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs +++ b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs @@ -110,7 +110,7 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker) var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None); var validator = new CSharpSelectionValidator(semanticDocument, testDocument.SelectedSpans.Single(), options); - var selectedCode = validator.GetValidSelectionAsync(CancellationToken.None).Result; + var selectedCode = await validator.GetValidSelectionAsync(CancellationToken.None); if (!succeed && selectedCode.Status.FailedWithNoBestEffortSuggestion()) { return null; diff --git a/src/EditorFeatures/CSharpTest/Organizing/OrganizeUsingsTests.cs b/src/EditorFeatures/CSharpTest/Organizing/OrganizeUsingsTests.cs index 35343e57975..bd84818b17e 100644 --- a/src/EditorFeatures/CSharpTest/Organizing/OrganizeUsingsTests.cs +++ b/src/EditorFeatures/CSharpTest/Organizing/OrganizeUsingsTests.cs @@ -17,7 +17,7 @@ protected async Task CheckAsync(string initial, string final, bool specialCaseSy using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(initial)) { var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id); - var newRoot = OrganizeImportsService.OrganizeImportsAsync(document, specialCaseSystem).Result.GetSyntaxRootAsync().Result; + var newRoot = await (await OrganizeImportsService.OrganizeImportsAsync(document, specialCaseSystem)).GetSyntaxRootAsync(); Assert.Equal(final.NormalizeLineEndings(), newRoot.ToFullString()); } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs index 353320ca7ac..7f4f234eb7f 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs @@ -21,7 +21,7 @@ private async Task TestAsync(string fileContents, params OutliningSpan[] expecte var workspace = await TestWorkspaceFactory.CreateWorkspaceFromFilesAsync(WorkspaceKind.MetadataAsSource, LanguageNames.CSharp, null, null, fileContents); var outliningService = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService(); var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); - var actualOutliningSpans = outliningService.GetOutliningSpansAsync(document, CancellationToken.None).Result.Where(s => s != null).ToArray(); + var actualOutliningSpans = (await outliningService.GetOutliningSpansAsync(document, CancellationToken.None)).Where(s => s != null).ToArray(); Assert.Equal(expectedSpans.Length, actualOutliningSpans.Length); for (int i = 0; i < expectedSpans.Length; i++) diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs index d481d7e43a7..b4b0a84ee49 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs @@ -114,7 +114,7 @@ private async Task VerifyWithMscorlib45Async(string markup, Action[] exp workspace.GetService(), workspace.GetService()); - var state = provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None).Result; + var state = await provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None); if (state != null) { WaitForDocumentationComment(state.Content); @@ -271,7 +271,7 @@ private async Task VerifyWithReferenceWorkerAsync(string xmlString, params Actio workspace.GetService(), workspace.GetService()); - var state = provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None).Result; + var state = await provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None); if (state != null) { WaitForDocumentationComment(state.Content); diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs index c01ce60cd9f..46708f36ab8 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs @@ -286,16 +286,16 @@ private IQuickInfoProvider CreateProvider(TestWorkspace workspace) workspace.GetService()); } - protected override void AssertNoContent( + protected override async Task AssertNoContentAsync( TestWorkspace workspace, Document document, int position) { var provider = CreateProvider(workspace); - Assert.Null(provider.GetItemAsync(document, position, CancellationToken.None).Result); + Assert.Null(await provider.GetItemAsync(document, position, CancellationToken.None)); } - protected override void AssertContentIs( + protected override async Task AssertContentIsAsync( TestWorkspace workspace, Document document, int position, @@ -303,7 +303,7 @@ private IQuickInfoProvider CreateProvider(TestWorkspace workspace) string expectedDocumentationComment = null) { var provider = CreateProvider(workspace); - var state = provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None).Result; + var state = await provider.GetItemAsync(document, position, cancellationToken: CancellationToken.None); Assert.NotNull(state); var viewHostingControl = (ViewHostingControl)((ElisionBufferDeferredContent)state.Content).Create(); @@ -347,11 +347,11 @@ protected override Task TestInScriptAsync(string code, string expectedContent, s if (string.IsNullOrEmpty(expectedContent)) { - AssertNoContent(workspace, document, position); + await AssertNoContentAsync(workspace, document, position); } else { - AssertContentIs(workspace, document, position, expectedContent, expectedDocumentationComment); + await AssertContentIsAsync(workspace, document, position, expectedContent, expectedDocumentationComment); } } } diff --git a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs index be79075785f..ca993eb95a3 100644 --- a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs +++ b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs @@ -19,11 +19,11 @@ private async Task TestDelegateAsync(string text, string expectedType) Document document = await fixture.UpdateDocumentAsync(text, SourceCodeKind.Regular); - var root = document.GetSyntaxTreeAsync().Result.GetRoot(); + var root = (await document.GetSyntaxTreeAsync()).GetRoot(); var node = FindExpressionSyntaxFromSpan(root, textSpan); var typeInference = document.GetLanguageService(); - var delegateType = typeInference.InferDelegateType(document.GetSemanticModelAsync().Result, node, CancellationToken.None); + var delegateType = typeInference.InferDelegateType(await document.GetSemanticModelAsync(), node, CancellationToken.None); Assert.NotNull(delegateType); Assert.Equal(expectedType, delegateType.ToNameDisplayString()); diff --git a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs index b6e49ce3a6a..b9e717a2c8b 100644 --- a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs +++ b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs @@ -27,8 +27,8 @@ protected override async Task TestWorkerAsync(Document document, TextSpan textSp var typeInference = document.GetLanguageService(); var inferredType = useNodeStartPosition - ? typeInference.InferType(document.GetSemanticModelForSpanAsync(new TextSpan(node?.SpanStart ?? textSpan.Start, 0), CancellationToken.None).Result, node?.SpanStart ?? textSpan.Start, objectAsDefault: true, cancellationToken: CancellationToken.None) - : typeInference.InferType(document.GetSemanticModelForSpanAsync(node?.Span ?? textSpan, CancellationToken.None).Result, node, objectAsDefault: true, cancellationToken: CancellationToken.None); + ? typeInference.InferType(await document.GetSemanticModelForSpanAsync(new TextSpan(node?.SpanStart ?? textSpan.Start, 0), CancellationToken.None), node?.SpanStart ?? textSpan.Start, objectAsDefault: true, cancellationToken: CancellationToken.None) + : typeInference.InferType(await document.GetSemanticModelForSpanAsync(node?.Span ?? textSpan, CancellationToken.None), node, objectAsDefault: true, cancellationToken: CancellationToken.None); var typeSyntax = inferredType.GenerateTypeSyntax(); Assert.Equal(expectedType, typeSyntax.ToString()); } diff --git a/src/EditorFeatures/Test/QuickInfo/AbstractQuickInfoSourceTests.cs b/src/EditorFeatures/Test/QuickInfo/AbstractQuickInfoSourceTests.cs index ca2978a8cbc..0bd4aceadf6 100644 --- a/src/EditorFeatures/Test/QuickInfo/AbstractQuickInfoSourceTests.cs +++ b/src/EditorFeatures/Test/QuickInfo/AbstractQuickInfoSourceTests.cs @@ -44,12 +44,12 @@ protected async Task TestInMethodAndScriptAsync(string code, string expectedCont string expectedDocumentationComment = null, CSharpParseOptions parseOptions = null); - protected abstract void AssertNoContent( + protected abstract Task AssertNoContentAsync( TestWorkspace workspace, Document document, int position); - protected abstract void AssertContentIs( + protected abstract Task AssertContentIsAsync( TestWorkspace workspace, Document document, int position, diff --git a/src/Workspaces/VisualBasicTest/CodeGeneration/AddImportsTests.vb b/src/Workspaces/VisualBasicTest/CodeGeneration/AddImportsTests.vb index 2e64a7bca2e..143eca3a150 100644 --- a/src/Workspaces/VisualBasicTest/CodeGeneration/AddImportsTests.vb +++ b/src/Workspaces/VisualBasicTest/CodeGeneration/AddImportsTests.vb @@ -38,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Editting Dim doc = GetDocument(initialText, globalImports) options = If(options, doc.Project.Solution.Workspace.Options) - Dim imported = ImportAdder.AddImportsAsync(doc, options).Result + Dim imported = Await ImportAdder.AddImportsAsync(doc, options) If importsAddedText IsNot Nothing Then Dim formatted = Await Formatter.FormatAsync(imported, SyntaxAnnotation.ElasticAnnotation, options) -- GitLab