Skip to content

Commit e81b50e

Browse files
committed
Update tests to use the correct JoinableTaskContext in Visual Studio 2013
1 parent 03a4a4a commit e81b50e

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/AbstractIdeIntegrationTest.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
55
{
66
using System;
7-
using System.Linq;
87
using System.Threading.Tasks;
98
using System.Windows;
10-
using Microsoft.VisualStudio.ComponentModelHost;
9+
using Microsoft.VisualStudio.Shell.Interop;
1110
using Microsoft.VisualStudio.Threading;
1211
using Xunit;
13-
using ServiceProvider = Microsoft.VisualStudio.Shell.ServiceProvider;
1412

1513
[VsTestSettings(UIThread = true)]
1614
public abstract class AbstractIdeIntegrationTest : IAsyncLifetime, IDisposable
@@ -23,10 +21,18 @@ protected AbstractIdeIntegrationTest()
2321
{
2422
Assert.True(Application.Current.Dispatcher.CheckAccess());
2523

26-
var componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));
27-
JoinableTaskContext = componentModel.GetExtensions<JoinableTaskContext>().SingleOrDefault() ?? new JoinableTaskContext();
24+
if (ServiceProvider.GetService(typeof(SVsTaskSchedulerService)) is IVsTaskSchedulerService2 taskSchedulerService)
25+
{
26+
JoinableTaskContext = (JoinableTaskContext)taskSchedulerService.GetAsyncTaskContext();
27+
}
28+
else
29+
{
30+
JoinableTaskContext = new JoinableTaskContext();
31+
}
2832
}
2933

34+
protected static IServiceProvider ServiceProvider => Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
35+
3036
protected JoinableTaskContext JoinableTaskContext
3137
{
3238
get

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/ScrollingIntegrationTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
1616
using Xunit.Abstractions;
1717
using _DTE = EnvDTE._DTE;
1818
using DTE = EnvDTE.DTE;
19-
using ServiceProvider = Microsoft.VisualStudio.Shell.ServiceProvider;
2019
using vsSaveChanges = EnvDTE.vsSaveChanges;
2120

2221
public class ScrollingIntegrationTest : AbstractIdeIntegrationTest
@@ -46,7 +45,7 @@ private IdeSendKeys SendKeys
4645
[VsFact]
4746
public async Task BasicScrollingBehaviorAsync()
4847
{
49-
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(_DTE));
48+
var dte = (DTE)ServiceProvider.GetService(typeof(_DTE));
5049
var window = dte.ItemOperations.NewFile(Name: Guid.NewGuid() + ".txt");
5150

5251
string initialText = string.Join(string.Empty, Enumerable.Range(0, 400).Select(i => Guid.NewGuid() + Environment.NewLine));
@@ -145,7 +144,7 @@ await SendKeys.SendAsync(inputSimulator =>
145144
[VsFact]
146145
public async Task ZoomDisabledAsync()
147146
{
148-
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(_DTE));
147+
var dte = (DTE)ServiceProvider.GetService(typeof(_DTE));
149148
var window = dte.ItemOperations.NewFile(Name: Guid.NewGuid() + ".txt");
150149

151150
string initialText = string.Join(string.Empty, Enumerable.Range(0, 400).Select(i => Guid.NewGuid() + Environment.NewLine));

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/Tvl.VisualStudio.MouseFastScroll.IntegrationTests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="InputSimulatorPlus" Version="1.0.6" />
17-
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="14.1.131" />
17+
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="12.0.0" />
18+
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0" Version="12.0.30111" />
1819
<PackageReference Include="VSSDK.ComponentModelHost.11" Version="11.0.4" />
1920
<PackageReference Include="VSSDK.DTE.8" Version="8.0.4" />
2021
<PackageReference Include="VSSDK.Shell.11" Version="11.0.4" />
21-
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="1.16.30" />
22-
<PackageReference Include="UIAComWrapper" Version="1.1.0.14" />
2322
<PackageReference Include="VsixTesting.Xunit" Version="0.1.4-beta" />
2423
<PackageReference Include="xunit" Version="2.3.1" />
2524
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" PrivateAssets="all" />

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/VsFactTest.cs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,93 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
88
using System.Threading.Tasks;
99
using System.Windows;
1010
using System.Windows.Threading;
11+
using Microsoft.VisualStudio.Shell.Interop;
1112
using Microsoft.VisualStudio.Threading;
1213
using Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Threading;
1314
using Xunit;
1415
using _DTE = EnvDTE._DTE;
1516
using DTE = EnvDTE.DTE;
1617
using ServiceProvider = Microsoft.VisualStudio.Shell.ServiceProvider;
17-
using ThreadHelper = Microsoft.VisualStudio.Shell.ThreadHelper;
1818

1919
public class VsFactTest : AbstractIdeIntegrationTest
2020
{
2121
[VsFact]
2222
public void TestOpenAndCloseIDE()
2323
{
2424
Assert.Equal("devenv", Process.GetCurrentProcess().ProcessName);
25-
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(_DTE));
25+
var dte = (DTE)ServiceProvider.GetService(typeof(_DTE));
2626
Assert.NotNull(dte);
2727
}
2828

2929
[VsFact]
3030
public void TestRunsOnUIThread()
3131
{
32-
Assert.True(ThreadHelper.CheckAccess());
32+
Assert.True(Application.Current.Dispatcher.CheckAccess());
3333
}
3434

3535
[VsFact]
3636
public async Task TestRunsOnUIThreadAsync()
3737
{
38-
Assert.True(ThreadHelper.CheckAccess());
38+
Assert.True(Application.Current.Dispatcher.CheckAccess());
3939
await Task.Yield();
40-
Assert.True(ThreadHelper.CheckAccess());
40+
Assert.True(Application.Current.Dispatcher.CheckAccess());
4141
}
4242

4343
[VsFact]
4444
public async Task TestYieldsToWorkAsync()
4545
{
46-
Assert.True(ThreadHelper.CheckAccess());
46+
Assert.True(Application.Current.Dispatcher.CheckAccess());
4747
await Task.Factory.StartNew(
4848
() => { },
4949
CancellationToken.None,
5050
TaskCreationOptions.None,
5151
new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Application.Current.Dispatcher)));
52-
Assert.True(ThreadHelper.CheckAccess());
52+
Assert.True(Application.Current.Dispatcher.CheckAccess());
5353
}
5454

