Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Automatically wait for completion in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Oct 11, 2019
1 parent 69cdbf1 commit 2a1c5c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 13 additions & 2 deletions Tests/EditorTestHelpers/CommandServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding;
Expand Down Expand Up @@ -36,11 +38,20 @@ public static void CheckAndExecute<T> (
this IEditorCommandHandlerService commandService,
Func<ITextView, ITextBuffer, T> argsFactory) where T : EditorCommandArgs
{
ITextView textView = null;
Func<ITextView, ITextBuffer, T> capturingArgsFactory = (v, b) => { textView = v; return argsFactory (v, b); };
if (commandService.GetCommandState (argsFactory, Unspecified).IsAvailable) {
commandService.Execute (argsFactory, Noop);
commandService.Execute (capturingArgsFactory, Noop);
} else {
throw new InvalidOperationException ($"No handler available for `{typeof (T)}`");
}

//ensure the computation is completed before we continue typing
if (textView != null) {
if (textView.Properties.TryGetProperty (typeof (IAsyncCompletionSession), out IAsyncCompletionSession session)) {
session.GetComputedItems (CancellationToken.None);
}
}
}

static Action Noop { get; } = new Action (() => { });
Expand Down
5 changes: 0 additions & 5 deletions Tests/EditorTestHelpers/EditorTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public async Task TestCommands (

foreach (var c in commands) {
c (commandService);

//ensure the computation is completed before we continue typing
if (textView.Properties.TryGetProperty (typeof (IAsyncCompletionSession), out IAsyncCompletionSession session)) {
session.GetComputedItems (CancellationToken.None);
}
}

Assert.AreEqual (afterDocumentText, textView.TextBuffer.CurrentSnapshot.GetText ());
Expand Down

0 comments on commit 2a1c5c7

Please sign in to comment.