Skip to content

Commit 495d38e

Browse files
committed
Simplify integration test helpers
1 parent f8c4369 commit 495d38e

File tree

6 files changed

+45
-98
lines changed

6 files changed

+45
-98
lines changed

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/InProcess/IdeSendKeys.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Harness
66
using System;
77
using System.Runtime.InteropServices;
88
using System.Threading.Tasks;
9+
using Microsoft.VisualStudio.Threading;
910
using Tvl.VisualStudio.MouseFastScroll.IntegrationTests.InProcess;
1011
using WindowsInput;
1112
using WindowsInput.Native;
1213

1314
public class IdeSendKeys
1415
{
15-
private readonly VisualStudio_InProc _visualStudio;
16+
private readonly VisualStudio_InProc2 _visualStudio;
1617

17-
public IdeSendKeys()
18+
public IdeSendKeys(JoinableTaskFactory joinableTaskFactory)
1819
{
19-
_visualStudio = VisualStudio_InProc.Create();
20+
_visualStudio = new VisualStudio_InProc2(joinableTaskFactory);
2021
}
2122

2223
internal async Task SendAsync(params object[] keys)
@@ -82,7 +83,7 @@ internal async Task SendAsync(Action<InputSimulator> actions)
8283
try
8384
{
8485
var foreground = GetForegroundWindow();
85-
await Task.Run(() => _visualStudio.ActivateMainWindow());
86+
await _visualStudio.ActivateMainWindowAsync();
8687

8788
await Task.Run(() => actions(new InputSimulator()));
8889
}
@@ -94,7 +95,7 @@ internal async Task SendAsync(Action<InputSimulator> actions)
9495
}
9596
}
9697

97-
await Task.Run(() => _visualStudio.WaitForApplicationIdle());
98+
await InProcComponent2.WaitForApplicationIdleAsync();
9899
}
99100

100101
private static bool AttachThreadInput(uint idAttach, uint idAttachTo)

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/InProcess/InProcComponent.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/InProcess/InProcComponent2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected async Task<DTE> GetDTEAsync()
4040
/// <summary>
4141
/// Waiting for the application to 'idle' means that it is done pumping messages (including WM_PAINT).
4242
/// </summary>
43-
protected static async Task WaitForApplicationIdleAsync()
43+
protected internal static async Task WaitForApplicationIdleAsync()
4444
{
4545
await Application.Current.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
4646
}

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/InProcess/VisualStudio_InProc.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE.txt in the project root for license information.
3+
4+
namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests.InProcess
5+
{
6+
using System;
7+
using System.Diagnostics;
8+
using System.Threading.Tasks;
9+
using Microsoft.VisualStudio.Threading;
10+
using Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Harness;
11+
12+
internal partial class VisualStudio_InProc2 : InProcComponent2
13+
{
14+
public VisualStudio_InProc2(JoinableTaskFactory joinableTaskFactory)
15+
: base(joinableTaskFactory)
16+
{
17+
}
18+
19+
public async Task ActivateMainWindowAsync()
20+
{
21+
await JoinableTaskFactory.SwitchToMainThreadAsync();
22+
23+
var dte = await GetDTEAsync();
24+
25+
var activeVisualStudioWindow = (IntPtr)dte.ActiveWindow.HWnd;
26+
Debug.WriteLine($"DTE.ActiveWindow.HWnd = {activeVisualStudioWindow}");
27+
28+
if (activeVisualStudioWindow == IntPtr.Zero)
29+
{
30+
activeVisualStudioWindow = (IntPtr)dte.MainWindow.HWnd;
31+
Debug.WriteLine($"DTE.MainWindow.HWnd = {activeVisualStudioWindow}");
32+
}
33+
34+
IntegrationHelper.SetForegroundWindow(activeVisualStudioWindow);
35+
}
36+
}
37+
}

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/ScrollingIntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ScrollingIntegrationTest(ITestOutputHelper testOutputHelper)
2424
{
2525
TestOutputHelper = testOutputHelper;
2626
Editor = new Editor_InProc2(JoinableTaskFactory);
27-
SendKeys = new IdeSendKeys();
27+
SendKeys = new IdeSendKeys(JoinableTaskFactory);
2828
}
2929

3030
protected ITestOutputHelper TestOutputHelper

0 commit comments

Comments
 (0)