5555
[VsFact]
5656
public async Task TestJoinableTaskFactoryAsync()
5757
{
5858
Assert.NotNull(JoinableTaskContext);
5959
Assert.NotNull(JoinableTaskFactory);
60-
Assert.True(JoinableTaskContext.IsOnMainThread);
60+
Assert.Equal(Thread.CurrentThread, JoinableTaskContext.MainThread);
6161

6262
await TaskScheduler.Default;
6363

64-
Assert.False(JoinableTaskContext.IsOnMainThread);
64+
Assert.NotEqual(Thread.CurrentThread, JoinableTaskContext.MainThread);
6565

6666
await JoinableTaskFactory.SwitchToMainThreadAsync();
6767

68-
Assert.True(JoinableTaskContext.IsOnMainThread);
68+
Assert.Equal(Thread.CurrentThread, JoinableTaskContext.MainThread);
69+
}
70+
71+
#if DEBUG // https://github.com/josetr/VsixTesting/issues/3
72+
[VsFact(Version = "2012")]
73+
public void TestJoinableTaskFactoryProvidedByTest()
74+
{
75+
var taskSchedulerServiceObject = ServiceProvider.GetService(typeof(SVsTaskSchedulerService));
76+
Assert.NotNull(taskSchedulerServiceObject);
77+
78+
var taskSchedulerService = taskSchedulerServiceObject as IVsTaskSchedulerService;
79+
Assert.NotNull(taskSchedulerService);
80+
81+
var taskSchedulerService2 = taskSchedulerServiceObject as IVsTaskSchedulerService2;
82+
Assert.Null(taskSchedulerService2);
83+
84+
Assert.NotNull(JoinableTaskContext);
85+
}
86+
#endif
87+
88+
[VsFact(Version = "2013-")]
89+
public void TestJoinableTaskFactoryObtainedFromEnvironment()
90+
{
91+
var taskSchedulerServiceObject = ServiceProvider.GetService(typeof(SVsTaskSchedulerService));
92+
Assert.NotNull(taskSchedulerServiceObject);
93+
94+
var taskSchedulerService = taskSchedulerServiceObject as IVsTaskSchedulerService2;
95+
Assert.NotNull(taskSchedulerService);
96+
97+
Assert.Same(JoinableTaskContext, taskSchedulerService.GetAsyncTaskContext());
6998
}
7099
}
71100
}

0 commit comments

Comments
 (0)