From 36a4029b1d91b0826e0c14d98f5c2f9991279222 Mon Sep 17 00:00:00 2001 From: Brad Wilson Date: Sun, 15 Oct 2023 10:24:18 -0700 Subject: [PATCH] Experiment: replace Microsoft.TestPlatform.ObjectModel NUGet reference with AssemblyHelper for one of its types --- src/xunit.runner.visualstudio/VsTestRunner.cs | 27 +++++++++++-------- .../xunit.runner.visualstudio.nuspec | 4 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/xunit.runner.visualstudio/VsTestRunner.cs b/src/xunit.runner.visualstudio/VsTestRunner.cs index 4c79e6c..4d396c9 100644 --- a/src/xunit.runner.visualstudio/VsTestRunner.cs +++ b/src/xunit.runner.visualstudio/VsTestRunner.cs @@ -8,6 +8,7 @@ using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Xunit.Abstractions; using Xunit.Internal; @@ -228,8 +229,11 @@ void DiscoverTests( RemotingUtility.CleanUpRegisteredChannels(); var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false); + var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink); + + using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink); + using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink); - using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink)); foreach (var assemblyFileNameCanBeWithoutAbsolutePath in sources) { var assembly = new XunitProjectAssembly { AssemblyFilename = GetAssemblyFileName(assemblyFileNameCanBeWithoutAbsolutePath) }; @@ -385,17 +389,18 @@ void RunTests( var reporter = GetRunnerReporter(logger, runSettings, runInfos.Select(ari => ari.Assembly.AssemblyFilename).ToList()); using var reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(reporter.CreateMessageHandler(new VisualStudioRunnerLogger(logger))); using var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false); + var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink); - using (AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink))) - { - if (parallelizeAssemblies) - runInfos - .Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)) - .ToList() - .ForEach(@event => @event.WaitOne()); - else - runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)); - } + using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink); + using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink); + + if (parallelizeAssemblies) + runInfos + .Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)) + .ToList() + .ForEach(@event => @event.WaitOne()); + else + runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)); } catch (Exception ex) { diff --git a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec index 6549723..4a3c0d7 100644 --- a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec +++ b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec @@ -16,9 +16,7 @@ true - - - +