Skip to content

Commit 4965677

Browse files
committed
Use WpfFact for integration tests
See dotnet/roslyn#25467
1 parent d9753b1 commit 4965677

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/AbstractIntegrationTest.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@
44
namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
55
{
66
using System;
7+
using System.Threading;
8+
using System.Threading.Tasks;
79
using System.Windows.Automation;
810
using Xunit;
911

1012
[CaptureTestName]
1113
[Collection(nameof(SharedIntegrationHostFixture))]
12-
public abstract class AbstractIntegrationTest : IDisposable
14+
public abstract class AbstractIntegrationTest : IAsyncLifetime, IDisposable
1315
{
16+
private readonly VisualStudioInstanceFactory _instanceFactory;
17+
private readonly Version _version;
1418
private VisualStudioInstanceContext _visualStudioContext;
1519

1620
protected AbstractIntegrationTest(VisualStudioInstanceFactory instanceFactory, Version version)
1721
{
22+
Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
23+
_instanceFactory = instanceFactory;
24+
_version = version;
1825
Automation.TransactionTimeout = 20000;
19-
_visualStudioContext = instanceFactory.GetNewOrUsedInstance(version, SharedIntegrationHostFixture.RequiredPackageIds);
20-
VisualStudio = _visualStudioContext.Instance;
2126
}
2227

23-
public VisualStudioInstance VisualStudio
28+
public VisualStudioInstance VisualStudio => _visualStudioContext?.Instance;
29+
30+
public virtual async Task InitializeAsync()
31+
{
32+
_visualStudioContext = await _instanceFactory.GetNewOrUsedInstanceAsync(_version, SharedIntegrationHostFixture.RequiredPackageIds).ConfigureAwait(false);
33+
}
34+
35+
public Task DisposeAsync()
2436
{
25-
get;
37+
return Task.FromResult<object>(null);
2638
}
2739

2840
public void Dispose()

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/IntegrationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static void SetForegroundWindow(IntPtr window, bool skipAttachingThread =
233233
try
234234
{
235235
// No need to re-attach threads in case when VS initializaed an UI thread for a debugged application.
236-
if (!skipAttachingThread)
236+
if (!skipAttachingThread && activeThreadId != currentThreadId)
237237
{
238238
// Attach the thread inputs so that 'SetActiveWindow' and 'SetFocus' work
239239
threadInputsAttached = AttachThreadInput(currentThreadId, activeThreadId);

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/TrivialIntegrationTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
88
using System.Windows;
99
using System.Windows.Media;
1010
using Microsoft.VisualStudio.Text.Formatting;
11+
using Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Threading;
1112
using WindowsInput;
1213
using WindowsInput.Native;
1314
using Xunit;
@@ -20,7 +21,7 @@ protected TrivialIntegrationTest(VisualStudioInstanceFactory instanceFactory, Ve
2021
{
2122
}
2223

23-
[Fact]
24+
[WpfFact]
2425
public void TestOpenAndCloseIDE()
2526
{
2627
var currentVersion = VisualStudioInstance.RetryRpcCall(() => VisualStudio.Dte.Version);
@@ -34,7 +35,7 @@ public void TestOpenAndCloseIDE()
3435
Assert.Equal(expectedVersion.ToString(), currentVersion);
3536
}
3637

37-
[Fact]
38+
[WpfFact]
3839
public void BasicScrollingBehavior()
3940
{
4041
var window = VisualStudioInstance.RetryRpcCall(() => VisualStudio.Dte.ItemOperations.NewFile(Name: Guid.NewGuid() + ".txt"));
@@ -129,7 +130,7 @@ public void BasicScrollingBehavior()
129130
/// <summary>
130131
/// Verifies that the Ctrl+Scroll operations do not change the zoom level in the editor.
131132
/// </summary>
132-
[Fact]
133+
[WpfFact]
133134
public void ZoomDisabled()
134135
{
135136
var window = VisualStudioInstance.RetryRpcCall(() => VisualStudio.Dte.ItemOperations.NewFile(Name: Guid.NewGuid() + ".txt"));

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/VisualStudioInstanceFactory.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
99
using System.Diagnostics;
1010
using System.Linq;
1111
using System.Reflection;
12+
using System.Threading.Tasks;
1213
using Microsoft.VisualStudio.ExtensionManager;
1314
using Microsoft.VisualStudio.Settings;
1415
using Microsoft.VisualStudio.Setup.Configuration;
@@ -55,12 +56,12 @@ private static Assembly AssemblyResolveHandler(object sender, ResolveEventArgs e
5556
/// <summary>
5657
/// Returns a <see cref="VisualStudioInstanceContext"/>, starting a new instance of Visual Studio if necessary.
5758
/// </summary>
58-
public VisualStudioInstanceContext GetNewOrUsedInstance(Version version, ImmutableHashSet<string> requiredPackageIds)
59+
public async Task<VisualStudioInstanceContext> GetNewOrUsedInstanceAsync(Version version, ImmutableHashSet<string> requiredPackageIds)
5960
{
6061
ThrowExceptionIfAlreadyHasActiveContext();
6162

6263
bool shouldStartNewInstance = ShouldStartNewInstance(version, requiredPackageIds);
63-
UpdateCurrentlyRunningInstance(version, requiredPackageIds, shouldStartNewInstance);
64+
await UpdateCurrentlyRunningInstanceAsync(version, requiredPackageIds, shouldStartNewInstance).ConfigureAwait(false);
6465

6566
return new VisualStudioInstanceContext(_currentlyRunningInstance, this);
6667
}
@@ -102,7 +103,7 @@ private void ThrowExceptionIfAlreadyHasActiveContext()
102103
/// <summary>
103104
/// Starts up a new <see cref="VisualStudioInstance"/>, shutting down any instances that are already running.
104105
/// </summary>
105-
private void UpdateCurrentlyRunningInstance(Version version, ImmutableHashSet<string> requiredPackageIds, bool shouldStartNewInstance)
106+
private async Task UpdateCurrentlyRunningInstanceAsync(Version version, ImmutableHashSet<string> requiredPackageIds, bool shouldStartNewInstance)
106107
{
107108
Process hostProcess;
108109
DTE dte;
@@ -123,7 +124,7 @@ private void UpdateCurrentlyRunningInstance(Version version, ImmutableHashSet<st
123124
hostProcess = StartNewVisualStudioProcess(installationPath, version);
124125

125126
// We wait until the DTE instance is up before we're good
126-
dte = IntegrationHelper.WaitForNotNullAsync(() => IntegrationHelper.TryLocateDteForProcess(hostProcess)).Result;
127+
dte = await IntegrationHelper.WaitForNotNullAsync(() => IntegrationHelper.TryLocateDteForProcess(hostProcess)).ConfigureAwait(false);
127128
}
128129
else
129130
{

0 commit comments

Comments
 (0)