diff --git a/.github/workflows/docs_validate.yml b/.github/workflows/docs_validate.yml
index e100eba6..90b75bf7 100644
--- a/.github/workflows/docs_validate.yml
+++ b/.github/workflows/docs_validate.yml
@@ -19,7 +19,7 @@ jobs:
- name: 🔗 Markup Link Checker (mlc)
uses: becheran/mlc@v0.19.2
with:
- args: --do-not-warn-for-redirect-to https://learn.microsoft.com*,https://dotnet.microsoft.com/*,https://dev.azure.com/*,https://app.codecov.io/* -p docfx -i https://aka.ms/onboardsupport,https://aka.ms/spot,https://msrc.microsoft.com/*,https://www.microsoft.com/msrc*,https://microsoft.com/msrc*
+ args: --do-not-warn-for-redirect-to https://learn.microsoft.com*,https://dotnet.microsoft.com/*,https://dev.azure.com/*,https://app.codecov.io/* -p docfx -i https://aka.ms/onboardsupport,https://aka.ms/spot,https://msrc.microsoft.com/*,https://www.microsoft.com/msrc*,https://microsoft.com/msrc*,https://dev.azure.com/devdiv/*
- name: âš™ Install prerequisites
run: |
./init.ps1 -UpgradePrerequisites
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 5353a855..c0df5e45 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -17,12 +17,13 @@
+
-
-
+
+
diff --git a/Microsoft.VisualStudio.Sdk.TestFramework.sln b/Microsoft.VisualStudio.Sdk.TestFramework.sln
index c357c1e5..5c0f8c9f 100644
--- a/Microsoft.VisualStudio.Sdk.TestFramework.sln
+++ b/Microsoft.VisualStudio.Sdk.TestFramework.sln
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.1.32107.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Sdk.TestFramework", "src\Microsoft.VisualStudio.Sdk.TestFramework\Microsoft.VisualStudio.Sdk.TestFramework.csproj", "{A62E3D92-0B5C-4D53-9269-EAC253BBCDEE}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Sdk.TestFramework.Tests", "test\Microsoft.VisualStudio.Sdk.TestFramework.Tests\Microsoft.VisualStudio.Sdk.TestFramework.Tests.csproj", "{94569D82-0C5E-4437-AADF-67738037ED9D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests", "test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.csproj", "{94569D82-0C5E-4437-AADF-67738037ED9D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{824473EA-BB16-47EE-96CA-CD854BF62276}"
ProjectSection(SolutionItems) = preProject
@@ -36,6 +36,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3D7D871C-3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit", "src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.csproj", "{A7FDF327-106E-4627-8D44-AFE7FDF56633}"
EndProject
+Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared", "src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.shproj", "{774B64A2-B1AB-4A09-8307-B87EA0D6D1D2}"
+EndProject
+Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared", "test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.shproj", "{E5D7C833-9946-4415-98E2-3FFC92C10B47}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3", "src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.csproj", "{A384DBA5-D380-41AA-B89A-57D05BD33EA7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests", "test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests.csproj", "{6C1A5941-E2DA-4A98-B80A-8C2F32DD4828}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -54,6 +62,14 @@ Global
{A7FDF327-106E-4627-8D44-AFE7FDF56633}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7FDF327-106E-4627-8D44-AFE7FDF56633}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7FDF327-106E-4627-8D44-AFE7FDF56633}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A384DBA5-D380-41AA-B89A-57D05BD33EA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A384DBA5-D380-41AA-B89A-57D05BD33EA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A384DBA5-D380-41AA-B89A-57D05BD33EA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A384DBA5-D380-41AA-B89A-57D05BD33EA7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6C1A5941-E2DA-4A98-B80A-8C2F32DD4828}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6C1A5941-E2DA-4A98-B80A-8C2F32DD4828}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6C1A5941-E2DA-4A98-B80A-8C2F32DD4828}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6C1A5941-E2DA-4A98-B80A-8C2F32DD4828}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -62,8 +78,20 @@ Global
{A62E3D92-0B5C-4D53-9269-EAC253BBCDEE} = {7750CC1F-2803-4A54-BBF7-5FD05FD49B96}
{94569D82-0C5E-4437-AADF-67738037ED9D} = {3D7D871C-3834-4575-B158-D38FEC07BC6B}
{A7FDF327-106E-4627-8D44-AFE7FDF56633} = {7750CC1F-2803-4A54-BBF7-5FD05FD49B96}
+ {774B64A2-B1AB-4A09-8307-B87EA0D6D1D2} = {7750CC1F-2803-4A54-BBF7-5FD05FD49B96}
+ {E5D7C833-9946-4415-98E2-3FFC92C10B47} = {3D7D871C-3834-4575-B158-D38FEC07BC6B}
+ {A384DBA5-D380-41AA-B89A-57D05BD33EA7} = {7750CC1F-2803-4A54-BBF7-5FD05FD49B96}
+ {6C1A5941-E2DA-4A98-B80A-8C2F32DD4828} = {3D7D871C-3834-4575-B158-D38FEC07BC6B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27C43278-C8F5-4183-A1E3-712A83362BB5}
EndGlobalSection
+ GlobalSection(SharedMSBuildProjectFiles) = preSolution
+ test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems*{6c1a5941-e2da-4a98-b80a-8c2f32dd4828}*SharedItemsImports = 5
+ src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems*{774b64a2-b1ab-4a09-8307-b87ea0d6d1d2}*SharedItemsImports = 13
+ test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems*{94569d82-0c5e-4437-aadf-67738037ed9d}*SharedItemsImports = 5
+ src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems*{a384dba5-d380-41aa-b89a-57d05bd33ea7}*SharedItemsImports = 5
+ src\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems*{a7fdf327-106e-4627-8d44-afe7fdf56633}*SharedItemsImports = 5
+ test\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared\Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems*{e5d7c833-9946-4415-98e2-3ffc92c10b47}*SharedItemsImports = 13
+ EndGlobalSection
EndGlobal
diff --git a/README.md b/README.md
index c7cd2661..f8194322 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,10 @@
# Visual Studio SDK Test Framework
[](https://dev.azure.com/azure-public/vside/_build/latest?definitionId=45&branchName=main)
-[](https://gitter.im/Microsoft/extendvs)
## Microsoft.VisualStudio.Sdk.TestFramework
-[](https://nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework)
+[](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework)
The VS SDK Test Framework is a library for your unit tests that exercise VS code to use
so that certain core VS functionality works outside the VS process so your unit tests can function.
@@ -16,12 +15,20 @@ tend to fail in unit tests without this library installed.
## Microsoft.VisualStudio.Sdk.TestFramework.Xunit
-[](https://nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit)
+[](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit)
-This package contains functionality applicable when using Xunit as your test framework.
+This package contains functionality applicable when using Xunit v2 as your test framework.
[Learn more about this package](src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/README.md).
+## Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3
+
+[](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3)
+
+This package contains functionality applicable when using Xunit v3 as your test framework.
+
+[Learn more about this package](src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/README.md).
+
## Contributing
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
diff --git a/doc/xunit.md b/doc/xunit.md
index 4140df70..394e5f4a 100644
--- a/doc/xunit.md
+++ b/doc/xunit.md
@@ -3,7 +3,9 @@
These instructions apply when consuming this test framework from an Xunit project.
This is an addendum to general instructions outlined in [our README](../README.md).
-1. Install the NuGet package `Microsoft.VisualStudio.Sdk.TestFramework.Xunit` [](https://nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit)
+1. Install the NuGet package.
+ * When using xUnit v2, install `Microsoft.VisualStudio.Sdk.TestFramework.Xunit` [](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit)
+ * When using xUnit v3, install `Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3` [](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3)
1. For *each* of your test classes that rely on VS mocked services, apply the `Collection` attribute and add a parameter and statement to your constructor:
```csharp
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/BrokeredServiceContractTestBase`2.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/BrokeredServiceContractTestBase`2.cs
similarity index 96%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/BrokeredServiceContractTestBase`2.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/BrokeredServiceContractTestBase`2.cs
index b95ec52a..ea606b89 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/BrokeredServiceContractTestBase`2.cs
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/BrokeredServiceContractTestBase`2.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics;
@@ -79,7 +79,11 @@ public BrokeredServiceContractTestBase(ITestOutputHelper logger, ServiceRpcDescr
protected SourceLevels DescriptorLoggingVerbosity { get; set; } = SourceLevels.Verbose;
///
+#if XUNIT_V3
+ public virtual async ValueTask InitializeAsync()
+#else
public virtual async Task InitializeAsync()
+#endif
{
int testId = Interlocked.Increment(ref testCounter);
Func traceSourceFactory = (name, verbosity) =>
@@ -162,7 +166,11 @@ public virtual async Task InitializeAsync()
}
///
+#if XUNIT_V3
+ public virtual async ValueTask DisposeAsync()
+#else
public virtual async Task DisposeAsync()
+#endif
{
(this.ClientProxy as IDisposable)?.Dispose();
@@ -185,10 +193,23 @@ public virtual async Task DisposeAsync()
///
/// Verifies that all methods on the service interface include a as the last parameter.
///
+#if XUNIT_V3
+ [Fact]
+#else
[SkippableFact]
+#endif
public void AllMethodsIncludeCancellationToken()
{
- Skip.IfNot(this.DefaultTestsEnabled, $"{nameof(this.DefaultTestsEnabled)} is set to false.");
+#if XUNIT_V3
+ Assert.SkipUnless(
+#else
+ Skip.IfNot(
+#endif
+#pragma warning disable SA1114 // Parameter list should follow declaration
+ this.DefaultTestsEnabled,
+#pragma warning restore SA1114 // Parameter list should follow declaration
+ $"{nameof(this.DefaultTestsEnabled)} is set to false.");
+
AssertAllMethodsIncludeCancellationToken();
}
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/BrokeredServiceContractTestBase`4.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/BrokeredServiceContractTestBase`4.cs
similarity index 100%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/BrokeredServiceContractTestBase`4.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/BrokeredServiceContractTestBase`4.cs
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/LoggingTestBase.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/LoggingTestBase.cs
similarity index 64%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/LoggingTestBase.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/LoggingTestBase.cs
index 1d9b11b3..86e3c2c5 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/LoggingTestBase.cs
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/LoggingTestBase.cs
@@ -17,7 +17,17 @@ public abstract class LoggingTestBase : TestBase
public LoggingTestBase(ITestOutputHelper logger)
{
this.Logger = logger;
- this.timeoutLoggerRegistration = this.TimeoutToken.Register(() => this.Logger.WriteLine($"TEST TIMEOUT: {nameof(TestBase)}.{nameof(this.TimeoutToken)} has been canceled due to the test exceeding the {this.UnexpectedTimeout} time limit."));
+ this.timeoutLoggerRegistration = this.TimeoutToken.Register(delegate
+ {
+ try
+ {
+ this.Logger.WriteLine($"TEST TIMEOUT: {nameof(TestBase)}.{nameof(this.TimeoutToken)} has been canceled due to the test exceeding the {this.UnexpectedTimeout} time limit.");
+ }
+ catch (InvalidOperationException)
+ {
+ // The test isn't running any more.
+ }
+ });
}
///
@@ -25,6 +35,16 @@ public LoggingTestBase(ITestOutputHelper logger)
///
public ITestOutputHelper Logger { get; }
+ ///
+ /// Gets a for use by all tests.
+ ///
+ protected static CancellationToken CancellationToken =>
+#if XUNIT_V3
+ TestContext.Current.CancellationToken;
+#else
+ CancellationToken.None;
+#endif
+
///
protected override void Dispose(bool disposing)
{
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/MefHostingFixture.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/MefHostingFixture.cs
similarity index 100%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/MefHostingFixture.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/MefHostingFixture.cs
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems
new file mode 100644
index 00000000..c776fc6c
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.projitems
@@ -0,0 +1,19 @@
+
+
+
+ $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+ true
+ 774b64a2-b1ab-4a09-8307-b87ea0d6d1d2
+
+
+ Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.shproj b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.shproj
new file mode 100644
index 00000000..3ed0c4ec
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.shproj
@@ -0,0 +1,13 @@
+
+
+
+ 774b64a2-b1ab-4a09-8307-b87ea0d6d1d2
+ 14.0
+
+
+
+
+
+
+
+
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Mocks/MockVsActivityLogXunitAdapter.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Mocks/MockVsActivityLogXunitAdapter.cs
similarity index 100%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Mocks/MockVsActivityLogXunitAdapter.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/Mocks/MockVsActivityLogXunitAdapter.cs
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/XunitTraceListener.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/XunitTraceListener.cs
similarity index 100%
rename from src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/XunitTraceListener.cs
rename to src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared/XunitTraceListener.cs
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.csproj b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.csproj
new file mode 100644
index 00000000..31dc5571
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.csproj
@@ -0,0 +1,26 @@
+
+
+
+ true
+ Microsoft.VisualStudio.Sdk.TestFramework
+ A test library to help in writing unit and integration tests for Visual Studio extensions.
+ Microsoft VisualStudio SDK Test Framework for Xunit v3
+ enable
+ enable
+ false
+ $(DefineConstants);XUNIT_V3
+ win-x64;win-arm64;win-x86
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/README.md b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/README.md
new file mode 100644
index 00000000..c8ebe2a3
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/README.md
@@ -0,0 +1,18 @@
+# Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3
+
+This package contains functionality applicable when using Xunit v3 as your test framework.
+
+For *each* of your test classes that rely on VS mocked services, apply the `Collection` attribute and add a parameter and statement to your constructor:
+
+```csharp
+using Microsoft.VisualStudio.Sdk.TestFramework;
+
+[Collection(MockedVS.Collection)]
+public class YourTestClass
+{
+ public TestFrameworkTests(GlobalServiceProvider sp)
+ {
+ sp.Reset();
+ }
+}
+```
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Usings.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Usings.cs
new file mode 100644
index 00000000..800d0909
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/Usings.cs
@@ -0,0 +1,4 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+global using Xunit;
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/contentFiles/MockedVS.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/contentFiles/MockedVS.cs
new file mode 100644
index 00000000..5b22fcd6
--- /dev/null
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3/contentFiles/MockedVS.cs
@@ -0,0 +1,24 @@
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace Microsoft.VisualStudio.Sdk.TestFramework
+{
+ using Xunit;
+
+ ///
+ /// Defines the "MockedVS" xunit test collection.
+ ///
+ [CollectionDefinition(Collection)]
+ public class MockedVS :
+#if NETFRAMEWORK || WINDOWS
+ ICollectionFixture,
+#endif
+ ICollectionFixture
+ {
+ ///
+ /// The name of the xunit test collection.
+ ///
+ public const string Collection = "MockedVS";
+ }
+}
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.csproj b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.csproj
index f2e1988d..5dcdaa34 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.csproj
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.csproj
@@ -4,7 +4,7 @@
trueMicrosoft.VisualStudio.Sdk.TestFrameworkA test library to help in writing unit and integration tests for Visual Studio extensions.
- Microsoft VisualStudio SDK Test Framework for Xunit
+ Microsoft VisualStudio SDK Test Framework for Xunit v2enableenablefalse
@@ -21,4 +21,5 @@
+
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/README.md b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/README.md
index 32f11c20..d6be2e55 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/README.md
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework.Xunit/README.md
@@ -1,6 +1,6 @@
# Microsoft.VisualStudio.Sdk.TestFramework.Xunit
-This package contains functionality applicable when using Xunit as your test framework.
+This package contains functionality applicable when using Xunit v2 as your test framework.
For *each* of your test classes that rely on VS mocked services, apply the `Collection` attribute and add a parameter and statement to your constructor:
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework/GlobalServiceProvider.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework/GlobalServiceProvider.cs
index c7ce3d00..fab0fda8 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework/GlobalServiceProvider.cs
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework/GlobalServiceProvider.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK || WINDOWS
@@ -178,6 +178,13 @@ internal void Reset()
{
this.mockBrokeredServiceContainer = new();
this.services = this.baseServices.SetItem(typeof(SVsBrokeredServiceContainer).GUID, this.mockBrokeredServiceContainer);
+
+ // The mock activity log might be forwarding to a service that is only available
+ // within a test. Reset the log so that it does not forward to anything.
+ if (this.baseServices.GetValueOrDefault(typeof(SVsActivityLog).GUID) is MockVsActivityLog log)
+ {
+ log.ForwardTo = null;
+ }
}
///
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework/MefHosting.cs b/src/Microsoft.VisualStudio.Sdk.TestFramework/MefHosting.cs
index aeb26876..f0396772 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework/MefHosting.cs
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework/MefHosting.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
@@ -19,6 +19,12 @@ public class MefHosting
new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true),
new AttributedPartDiscoveryV1(Resolver.DefaultInstance));
+ ///
+ /// The lazily-created mapping of assembly names to file names of
+ /// all assembly files in the environment's current directory.
+ ///
+ private static readonly Dictionary DefaultAssemblyNamesToFileNames = GetDefaultAssemblyNamesToFileNames();
+
///
/// The names of the assemblies to include in the catalog.
///
@@ -45,7 +51,7 @@ public class MefHosting
/// included in the MEF catalog.
///
public MefHosting()
- : this(GetDefaultAssemblyNames())
+ : this(DefaultAssemblyNamesToFileNames.Keys)
{
}
@@ -111,10 +117,17 @@ public async Task CreateExportProviderAsync()
///
/// Gets a reasonable guess at which assemblies to include in the MEF catalog.
///
- /// The list of assembly names.
- private static IEnumerable GetDefaultAssemblyNames()
+ /// A mapping of assembly name to file name.
+ private static Dictionary GetDefaultAssemblyNamesToFileNames()
{
- foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory, "*.dll"))
+ Dictionary map = new();
+
+ // Search for DLL and executable files because xUnit v3
+ // tests can be compiled to an executable instead of a library.
+ IEnumerable dlls = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.dll");
+ IEnumerable exes = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.exe");
+
+ foreach (string file in dlls.Concat(exes))
{
if (file.EndsWith(".resources.dll", StringComparison.OrdinalIgnoreCase))
{
@@ -122,13 +135,20 @@ private static IEnumerable GetDefaultAssemblyNames()
continue;
}
- string? assemblyFullName = null;
+ string fileName = Path.GetFileName(file);
+ if (fileName.StartsWith("Mono.", StringComparison.OrdinalIgnoreCase) ||
+ fileName.StartsWith("Xunit.", StringComparison.OrdinalIgnoreCase))
+ {
+ // Xunit v3 brings in mono assemblies that fail to load and aren't meant for inclusion in the MEF catalog anyway.
+ continue;
+ }
+
try
{
var assemblyName = AssemblyName.GetAssemblyName(file);
if (assemblyName != null)
{
- assemblyFullName = assemblyName.FullName;
+ map[assemblyName.FullName] = file;
}
}
#pragma warning disable CA1031 // Do not catch general exception types
@@ -136,12 +156,9 @@ private static IEnumerable GetDefaultAssemblyNames()
#pragma warning restore CA1031 // Do not catch general exception types
{
}
-
- if (assemblyFullName != null)
- {
- yield return assemblyFullName;
- }
}
+
+ return map;
}
///
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework/Microsoft.VisualStudio.Sdk.TestFramework.csproj b/src/Microsoft.VisualStudio.Sdk.TestFramework/Microsoft.VisualStudio.Sdk.TestFramework.csproj
index dfa2c5fc..5eb2582b 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework/Microsoft.VisualStudio.Sdk.TestFramework.csproj
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework/Microsoft.VisualStudio.Sdk.TestFramework.csproj
@@ -2,7 +2,9 @@
A test library to help in writing unit and integration tests for Visual Studio extensions.
-Xunit test projects should consume via the Microsoft.VisualStudio.Sdk.TestFramework.Xunit package.
+ Xunit v2 test projects should consume via the Microsoft.VisualStudio.Sdk.TestFramework.Xunit package.
+
+ Xunit v3 test projects should consume via the Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3 package.
Microsoft VisualStudio SDK Test Frameworktruetrue
diff --git a/src/Microsoft.VisualStudio.Sdk.TestFramework/README.md b/src/Microsoft.VisualStudio.Sdk.TestFramework/README.md
index 49b307a2..ac4c015d 100644
--- a/src/Microsoft.VisualStudio.Sdk.TestFramework/README.md
+++ b/src/Microsoft.VisualStudio.Sdk.TestFramework/README.md
@@ -9,8 +9,10 @@ tend to fail in unit tests without this library installed.
**Microsoft Internal users**: See [specific guidance if consuming within the `VS` repo](https://github.com/microsoft/vssdktestfx/blob/main/doc/vs_repo.md).
-1. Install the NuGet package [Microsoft.VisualStudio.Sdk.TestFramework](https://nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework),
- or for Xunit test projects, install the more specific [Microsoft.VisualStudio.Sdk.TestFramework.Xunit](https://nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit) package
+1. Install the NuGet package [Microsoft.VisualStudio.Sdk.TestFramework](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework),
+ or for Xunit test projects, install the more specific package:
+ * Xunit v2: [Microsoft.VisualStudio.Sdk.TestFramework.Xunit](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit)
+ * Xunit v3: [Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3](https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3)
1. Make sure your unit test project generates the required binding redirects by adding these two properties to your project file:
diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets
index 9f32cd06..a6e0f4ac 100644
--- a/test/Directory.Build.targets
+++ b/test/Directory.Build.targets
@@ -1,8 +1,4 @@
-
-
-
-
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/Descriptors.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/Descriptors.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/Descriptors.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/Descriptors.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/ICalculator.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/ICalculator.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/ICalculator.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/ICalculator.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/IGreet.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/IGreet.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/IGreet.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/IGreet.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/ISayName.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/ISayName.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceContracts/ISayName.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceContracts/ISayName.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceTests2.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceTests2.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceTests2.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceTests2.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceTests4.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceTests4.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/BrokeredServiceTests4.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/BrokeredServiceTests4.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/ChildServiceProviderTests.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/ChildServiceProviderTests.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/ChildServiceProviderTests.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/ChildServiceProviderTests.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/MefHostingTests.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/MefHostingTests.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/MefHostingTests.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/MefHostingTests.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems
new file mode 100644
index 00000000..63ca1586
--- /dev/null
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.projitems
@@ -0,0 +1,33 @@
+
+
+
+ $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+ true
+ e5d7c833-9946-4415-98e2-3ffc92c10b47
+
+
+ Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.shproj b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.shproj
new file mode 100644
index 00000000..7b7f9474
--- /dev/null
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.shproj
@@ -0,0 +1,13 @@
+
+
+
+ e5d7c833-9946-4415-98e2-3ffc92c10b47
+ 14.0
+
+
+
+
+
+
+
+
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/CalculatorMock.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/CalculatorMock.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/CalculatorMock.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/CalculatorMock.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/GreetMock.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/GreetMock.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/GreetMock.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/GreetMock.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/SayNameMock.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/SayNameMock.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Mocks/SayNameMock.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/Mocks/SayNameMock.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SdkTestUtilitiesTests.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SdkTestUtilitiesTests.cs
similarity index 89%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SdkTestUtilitiesTests.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SdkTestUtilitiesTests.cs
index f48d45ec..b2f16ef1 100644
--- a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SdkTestUtilitiesTests.cs
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SdkTestUtilitiesTests.cs
@@ -26,8 +26,8 @@ public async Task PromotedPackagesAvailable()
{
SomePackage package = await SdkTestUtilities.LoadPackageAsync(this.Logger.WriteLine);
- Assert.NotNull(await package.GetServiceAsync());
- Assert.NotNull(await AsyncServiceProvider.GlobalProvider.GetServiceAsync());
+ Assert.NotNull(await package.GetServiceAsync(CancellationToken));
+ Assert.NotNull(await AsyncServiceProvider.GlobalProvider.GetServiceAsync(CancellationToken));
}
[Fact]
@@ -44,8 +44,8 @@ public async Task ServicesCached()
{
SomePackage package = await SdkTestUtilities.LoadPackageAsync(this.Logger.WriteLine);
- object serviceOne = await package.GetServiceAsync();
- object serviceTwo = await package.GetServiceAsync();
+ object serviceOne = await package.GetServiceAsync(CancellationToken);
+ object serviceTwo = await package.GetServiceAsync(CancellationToken);
Assert.Same(serviceOne, serviceTwo);
}
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SomeMefExport.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SomeMefExport.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SomeMefExport.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SomeMefExport.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SomePackage.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SomePackage.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/SomePackage.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/SomePackage.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/TestFrameworkTests.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/TestFrameworkTests.cs
similarity index 95%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/TestFrameworkTests.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/TestFrameworkTests.cs
index 4e3c5335..fb782698 100644
--- a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/TestFrameworkTests.cs
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared/TestFrameworkTests.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK || WINDOWS
@@ -40,7 +40,7 @@ private interface ITestService
[Fact]
public async Task OleServiceProviderIsService()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
object sp = ServiceProvider.GlobalProvider.GetService(typeof(OleServiceProvider));
Assert.IsAssignableFrom(sp);
}
@@ -65,7 +65,7 @@ public async Task MainThreadHandling()
ThreadHelper.ThrowIfOnUIThread();
Assert.Throws(() => ThreadHelper.ThrowIfNotOnUIThread());
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
Assert.Same(ThreadHelper.JoinableTaskContext.MainThread, Thread.CurrentThread);
#pragma warning disable VSTHRD109 // Switch instead of assert in async methods
@@ -94,7 +94,7 @@ public async Task ThreadHelper_Invoke(bool fromMainThread)
}
else if (fromMainThread && !ThreadHelper.CheckAccess())
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
Assert.True(ThreadHelper.CheckAccess());
}
@@ -121,7 +121,7 @@ public async Task ThreadHelper_Invoke_PropagatesExceptions(bool fromMainThread)
}
else if (fromMainThread && !ThreadHelper.CheckAccess())
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
Assert.True(ThreadHelper.CheckAccess());
}
@@ -145,7 +145,7 @@ public async Task ThreadHelper_BeginInvoke()
{
delegateExecuted.Set();
});
- await delegateExecuted.WaitAsync();
+ await delegateExecuted.WaitAsync(CancellationToken);
}
[Fact]
@@ -168,7 +168,7 @@ await ThreadHelper.JoinableTaskFactory.RunAsync(
async delegate
{
await Task.Yield();
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
});
}
@@ -196,7 +196,7 @@ async Task Helper()
delegateInvoked.Set();
}
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
Helper().Forget();
Assert.False(delegateInvoked.IsSet);
await delegateInvoked.WaitAsync(this.TimeoutToken);
@@ -205,7 +205,7 @@ async Task Helper()
[Fact]
public async Task StartOnIdleExecutesDelegateLater()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
var delegateInvoked = new AsyncManualResetEvent();
ThreadHelper.JoinableTaskFactory.StartOnIdle(delegate
{
@@ -228,7 +228,7 @@ public async Task ExplicitVsTaskCreation()
[Fact]
public async Task AwaitingIVsTaskPreservesContext()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
await ThreadHelper.JoinableTaskFactory.RunAsyncAsVsTask(
VsTaskRunContext.UIThreadBackgroundPriority,
async ct =>
@@ -244,7 +244,7 @@ await ThreadHelper.JoinableTaskFactory.RunAsyncAsVsTask(
[Fact]
public async Task AddService()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
object expected = new object();
this.container.AddService(typeof(SVsProjectMRU), expected);
Assert.Same(expected, ServiceProvider.GlobalProvider.GetService(typeof(SVsProjectMRU)));
@@ -253,7 +253,7 @@ public async Task AddService()
[Fact]
public async Task AddService_TwiceThrows()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
object expected = new object();
this.container.AddService(typeof(SVsProjectMRU), expected);
Assert.Throws(() => this.container.AddService(typeof(SVsProjectMRU), new object()));
@@ -263,7 +263,7 @@ public async Task AddService_TwiceThrows()
[Fact]
public async Task AddService_ExistingMock()
{
- await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken);
object expected = new object();
this.container.AddService(typeof(SVsActivityLog), expected);
Assert.Same(expected, ServiceProvider.GlobalProvider.GetService(typeof(SVsActivityLog)));
@@ -272,9 +272,9 @@ public async Task AddService_ExistingMock()
[Fact]
public async Task MockedBrokeredService_StandardFactory()
{
- IBrokeredServiceContainer sbc = await AsyncServiceProvider.GlobalProvider.GetServiceAsync();
+ IBrokeredServiceContainer sbc = await AsyncServiceProvider.GlobalProvider.GetServiceAsync(CancellationToken);
sbc.Proffer(MockedBrokeredServiceDescriptor, (ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, CancellationToken cancellationToken) => new ValueTask
+
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Usings.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests/Usings.cs
similarity index 100%
rename from test/Microsoft.VisualStudio.Sdk.TestFramework.Tests/Usings.cs
rename to test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests/Usings.cs
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests.csproj b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests.csproj
new file mode 100644
index 00000000..b798270b
--- /dev/null
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests.csproj
@@ -0,0 +1,23 @@
+
+
+
+ $(NoWarn);NU1603
+ Exe
+ $(DefineConstants);XUNIT_V3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Usings.cs b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Usings.cs
new file mode 100644
index 00000000..08ff1569
--- /dev/null
+++ b/test/Microsoft.VisualStudio.Sdk.TestFramework.Xunit.v3.Tests/Usings.cs
@@ -0,0 +1,10 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+global using Microsoft.VisualStudio.Sdk.TestFramework;
+global using Microsoft.VisualStudio.Shell;
+#if NETFRAMEWORK || WINDOWS
+global using Microsoft.VisualStudio.Shell.Interop;
+#endif
+global using Microsoft.VisualStudio.Threading;
+global using Xunit;