diff --git a/playground/TestPlatform.Playground/Environment.cs b/playground/TestPlatform.Playground/Environment.cs index 14cf4a88a4..d7ba86c869 100644 --- a/playground/TestPlatform.Playground/Environment.cs +++ b/playground/TestPlatform.Playground/Environment.cs @@ -7,7 +7,7 @@ namespace TestPlatform.Playground; internal class EnvironmentVariables { - public static readonly Dictionary Variables = new() + public static readonly Dictionary Variables = new() { ["VSTEST_CONNECTION_TIMEOUT"] = "999", ["VSTEST_DEBUG_NOBP"] = "1", diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs index 9449ce97a5..24c0474dc0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs @@ -80,7 +80,7 @@ public void CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs, return; } - if (string.IsNullOrEmpty(_testSessionCorrelationId)) + if (_testSessionCorrelationId.IsNullOrEmpty()) { EqtTrace.Verbose("ArtifactProcessingManager.CollectArtifacts: null testSessionCorrelationId"); return; @@ -118,12 +118,13 @@ public async Task PostProcessArtifactsAsync() } // This is not expected, anyway we prefer avoid exception for post processing - if (string.IsNullOrEmpty(_testSessionCorrelationId)) + if (_testSessionCorrelationId.IsNullOrEmpty()) { EqtTrace.Error("ArtifactProcessingManager.PostProcessArtifacts: Unexpected null testSessionCorrelationId"); return; } + TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null"); if (!_fileHelper.DirectoryExists(_processArtifactFolder)) { EqtTrace.Verbose("ArtifactProcessingManager.PostProcessArtifacts: There are no artifacts to postprocess"); @@ -218,10 +219,10 @@ private TestArtifacts[] LoadTestArtifacts() { TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null"); return _fileHelper.GetFiles(_processArtifactFolder, "*.*", SearchOption.AllDirectories) - .Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file }) - .GroupBy(grp => grp.TestSessionId) - .Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause - .ToArray(); + .Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file }) + .GroupBy(grp => grp.TestSessionId) + .Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause + .ToArray(); } private static Artifact? ParseArtifact(string fileName) diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestProcessAttachDebuggerPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/TestProcessAttachDebuggerPayload.cs index 129b62911b..b820302fb5 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestProcessAttachDebuggerPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestProcessAttachDebuggerPayload.cs @@ -1,7 +1,6 @@ // 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.Collections; using System.Collections.Generic; using System.Runtime.Serialization; diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs index f3d38c923a..397e4ce591 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs @@ -5,13 +5,12 @@ using System.Diagnostics; using System.IO; +using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -21,9 +20,10 @@ public class ConsoleParameters { internal static readonly ConsoleParameters Default = new(); - private string _logFilePath; private readonly IFileHelper _fileHelper; + private string? _logFilePath; + /// /// Create instance of /// @@ -43,12 +43,12 @@ public ConsoleParameters(IFileHelper fileHelper) /// Environment variables to be set for the process. This will merge the specified entries to the environment variables /// inherited from the current process. If you wish to provide a full set of environment variables yourself set to false. /// - public Dictionary EnvironmentVariables { get; set; } = new Dictionary(); + public Dictionary EnvironmentVariables { get; set; } = new(); /// /// When set to true (default), all environment variables are inherited from the current process and the entries provided in are merged with that set. /// When set to false, only the values you provide in are used. Giving you full control of the environment vstest.console is started with. - /// This is only rarely useful and can lead to vstest.console not being able to start at all. + /// This is only rarely useful and can lead to vstest.console not being able to start at all. /// You most likely want to use and combine /// and responses. /// @@ -62,7 +62,7 @@ public ConsoleParameters(IFileHelper fileHelper) /// /// Full path for the log file /// - public string LogFilePath + public string? LogFilePath { get { @@ -71,15 +71,15 @@ public string LogFilePath set { - ValidateArg.NotNullOrEmpty(value, "LogFilePath"); + ValidateArg.NotNullOrEmpty(value!, "LogFilePath"); var directoryPath = Path.GetDirectoryName(value); - if (!string.IsNullOrEmpty(directoryPath) && !_fileHelper.DirectoryExists(directoryPath)) + if (!directoryPath.IsNullOrEmpty() && !_fileHelper.DirectoryExists(directoryPath)) { Directory.CreateDirectory(directoryPath); } // Ensure path is double quoted. if path has white space then it can create problem. - _logFilePath = value.AddDoubleQuote(); + _logFilePath = value!.AddDoubleQuote(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs index c3555f72cd..693f8e0a08 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -54,7 +52,7 @@ public void HandleLogMessage(TestMessageLevel level, string message) /// /// /// - public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable lastChunk) + public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable? lastChunk) { _testDiscoveryEventsHandler.HandleDiscoveryComplete(discoveryCompleteEventArgs.TotalCount, lastChunk, discoveryCompleteEventArgs.IsAborted); } @@ -63,7 +61,7 @@ public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryComplete /// Handles Discovery Tests /// /// - public void HandleDiscoveredTests(IEnumerable discoveredTestCases) + public void HandleDiscoveredTests(IEnumerable? discoveredTestCases) { _testDiscoveryEventsHandler.HandleDiscoveredTests(discoveredTestCases); } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IProcessManager.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IProcessManager.cs index abb030986c..69f72975a8 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IProcessManager.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IProcessManager.cs @@ -3,8 +3,6 @@ using System; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSession.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSession.cs index a608aa836d..aa1d868fbe 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSession.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSession.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -23,12 +21,12 @@ public interface ITestSession : IDisposable, ITestSessionAsync /// Gets the underlying test session info object. /// [Obsolete("This API is not final yet and is subject to changes.", false)] - TestSessionInfo TestSessionInfo { get; } + TestSessionInfo? TestSessionInfo { get; } /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The discovery event handler. @@ -41,7 +39,7 @@ void DiscoverTests( /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The test platform options. @@ -62,7 +60,7 @@ void DiscoverTests( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. @@ -75,7 +73,7 @@ void RunTests( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -90,7 +88,7 @@ void RunTests( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. @@ -103,7 +101,7 @@ void RunTests( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -118,7 +116,7 @@ void RunTests( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. @@ -133,7 +131,7 @@ void RunTestsWithCustomTestHost( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -150,7 +148,7 @@ void RunTestsWithCustomTestHost( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. @@ -165,7 +163,7 @@ void RunTestsWithCustomTestHost( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -182,7 +180,7 @@ void RunTestsWithCustomTestHost( /// /// Stops the test session. /// - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] bool StopTestSession(); @@ -190,9 +188,9 @@ void RunTestsWithCustomTestHost( /// /// Stops the test session. /// - /// + /// /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] bool StopTestSession(ITestSessionEventsHandler eventsHandler); @@ -203,7 +201,7 @@ void RunTestsWithCustomTestHost( /// /// Test Platform options. /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] bool StopTestSession(TestPlatformOptions options, ITestSessionEventsHandler eventsHandler); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSessionAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSessionAsync.cs index 65ffc63c6a..d06c311981 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSessionAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITestSessionAsync.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -23,7 +21,7 @@ public interface ITestSessionAsync : IDisposable /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The discovery event handler. @@ -37,7 +35,7 @@ Task DiscoverTestsAsync( /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The test platform options. @@ -58,7 +56,7 @@ Task DiscoverTestsAsync( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. @@ -71,7 +69,7 @@ Task RunTestsAsync( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -86,7 +84,7 @@ Task RunTestsAsync( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. @@ -99,7 +97,7 @@ Task RunTestsAsync( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -114,7 +112,7 @@ Task RunTestsAsync( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. @@ -129,7 +127,7 @@ Task RunTestsWithCustomTestHostAsync( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -146,7 +144,7 @@ Task RunTestsWithCustomTestHostAsync( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. @@ -161,7 +159,7 @@ Task RunTestsWithCustomTestHostAsync( /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -178,7 +176,7 @@ Task RunTestsWithCustomTestHostAsync( /// /// Stops the test session. /// - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] Task StopTestSessionAsync(); @@ -186,9 +184,9 @@ Task RunTestsWithCustomTestHostAsync( /// /// Stops the test session. /// - /// + /// /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] Task StopTestSessionAsync( @@ -200,7 +198,7 @@ Task StopTestSessionAsync( /// /// Test Platform options. /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] Task StopTestSessionAsync( diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 135451a939..924458d746 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -21,16 +19,16 @@ internal interface ITranslationLayerRequestSender : IDisposable, ITranslationLay /// Initializes communication with the vstest.console.exe process. /// Hosts a communication channel and asynchronously connects to vstest.console.exe. /// - /// + /// /// Port number of the hosted server on this side. int InitializeCommunication(); /// /// Waits for the request handler to be connected. /// - /// + /// /// Time to wait for connection. - /// + /// /// True if the handler has connected, false otherwise. bool WaitForRequestHandlerConnection(int connectionTimeout); @@ -42,14 +40,14 @@ internal interface ITranslationLayerRequestSender : IDisposable, ITranslationLay /// /// Initializes the extensions while probing additional extension paths. /// - /// + /// /// Paths to check for additional extensions. void InitializeExtensions(IEnumerable pathToAdditionalExtensions); /// /// Discovers the tests /// - /// + /// /// Sources for discovering tests. /// Run settings for discovering tests. /// Options to be passed into the platform. @@ -57,15 +55,15 @@ internal interface ITranslationLayerRequestSender : IDisposable, ITranslationLay /// Event handler for discovery events. void DiscoverTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// /// Starts the test run with given sources and criteria. /// - /// + /// /// Sources for test run. /// Run settings for test run. /// Options to be passed into the platform. @@ -73,15 +71,15 @@ void DiscoverTests( /// Event handler for test run events. void StartTestRun( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler); /// /// Starts the test run with given sources and criteria. /// - /// + /// /// Test cases to run. /// Run settings for test run. /// Options to be passed into the platform. @@ -89,15 +87,15 @@ void StartTestRun( /// Event handler for test run events. void StartTestRun( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler); /// /// Starts the test run with given sources and criteria and a custom launcher. /// - /// + /// /// Sources for test run. /// Run settings for test run. /// Options to be passed into the platform. @@ -106,16 +104,16 @@ void StartTestRun( /// Custom test host launcher. void StartTestRunWithCustomHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts the test run with given sources and criteria and a custom launcher. /// - /// + /// /// Test cases to run. /// Run settings for test run. /// Options to be passed into the platform. @@ -124,39 +122,39 @@ void StartTestRunWithCustomHost( /// Custom test host launcher. void StartTestRunWithCustomHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a new test session. /// - /// + /// /// Sources for test run. /// Run settings for test run. /// Options to be passed into the platform. /// Event handler for test session events. /// Custom test host launcher. /// - TestSessionInfo StartTestSession( + TestSessionInfo? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher); + ITestHostLauncher? testHostLauncher); /// /// Stops the test session. /// - /// + /// /// Test session info. /// Test Platform options. /// Event handler for test session events. bool StopTestSession( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs index 81742aaa72..6b56d2b05f 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -33,9 +31,9 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable /// Task DiscoverTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// @@ -49,9 +47,9 @@ Task DiscoverTestsAsync( /// Task StartTestRunAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler); /// @@ -65,9 +63,9 @@ Task StartTestRunAsync( /// Task StartTestRunAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler); /// @@ -82,9 +80,9 @@ Task StartTestRunAsync( /// Task StartTestRunWithCustomHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -100,9 +98,9 @@ Task StartTestRunWithCustomHostAsync( /// Task StartTestRunWithCustomHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -115,12 +113,12 @@ Task StartTestRunWithCustomHostAsync( /// ITestSessionEventsHandler, /// ITestHostLauncher)"/>. /// - Task StartTestSessionAsync( + Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher); + ITestHostLauncher? testHostLauncher); /// /// Asynchronous equivalent of . /// Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// /// Provides back all attachments to test platform for additional processing (for example /// merging). /// - /// + /// /// Collection of attachments. /// Collection of invoked data collectors. /// RunSettings configuration @@ -147,8 +145,8 @@ Task StopTestSessionAsync( /// Cancellation token. Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - IEnumerable invokedDataCollectors, - string runSettings, + IEnumerable? invokedDataCollectors, + string? runSettings, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testRunAttachmentsProcessingCompleteEventsHandler, CancellationToken cancellationToken); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs index f14f1e4025..4a1243b390 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -26,120 +24,120 @@ public interface IVsTestConsoleWrapper : IVsTestConsoleWrapperAsync /// /// Starts a new test session. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The session event handler. - /// + /// /// A test session info object. [Obsolete("This API is not final yet and is subject to changes.", false)] - ITestSession StartTestSession( + ITestSession? StartTestSession( IList sources, - string runSettings, + string? runSettings, ITestSessionEventsHandler eventsHandler); /// /// Starts a new test session. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. /// The session event handler. - /// + /// /// A test session info object. [Obsolete("This API is not final yet and is subject to changes.", false)] - ITestSession StartTestSession( + ITestSession? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// /// Starts a new test session. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. /// The session event handler. /// The custom host launcher. - /// + /// /// A test session info object. [Obsolete("This API is not final yet and is subject to changes.", false)] - ITestSession StartTestSession( + ITestSession? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, ITestHostLauncher testHostLauncher); /// /// Stops the test session. /// - /// + /// /// The test session info object. /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] bool StopTestSession( - TestSessionInfo testSessionInfo, + TestSessionInfo? testSessionInfo, ITestSessionEventsHandler eventsHandler); /// /// Stops the test session. /// - /// + /// /// The test session info object. /// Test Platform options. /// The session event handler. - /// + /// /// True if the session was successfuly stopped, false otherwise. [Obsolete("This API is not final yet and is subject to changes.", false)] bool StopTestSession( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// /// Initializes the test platform with paths to extensions like adapters, loggers and any /// other extensions. /// - /// + /// /// Full paths to extension DLLs. void InitializeExtensions(IEnumerable pathToAdditionalExtensions); /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The discovery event handler. void DiscoverTests( IEnumerable sources, - string discoverySettings, + string? discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler); /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The test platform options. /// The discovery event handler. void DiscoverTests( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, + string? discoverySettings, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// /// Starts test discovery. /// - /// + /// /// The list of source assemblies for the discovery. /// The run settings for the discovery. /// The test platform options. @@ -147,9 +145,9 @@ void DiscoverTests( /// The discovery event handler. void DiscoverTests( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? discoverySettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// @@ -160,33 +158,33 @@ void DiscoverTests( /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. void RunTests( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. /// The run event handler. void RunTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -194,41 +192,41 @@ void RunTests( /// The run event handler. void RunTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. void RunTests( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. /// The run event handler. void RunTests( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -236,29 +234,29 @@ void RunTests( /// The run event handler. void RunTests( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler); /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The run event handler. /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -266,15 +264,15 @@ void RunTestsWithCustomTestHost( /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a test run. /// - /// + /// /// The list of source assemblies for the test run. /// The run settings for the run. /// The test platform options. @@ -283,30 +281,30 @@ void RunTestsWithCustomTestHost( /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The run event handler. /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -314,15 +312,15 @@ void RunTestsWithCustomTestHost( /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// /// Starts a test run. /// - /// + /// /// The list of test cases for the test run. /// The run settings for the run. /// The test platform options. @@ -331,9 +329,9 @@ void RunTestsWithCustomTestHost( /// The custom host launcher. void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 43cdce96ae..c8163b35de 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -11,8 +11,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; /// @@ -33,9 +31,9 @@ public interface IVsTestConsoleWrapperAsync /// ITestSessionEventsHandler)"/>. /// [Obsolete("This API is not final yet and is subject to changes.", false)] - Task StartTestSessionAsync( + Task StartTestSessionAsync( IList sources, - string runSettings, + string? runSettings, ITestSessionEventsHandler eventsHandler); /// @@ -47,10 +45,10 @@ Task StartTestSessionAsync( /// ITestSessionEventsHandler)"/>. /// [Obsolete("This API is not final yet and is subject to changes.", false)] - Task StartTestSessionAsync( + Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// @@ -63,10 +61,10 @@ Task StartTestSessionAsync( /// ITestHostLauncher)"/>. /// [Obsolete("This API is not final yet and is subject to changes.", false)] - Task StartTestSessionAsync( + Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, ITestHostLauncher testHostLauncher); @@ -78,7 +76,7 @@ Task StartTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, + TestSessionInfo? testSessionInfo, ITestSessionEventsHandler eventsHandler); /// @@ -90,8 +88,8 @@ Task StopTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler); /// @@ -110,7 +108,7 @@ Task StopTestSessionAsync( /// Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, + string? discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler); /// @@ -123,8 +121,8 @@ Task DiscoverTestsAsync( /// Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, + string? discoverySettings, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// @@ -138,9 +136,9 @@ Task DiscoverTestsAsync( /// Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? discoverySettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// @@ -157,7 +155,7 @@ Task DiscoverTestsAsync( /// Task RunTestsAsync( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler); /// @@ -170,8 +168,8 @@ Task RunTestsAsync( /// Task RunTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler); /// @@ -185,9 +183,9 @@ Task RunTestsAsync( /// Task RunTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler); /// @@ -199,7 +197,7 @@ Task RunTestsAsync( /// Task RunTestsAsync( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler); /// @@ -212,8 +210,8 @@ Task RunTestsAsync( /// Task RunTestsAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler); /// @@ -227,9 +225,9 @@ Task RunTestsAsync( /// Task RunTestsAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler); /// @@ -242,7 +240,7 @@ Task RunTestsAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -257,8 +255,8 @@ Task RunTestsWithCustomTestHostAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -274,9 +272,9 @@ Task RunTestsWithCustomTestHostAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -290,7 +288,7 @@ Task RunTestsWithCustomTestHostAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -305,8 +303,8 @@ Task RunTestsWithCustomTestHostAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -322,9 +320,9 @@ Task RunTestsWithCustomTestHostAsync( /// Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); @@ -341,7 +339,7 @@ Task RunTestsWithCustomTestHostAsync( /// /// Gets back all attachments to test platform for additional processing (for example merging). /// - /// + /// /// Collection of attachments. /// XML processing settings. /// @@ -352,7 +350,7 @@ Task RunTestsWithCustomTestHostAsync( /// Cancellation token. Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - string processingSettings, + string? processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventsHandler, @@ -361,7 +359,7 @@ Task ProcessTestRunAttachmentsAsync( /// /// Gets back all attachments to test platform for additional processing (for example merging). /// - /// + /// /// Collection of attachments. /// Collection of invoked data collectors. /// XML processing settings. @@ -373,8 +371,8 @@ Task ProcessTestRunAttachmentsAsync( /// Cancellation token. Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - IEnumerable invokedDataCollectors, - string processingSettings, + IEnumerable? invokedDataCollectors, + string? processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventsHandler, diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj index 2c1cf7f1eb..87a74b793d 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj @@ -6,7 +6,7 @@ Microsoft.TestPlatform.VsTestConsole.TranslationLayer - netstandard2.0;net451 + netstandard2.0;net451;net6.0 net6.0 false diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TestSession.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TestSession.cs index b63e8e0d02..aea930c533 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TestSession.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TestSession.cs @@ -12,8 +12,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -30,11 +28,11 @@ public class TestSession : ITestSession /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public TestSessionInfo TestSessionInfo { get; private set; } + public TestSessionInfo? TestSessionInfo { get; private set; } /// /// Initializes a new instance of the class. /// - /// + /// /// The test session info object. /// The session event handler. /// The encapsulated console wrapper. @@ -66,7 +64,7 @@ public void Dispose() /// /// Disposes of the current instance of the class. /// - /// + /// /// Indicates if managed resources should be disposed. protected virtual void Dispose(bool disposing) { @@ -120,7 +118,7 @@ public void DiscoverTests( public void DiscoverTests( IEnumerable sources, string discoverySettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { _consoleWrapper.DiscoverTests( @@ -150,7 +148,7 @@ public void RunTests( public void RunTests( IEnumerable sources, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { _consoleWrapper.RunTests( @@ -180,7 +178,7 @@ public void RunTests( public void RunTests( IEnumerable testCases, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { _consoleWrapper.RunTests( @@ -212,7 +210,7 @@ public void RunTestsWithCustomTestHost( public void RunTestsWithCustomTestHost( IEnumerable sources, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -246,7 +244,7 @@ public void RunTestsWithCustomTestHost( public void RunTestsWithCustomTestHost( IEnumerable testCases, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -276,7 +274,7 @@ public bool StopTestSession(ITestSessionEventsHandler eventsHandler) /// [Obsolete("This API is not final yet and is subject to changes.", false)] public bool StopTestSession( - TestPlatformOptions options, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { if (TestSessionInfo == null) @@ -320,7 +318,7 @@ await DiscoverTestsAsync( public async Task DiscoverTestsAsync( IEnumerable sources, string discoverySettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { await _consoleWrapper.DiscoverTestsAsync( @@ -350,7 +348,7 @@ await RunTestsAsync( public async Task RunTestsAsync( IEnumerable sources, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { await _consoleWrapper.RunTestsAsync( @@ -380,7 +378,7 @@ await RunTestsAsync( public async Task RunTestsAsync( IEnumerable testCases, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { await _consoleWrapper.RunTestsAsync( @@ -412,7 +410,7 @@ await RunTestsWithCustomTestHostAsync( public async Task RunTestsWithCustomTestHostAsync( IEnumerable sources, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -446,7 +444,7 @@ await RunTestsWithCustomTestHostAsync( public async Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, string runSettings, - TestPlatformOptions options, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -476,7 +474,7 @@ public async Task StopTestSessionAsync(ITestSessionEventsHandler eventsHan /// [Obsolete("This API is not final yet and is subject to changes.", false)] public async Task StopTestSessionAsync( - TestPlatformOptions options, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { if (TestSessionInfo == null) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TransationLayerException.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TransationLayerException.cs index cb5ebe8b7a..65068115fd 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TransationLayerException.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/TransationLayerException.cs @@ -3,8 +3,6 @@ using System; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -16,7 +14,7 @@ public class TransationLayerException : Exception /// Initializes a new instance of the TransationLayerException class. /// /// The message that describes the error. - public TransationLayerException(string message) + public TransationLayerException(string? message) : base(message) { } @@ -26,7 +24,7 @@ public TransationLayerException(string message) /// /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception. - public TransationLayerException(string message, Exception innerException) + public TransationLayerException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs index 8cb2706e17..2ffd6b599d 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs @@ -10,7 +10,7 @@ using System.Threading; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; - +using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; @@ -19,8 +19,6 @@ using Resources = Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Resources; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -52,17 +50,17 @@ internal class VsTestConsoleProcessManager : IProcessManager private readonly string _vstestConsolePath; private readonly object _syncObject = new(); - private bool _vstestConsoleStarted; - private bool _vstestConsoleExited; private readonly bool _isNetCoreRunner; - private readonly string _dotnetExePath; - private Process _process; + private readonly string? _dotnetExePath; private readonly ManualResetEvent _processExitedEvent = new(false); + private Process? _process; + private bool _vstestConsoleStarted; + private bool _vstestConsoleExited; internal IFileHelper FileHelper { get; set; } /// - public event EventHandler ProcessExited; + public event EventHandler? ProcessExited; /// /// Creates an instance of VsTestConsoleProcessManager class. @@ -158,7 +156,7 @@ public void StartProcess(ConsoleParameters consoleParameters) _vstestConsoleStarted = true; } - _process.EnableRaisingEvents = true; + _process!.EnableRaisingEvents = true; _process.Exited += Process_Exited; _process.OutputDataReceived += Process_OutputDataReceived; @@ -178,11 +176,14 @@ public void ShutdownProcess() { EqtTrace.Info($"VsTestConsoleProcessManager.ShutDownProcess : Terminating vstest.console process after waiting for {Endsessiontimeout} milliseconds."); _vstestConsoleExited = true; - _process.OutputDataReceived -= Process_OutputDataReceived; - _process.ErrorDataReceived -= Process_ErrorDataReceived; - SafelyTerminateProcess(); - _process.Dispose(); - _process = null; + if (_process is not null) + { + _process.OutputDataReceived -= Process_OutputDataReceived; + _process.ErrorDataReceived -= Process_ErrorDataReceived; + SafelyTerminateProcess(); + _process.Dispose(); + _process = null; + } } } @@ -201,7 +202,7 @@ private void SafelyTerminateProcess() } } - private void Process_Exited(object sender, EventArgs e) + private void Process_Exited(object? sender, EventArgs e) { lock (_syncObject) { @@ -236,7 +237,7 @@ private string[] BuildArguments(ConsoleParameters parameters) string.Format(CultureInfo.InvariantCulture, PortArgument, parameters.PortNumber) }; - if (!string.IsNullOrEmpty(parameters.LogFilePath)) + if (!parameters.LogFilePath.IsNullOrEmpty()) { // Extra args: --diag|/diag:;tracelevel= args.Add(string.Format(CultureInfo.InvariantCulture, DiagArgument, parameters.LogFilePath, parameters.TraceLevel)); @@ -251,8 +252,12 @@ private string[] BuildArguments(ConsoleParameters parameters) } private string GetConsoleRunner() - => _isNetCoreRunner ? (string.IsNullOrEmpty(_dotnetExePath) ? new DotnetHostHelper().GetDotnetPath() : _dotnetExePath) : GetEscapeSequencedPath(_vstestConsolePath); - - private string GetEscapeSequencedPath(string path) - => string.IsNullOrEmpty(path) ? path : $"\"{path.Trim('"')}\""; + => _isNetCoreRunner + ? _dotnetExePath.IsNullOrEmpty() + ? new DotnetHostHelper().GetDotnetPath() + : _dotnetExePath + : GetEscapeSequencedPath(_vstestConsolePath); + + private static string GetEscapeSequencedPath(string path) + => path.IsNullOrEmpty() ? path : $"\"{path.Trim('"')}\""; } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 33c1ad1b32..7619acd83d 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -23,8 +23,6 @@ using TranslationLayerResources = Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Resources; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -38,20 +36,17 @@ internal class VsTestConsoleRequestSender : ITranslationLayerRequestSender private const int MinimumProtocolVersionWithTestSessionSupport = 5; private readonly ICommunicationManager _communicationManager; - private readonly IDataSerializer _dataSerializer; private readonly ITestPlatformEventSource _testPlatformEventSource; - private readonly ManualResetEvent _handShakeComplete = new(false); private bool _handShakeSuccessful; - private int _protocolVersion = ProtocolVersioning.HighestSupportedVersion; /// /// Used to cancel blocking tasks associated with the vstest.console process. /// - private CancellationTokenSource _processExitCancellationTokenSource; + private CancellationTokenSource? _processExitCancellationTokenSource; /// /// Initializes a new instance of the class. @@ -171,9 +166,9 @@ public void InitializeExtensions(IEnumerable pathToAdditionalExtensions) /// public void DiscoverTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 eventHandler) { EqtTrace.Info("VsTestConsoleRequestSender.DiscoverTests: Starting test discovery."); @@ -189,9 +184,9 @@ public void DiscoverTests( /// public async Task DiscoverTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 eventHandler) { EqtTrace.Info("VsTestConsoleRequestSender.DiscoverTestsAsync: Starting test discovery."); @@ -207,9 +202,9 @@ await SendMessageAndListenAndReportTestCasesAsync( /// public void StartTestRun( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler) { EqtTrace.Info("VsTestConsoleRequestSender.StartTestRun: Starting test run."); @@ -230,9 +225,9 @@ public void StartTestRun( /// public async Task StartTestRunAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler) { EqtTrace.Info("VsTestConsoleRequestSender.StartTestRunAsync: Starting test run."); @@ -253,9 +248,9 @@ await SendMessageAndListenAndReportTestResultsAsync( /// public void StartTestRun( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler) { EqtTrace.Info("VsTestConsoleRequestSender.StartTestRun: Starting test run."); @@ -276,9 +271,9 @@ public void StartTestRun( /// public async Task StartTestRunAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler) { EqtTrace.Info("VsTestConsoleRequestSender.StartTestRunAsync: Starting test run."); @@ -299,9 +294,9 @@ await SendMessageAndListenAndReportTestResultsAsync( /// public void StartTestRunWithCustomHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customHostLauncher) { @@ -324,9 +319,9 @@ public void StartTestRunWithCustomHost( /// public async Task StartTestRunWithCustomHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customHostLauncher) { @@ -349,9 +344,9 @@ await SendMessageAndListenAndReportTestResultsAsync( /// public void StartTestRunWithCustomHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customHostLauncher) { @@ -374,9 +369,9 @@ public void StartTestRunWithCustomHost( /// public async Task StartTestRunWithCustomHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customHostLauncher) { @@ -397,12 +392,12 @@ await SendMessageAndListenAndReportTestResultsAsync( } /// - public TestSessionInfo StartTestSession( + public TestSessionInfo? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher) + ITestHostLauncher? testHostLauncher) { // Make sure vstest.console knows how to handle start/stop test session messages. // Bail out if it doesn't, otherwise we'll hang waiting for a reply from the console @@ -448,10 +443,9 @@ public TestSessionInfo StartTestSession( switch (message.MessageType) { case MessageType.StartTestSessionCallback: - var ackPayload = _dataSerializer - .DeserializePayload(message); - eventsHandler?.HandleStartTestSessionComplete( - ackPayload.EventArgs); + var ackPayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(ackPayload is not null, "ackPayload is null"); + eventsHandler?.HandleStartTestSessionComplete(ackPayload.EventArgs); return ackPayload.EventArgs.TestSessionInfo; case MessageType.CustomTestHostLaunch: @@ -464,8 +458,8 @@ public TestSessionInfo StartTestSession( break; case MessageType.TestMessage: - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventsHandler?.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -499,12 +493,12 @@ public TestSessionInfo StartTestSession( } /// - public async Task StartTestSessionAsync( + public async Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher) + ITestHostLauncher? testHostLauncher) { // Make sure vstest.console knows how to handle start/stop test session messages. // Bail out if it doesn't, otherwise we'll hang waiting for a reply from the console @@ -512,7 +506,7 @@ public async Task StartTestSessionAsync( if (_protocolVersion < MinimumProtocolVersionWithTestSessionSupport) { eventsHandler?.HandleStartTestSessionComplete(new()); - return await Task.FromResult((TestSessionInfo)null); + return await Task.FromResult((TestSessionInfo?)null); } EqtTrace.Info("VsTestConsoleRequestSender.StartTestSession: Starting test session."); @@ -549,10 +543,9 @@ public async Task StartTestSessionAsync( switch (message.MessageType) { case MessageType.StartTestSessionCallback: - var ackPayload = _dataSerializer - .DeserializePayload(message); - eventsHandler?.HandleStartTestSessionComplete( - ackPayload.EventArgs); + var ackPayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(ackPayload is not null, "ackPayload is null"); + eventsHandler?.HandleStartTestSessionComplete(ackPayload.EventArgs); return ackPayload.EventArgs.TestSessionInfo; case MessageType.CustomTestHostLaunch: @@ -565,8 +558,8 @@ public async Task StartTestSessionAsync( break; case MessageType.TestMessage: - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventsHandler?.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -599,8 +592,8 @@ public async Task StartTestSessionAsync( /// public bool StopTestSession( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { // Make sure vstest.console knows how to handle start/stop test session messages. @@ -647,12 +640,13 @@ public bool StopTestSession( { case MessageType.StopTestSessionCallback: var payload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(payload is not null, "payload is null"); eventsHandler?.HandleStopTestSessionComplete(payload.EventArgs); return payload.EventArgs.IsStopped; case MessageType.TestMessage: - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventsHandler?.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -688,8 +682,8 @@ public bool StopTestSession( /// public async Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { // Make sure vstest.console knows how to handle start/stop test session messages. @@ -736,12 +730,13 @@ public async Task StopTestSessionAsync( { case MessageType.StopTestSessionCallback: var payload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(payload is not null, "payload is null"); eventsHandler?.HandleStopTestSessionComplete(payload.EventArgs); return payload.EventArgs.IsStopped; case MessageType.TestMessage: - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventsHandler?.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -802,7 +797,7 @@ public void CancelDiscovery() /// public void OnProcessExited() { - _processExitCancellationTokenSource.Cancel(); + _processExitCancellationTokenSource?.Cancel(); } /// @@ -820,8 +815,8 @@ public void EndSession() /// public Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - IEnumerable invokedDataCollectors, - string runSettings, + IEnumerable? invokedDataCollectors, + string? runSettings, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) @@ -845,41 +840,40 @@ public void Dispose() private bool HandShakeWithVsTestConsole() { - var success = false; var message = _communicationManager.ReceiveMessage(); - if (message.MessageType == MessageType.SessionConnected) + if (message?.MessageType != MessageType.SessionConnected) { - _communicationManager.SendMessage( - MessageType.VersionCheck, - _protocolVersion); + EqtTrace.Error( + "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: SessionConnected Message Expected but different message received: Received MessageType: {0}", + message?.MessageType); + return false; + } - message = _communicationManager.ReceiveMessage(); + _communicationManager.SendMessage( + MessageType.VersionCheck, + _protocolVersion); - if (message.MessageType == MessageType.VersionCheck) - { - _protocolVersion = _dataSerializer - .DeserializePayload(message); - success = true; - } - else if (message.MessageType == MessageType.ProtocolError) - { - // TODO : Payload for ProtocolError needs to finalized. - EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: Version Check failed. ProtolError was received from the runner"); - } - else - { - EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: VersionCheck Message Expected but different message received: Received MessageType: {0}", - message.MessageType); - } + message = _communicationManager.ReceiveMessage(); + var success = false; + + if (message?.MessageType == MessageType.VersionCheck) + { + _protocolVersion = _dataSerializer + .DeserializePayload(message); + success = true; + } + else if (message?.MessageType == MessageType.ProtocolError) + { + // TODO : Payload for ProtocolError needs to finalized. + EqtTrace.Error( + "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: Version Check failed. ProtolError was received from the runner"); } else { EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: SessionConnected Message Expected but different message received: Received MessageType: {0}", - message.MessageType); + "VsTestConsoleRequestSender.HandShakeWithVsTestConsole: VersionCheck Message Expected but different message received: Received MessageType: {0}", + message?.MessageType); } return success; @@ -887,42 +881,42 @@ private bool HandShakeWithVsTestConsole() private async Task HandShakeWithVsTestConsoleAsync() { - var success = false; + TPDebug.Assert(_processExitCancellationTokenSource is not null, "_processExitCancellationTokenSource is null"); var message = await _communicationManager.ReceiveMessageAsync( _processExitCancellationTokenSource.Token).ConfigureAwait(false); - if (message.MessageType == MessageType.SessionConnected) + if (message?.MessageType != MessageType.SessionConnected) { - _communicationManager.SendMessage( - MessageType.VersionCheck, - _protocolVersion); + EqtTrace.Error( + "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: SessionConnected Message Expected but different message received: Received MessageType: {0}", + message?.MessageType); + return false; + } - message = await _communicationManager.ReceiveMessageAsync( - _processExitCancellationTokenSource.Token).ConfigureAwait(false); + _communicationManager.SendMessage( + MessageType.VersionCheck, + _protocolVersion); - if (message.MessageType == MessageType.VersionCheck) - { - _protocolVersion = _dataSerializer.DeserializePayload(message); - success = true; - } - else if (message.MessageType == MessageType.ProtocolError) - { - // TODO : Payload for ProtocolError needs to finalized. - EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: Version Check failed. ProtolError was received from the runner"); - } - else - { - EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: VersionCheck Message Expected but different message received: Received MessageType: {0}", - message.MessageType); - } + message = await _communicationManager.ReceiveMessageAsync( + _processExitCancellationTokenSource.Token).ConfigureAwait(false); + + var success = false; + if (message?.MessageType == MessageType.VersionCheck) + { + _protocolVersion = _dataSerializer.DeserializePayload(message); + success = true; + } + else if (message?.MessageType == MessageType.ProtocolError) + { + // TODO : Payload for ProtocolError needs to finalized. + EqtTrace.Error( + "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: Version Check failed. ProtolError was received from the runner"); } else { EqtTrace.Error( - "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: SessionConnected Message Expected but different message received: Received MessageType: {0}", - message.MessageType); + "VsTestConsoleRequestSender.HandShakeWithVsTestConsoleAsync: VersionCheck Message Expected but different message received: Received MessageType: {0}", + message?.MessageType); } return success; @@ -930,9 +924,9 @@ private async Task HandShakeWithVsTestConsoleAsync() private void SendMessageAndListenAndReportTestCases( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 eventHandler) { try @@ -971,6 +965,7 @@ private void SendMessageAndListenAndReportTestCases( "VsTestConsoleRequestSender.SendMessageAndListenAndReportTestCases: Discovery complete."); var discoveryCompletePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(discoveryCompletePayload is not null, "discoveryCompletePayload is null"); var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs { @@ -991,8 +986,8 @@ private void SendMessageAndListenAndReportTestCases( } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -1021,9 +1016,9 @@ private void SendMessageAndListenAndReportTestCases( private async Task SendMessageAndListenAndReportTestCasesAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 eventHandler) { try @@ -1063,7 +1058,7 @@ private async Task SendMessageAndListenAndReportTestCasesAsync( var discoveryCompletePayload = _dataSerializer.DeserializePayload(message); - + TPDebug.Assert(discoveryCompletePayload is not null, "discoveryCompletePayload is null"); var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs { TotalCount = discoveryCompletePayload.TotalTests, @@ -1087,6 +1082,7 @@ private async Task SendMessageAndListenAndReportTestCasesAsync( { var testMessagePayload = _dataSerializer .DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -1118,7 +1114,7 @@ private void SendMessageAndListenAndReportTestResults( string messageType, object payload, ITestRunEventsHandler eventHandler, - ITestHostLauncher customHostLauncher) + ITestHostLauncher? customHostLauncher) { try { @@ -1148,7 +1144,7 @@ private void SendMessageAndListenAndReportTestResults( var testRunCompletePayload = _dataSerializer .DeserializePayload(message); - + TPDebug.Assert(testRunCompletePayload is not null, "testRunCompletePayload is null"); eventHandler.HandleTestRunComplete( testRunCompletePayload.TestRunCompleteArgs, testRunCompletePayload.LastRunTests, @@ -1160,6 +1156,7 @@ private void SendMessageAndListenAndReportTestResults( { var testMessagePayload = _dataSerializer .DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -1199,7 +1196,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync( string messageType, object payload, ITestRunEventsHandler eventHandler, - ITestHostLauncher customHostLauncher) + ITestHostLauncher? customHostLauncher) { try { @@ -1228,7 +1225,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync( var testRunCompletePayload = _dataSerializer .DeserializePayload(message); - + TPDebug.Assert(testRunCompletePayload is not null, "testRunCompletePayload is null"); eventHandler.HandleTestRunComplete( testRunCompletePayload.TestRunCompleteArgs, testRunCompletePayload.LastRunTests, @@ -1238,8 +1235,8 @@ private async Task SendMessageAndListenAndReportTestResultsAsync( } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); eventHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -1277,8 +1274,8 @@ private async Task SendMessageAndListenAndReportTestResultsAsync( private async Task SendMessageAndListenAndReportAttachmentsProcessingResultAsync( IEnumerable attachments, - IEnumerable invokedDataCollectors, - string runSettings, + IEnumerable? invokedDataCollectors, + string? runSettings, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken) @@ -1319,6 +1316,7 @@ private async Task SendMessageAndListenAndReportAttachmentsProcessingResultAsync var testRunAttachmentsProcessingCompletePayload = _dataSerializer .DeserializePayload(message); + TPDebug.Assert(testRunAttachmentsProcessingCompletePayload is not null, "testRunAttachmentsProcessingCompletePayload is null"); eventHandler.HandleTestRunAttachmentsProcessingComplete( testRunAttachmentsProcessingCompletePayload.AttachmentsProcessingCompleteEventArgs, @@ -1331,13 +1329,16 @@ private async Task SendMessageAndListenAndReportAttachmentsProcessingResultAsync { var testRunAttachmentsProcessingProgressPayload = _dataSerializer .DeserializePayload(message); + TPDebug.Assert(testRunAttachmentsProcessingProgressPayload is not null, "testRunAttachmentsProcessingProgressPayload is null"); + eventHandler.HandleTestRunAttachmentsProcessingProgress( testRunAttachmentsProcessingProgressPayload.AttachmentsProcessingProgressEventArgs); } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { - var testMessagePayload = _dataSerializer - .DeserializePayload(message); + var testMessagePayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(testMessagePayload is not null, "testMessagePayload is null"); + eventHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); @@ -1375,25 +1376,21 @@ private async Task SendMessageAndListenAndReportAttachmentsProcessingResultAsync private Message TryReceiveMessage() { - var receiverMessageTask = _communicationManager.ReceiveMessageAsync( - _processExitCancellationTokenSource.Token); - receiverMessageTask.Wait(); - Message message = receiverMessageTask.Result; - - return message ?? throw new TransationLayerException( - TranslationLayerResources.FailedToReceiveMessage); + return TryReceiveMessageAsync().GetAwaiter().GetResult(); } private async Task TryReceiveMessageAsync() { - Message message = await _communicationManager.ReceiveMessageAsync( - _processExitCancellationTokenSource.Token).ConfigureAwait(false); + // TODO: Rework logic of this class to avoid relying on throwing/catching exceptions: + // - NRE on null _processExitCancellationTokenSource + // - TransationLayerException on null message + Message? message = await _communicationManager.ReceiveMessageAsync(_processExitCancellationTokenSource!.Token) + .ConfigureAwait(false); - return message ?? throw new TransationLayerException( - TranslationLayerResources.FailedToReceiveMessage); + return message ?? throw new TransationLayerException(TranslationLayerResources.FailedToReceiveMessage); } - private void HandleCustomHostLaunch(ITestHostLauncher customHostLauncher, Message message) + private void HandleCustomHostLaunch(ITestHostLauncher? customHostLauncher, Message message) { var ackPayload = new CustomHostLaunchAckPayload() { @@ -1430,7 +1427,7 @@ private void HandleCustomHostLaunch(ITestHostLauncher customHostLauncher, Messag } } - private void AttachDebuggerToProcess(ITestHostLauncher customHostLauncher, Message message) + private void AttachDebuggerToProcess(ITestHostLauncher? customHostLauncher, Message message) { var ackPayload = new EditorAttachDebuggerAckPayload() { @@ -1444,6 +1441,7 @@ private void AttachDebuggerToProcess(ITestHostLauncher customHostLauncher, Messa if (message.MessageType == MessageType.EditorAttachDebugger2) { var attachDebuggerPayload = _dataSerializer.DeserializePayload(message); + TPDebug.Assert(attachDebuggerPayload is not null, "attachDebuggerPayload is null"); switch (customHostLauncher) { case ITestHostLauncher3 launcher3: diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index e543f6ba57..5e76f3adcd 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -24,8 +24,6 @@ using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources; using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants; -#nullable disable - namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; /// @@ -168,9 +166,9 @@ public void StartSession() /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public ITestSession StartTestSession( + public ITestSession? StartTestSession( IList sources, - string runSettings, + string? runSettings, ITestSessionEventsHandler eventsHandler) { return StartTestSession( @@ -182,10 +180,10 @@ public ITestSession StartTestSession( /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public ITestSession StartTestSession( + public ITestSession? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { return StartTestSession( @@ -198,12 +196,12 @@ public ITestSession StartTestSession( /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public ITestSession StartTestSession( + public ITestSession? StartTestSession( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher) + ITestHostLauncher? testHostLauncher) { _testPlatformEventSource.TranslationLayerStartTestSessionStart(); @@ -227,7 +225,7 @@ public ITestSession StartTestSession( /// [Obsolete("This API is not final yet and is subject to changes.", false)] public bool StopTestSession( - TestSessionInfo testSessionInfo, + TestSessionInfo? testSessionInfo, ITestSessionEventsHandler eventsHandler) { return StopTestSession( @@ -239,8 +237,8 @@ public bool StopTestSession( /// [Obsolete("This API is not final yet and is subject to changes.", false)] public bool StopTestSession( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { _testPlatformEventSource.TranslationLayerStopTestSessionStart(); @@ -264,7 +262,7 @@ public void InitializeExtensions(IEnumerable pathToAdditionalExtensions) /// public void DiscoverTests( IEnumerable sources, - string discoverySettings, + string? discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler) { DiscoverTests( @@ -277,8 +275,8 @@ public void DiscoverTests( /// public void DiscoverTests( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, + string? discoverySettings, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { DiscoverTests( @@ -292,9 +290,9 @@ public void DiscoverTests( /// public void DiscoverTests( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? discoverySettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { _testPlatformEventSource.TranslationLayerDiscoveryStart(); @@ -317,7 +315,7 @@ public void CancelDiscovery() /// public void RunTests( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler) { RunTests( @@ -330,8 +328,8 @@ public void RunTests( /// public void RunTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { RunTests( @@ -345,9 +343,9 @@ public void RunTests( /// public void RunTests( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var sourceList = sources.ToList(); @@ -369,7 +367,7 @@ public void RunTests( /// public void RunTests( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler) { RunTests( @@ -382,8 +380,8 @@ public void RunTests( /// public void RunTests( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { RunTests( @@ -397,9 +395,9 @@ public void RunTests( /// public void RunTests( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var testCaseList = testCases.ToList(); @@ -421,7 +419,7 @@ public void RunTests( /// public void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -436,8 +434,8 @@ public void RunTestsWithCustomTestHost( /// public void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -453,9 +451,9 @@ public void RunTestsWithCustomTestHost( /// public void RunTestsWithCustomTestHost( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -479,7 +477,7 @@ public void RunTestsWithCustomTestHost( /// public void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -494,8 +492,8 @@ public void RunTestsWithCustomTestHost( /// public void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -511,9 +509,9 @@ public void RunTestsWithCustomTestHost( /// public void RunTestsWithCustomTestHost( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -594,9 +592,9 @@ public async Task StartSessionAsync() /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public async Task StartTestSessionAsync( + public async Task StartTestSessionAsync( IList sources, - string runSettings, + string? runSettings, ITestSessionEventsHandler eventsHandler) { return await StartTestSessionAsync( @@ -608,10 +606,10 @@ public async Task StartTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public async Task StartTestSessionAsync( + public async Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { return await StartTestSessionAsync( @@ -624,12 +622,12 @@ public async Task StartTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] - public async Task StartTestSessionAsync( + public async Task StartTestSessionAsync( IList sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler, - ITestHostLauncher testHostLauncher) + ITestHostLauncher? testHostLauncher) { _testPlatformEventSource.TranslationLayerStartTestSessionStart(); @@ -642,7 +640,7 @@ public async Task StartTestSessionAsync( eventsHandler, testHostLauncher).ConfigureAwait(false); - return (testSessionInfo != null) + return testSessionInfo != null ? new TestSession( testSessionInfo, eventsHandler, @@ -653,7 +651,7 @@ public async Task StartTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] public async Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, + TestSessionInfo? testSessionInfo, ITestSessionEventsHandler eventsHandler) { return await StopTestSessionAsync( @@ -665,8 +663,8 @@ public async Task StopTestSessionAsync( /// [Obsolete("This API is not final yet and is subject to changes.", false)] public async Task StopTestSessionAsync( - TestSessionInfo testSessionInfo, - TestPlatformOptions options, + TestSessionInfo? testSessionInfo, + TestPlatformOptions? options, ITestSessionEventsHandler eventsHandler) { _testPlatformEventSource.TranslationLayerStopTestSessionStart(); @@ -689,7 +687,7 @@ public async Task InitializeExtensionsAsync(IEnumerable pathToAdditional /// public async Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, + string? discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler) { await DiscoverTestsAsync( @@ -703,8 +701,8 @@ await DiscoverTestsAsync( /// public async Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, + string? discoverySettings, + TestPlatformOptions? options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { await DiscoverTestsAsync( @@ -718,9 +716,9 @@ await DiscoverTestsAsync( /// public async Task DiscoverTestsAsync( IEnumerable sources, - string discoverySettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? discoverySettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { _testPlatformEventSource.TranslationLayerDiscoveryStart(); @@ -737,7 +735,7 @@ await _requestSender.DiscoverTestsAsync( /// public async Task RunTestsAsync( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler) { await RunTestsAsync( @@ -750,8 +748,8 @@ await RunTestsAsync( /// public async Task RunTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { await RunTestsAsync( @@ -765,9 +763,9 @@ await RunTestsAsync( /// public async Task RunTestsAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var sourceList = sources.ToList(); @@ -789,7 +787,7 @@ await _requestSender.StartTestRunAsync( /// public async Task RunTestsAsync( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler) { await RunTestsAsync( @@ -802,8 +800,8 @@ await RunTestsAsync( /// public async Task RunTestsAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler) { await RunTestsAsync( @@ -817,9 +815,9 @@ await RunTestsAsync( /// public async Task RunTestsAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var testCaseList = testCases.ToList(); @@ -841,7 +839,7 @@ await _requestSender.StartTestRunAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -856,8 +854,8 @@ await RunTestsWithCustomTestHostAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -873,9 +871,9 @@ await RunTestsWithCustomTestHostAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable sources, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -899,7 +897,7 @@ await _requestSender.StartTestRunWithCustomHostAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, + string? runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -914,8 +912,8 @@ await RunTestsWithCustomTestHostAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, + string? runSettings, + TestPlatformOptions? options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -931,9 +929,9 @@ await RunTestsWithCustomTestHostAsync( /// public async Task RunTestsWithCustomTestHostAsync( IEnumerable testCases, - string runSettings, - TestPlatformOptions options, - TestSessionInfo testSessionInfo, + string? runSettings, + TestPlatformOptions? options, + TestSessionInfo? testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { @@ -957,8 +955,8 @@ await _requestSender.StartTestRunWithCustomHostAsync( /// public async Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - IEnumerable invokedDataCollectors, - string processingSettings, + IEnumerable? invokedDataCollectors, + string? processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, @@ -979,7 +977,7 @@ await _requestSender.ProcessTestRunAttachmentsAsync( /// public Task ProcessTestRunAttachmentsAsync( IEnumerable attachments, - string processingSettings, + string? processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs index cac61c83d7..e0657ff25b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs @@ -85,12 +85,12 @@ public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo) Setup(); // Xunit >= 2.2 won't support net451, Minimum target framework it supports is net452. - string testAssemblyPath = _testEnvironment.TargetFramework.Equals("net451") + string testAssemblyPath = _testEnvironment.TargetFramework!.Equals("net451") ? _testEnvironment.GetTestAsset("XUTestProject.dll", "net46") : _testEnvironment.GetTestAsset("XUTestProject.dll"); var sources = new List { testAssemblyPath }; var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.XUnit), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.First() }); _vstestConsoleWrapper.RunTests( sources, @@ -133,7 +133,7 @@ public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo) var jsInTemp = TempDirectory.CopyFile(jsSource); var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.Chutzpah), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.First() }); _vstestConsoleWrapper.RunTests( new[] { jsInTemp }, diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs index f5c2c04ae4..426ce341cf 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs @@ -52,7 +52,7 @@ public void RunTestsWithTestAdapterPath(RunnerInfo runnerInfo) Setup(); var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.First() }); _vstestConsoleWrapper.RunTests( GetTestAssemblies(), diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs index 141ec72976..77aae696bf 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs @@ -85,7 +85,7 @@ public void GetDotnetPathByArchitecture_EnvVars(PlatformArchitecture targetArchi _environmentHelper.SetupGet(x => x.OperatingSystem).Returns(platformSystem); _environmentVariableHelper.Setup(x => x.GetEnvironmentVariable(envVar)).Returns(Path.GetDirectoryName(envVars[envVar])!); _environmentVariableHelper.Setup(x => x.GetEnvironmentVariable("ProgramFiles")).Returns("notfound"); - _fileHelper.Setup(x => x.DirectoryExists(Path.GetDirectoryName(envVars[envVar]))).Returns(true); + _fileHelper.Setup(x => x.DirectoryExists(Path.GetDirectoryName(envVars[envVar])!)).Returns(true); _fileHelper.Setup(x => x.Exists(envVars[envVar])).Returns(true); if (found) { @@ -120,7 +120,7 @@ public void GetDotnetPathByArchitecture_EnvVars_DirectoryNotExists_TryNext(strin _environmentHelper.SetupGet(x => x.OperatingSystem).Returns(PlatformOperatingSystem.Windows); _environmentVariableHelper.Setup(x => x.GetEnvironmentVariable(notExists)).Returns(Path.GetDirectoryName(envVars[notExists])!); _environmentVariableHelper.Setup(x => x.GetEnvironmentVariable(nextEnv)).Returns(Path.GetDirectoryName(envVars[nextEnv])!); - _fileHelper.Setup(x => x.DirectoryExists(Path.GetDirectoryName(envVars[nextEnv]))).Returns(true); + _fileHelper.Setup(x => x.DirectoryExists(Path.GetDirectoryName(envVars[nextEnv])!)).Returns(true); _fileHelper.Setup(x => x.Exists(envVars[nextEnv])).Returns(true); _fileHelper.Setup(x => x.GetStream(envVars[nextEnv], FileMode.Open, FileAccess.Read)).Returns(File.OpenRead(envVars[nextEnv])); diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 4ebe8bc18b..d3d5d5d0c1 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -15,6 +15,7 @@ using Microsoft.TestPlatform.VsTestConsole.TranslationLayer; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; +using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index ed4fc46801..9980c90951 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -7,6 +7,7 @@ using System.IO; using System.Xml; +using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.TestPlatform.TestUtilities; diff --git a/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj b/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj index 9ae3c0949a..d6660c7850 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj +++ b/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj @@ -43,21 +43,8 @@ - - - NullableHelpers.cs - TextTemplatingFileGenerator - - - - - True - True - NullableHelpers.tt - - \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.cs b/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.cs deleted file mode 100644 index 79cb7190bb..0000000000 --- a/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// -// This code is auto-generated. Changes to this file will be lost! -// This T4 file is copied in various projects because inclusion as link or through shared project -// doesn't allow to generate the C# file locally. If some modification is required, please update -// all instances. -// - -#nullable enable - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.TestPlatform.TestUtilities; - -internal static class StringUtils -{ - /// - [SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] - public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this string? value) - => string.IsNullOrEmpty(value); - - /// - [SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] - public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] this string? value) - => string.IsNullOrWhiteSpace(value); -} - -[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] -internal static class TPDebug -{ - /// - [Conditional("DEBUG")] - public static void Assert([DoesNotReturnIf(false)] bool b) - => Debug.Assert(b); - - /// - [Conditional("DEBUG")] - public static void Assert([DoesNotReturnIf(false)] bool b, string message) - => Debug.Assert(b, message); -} diff --git a/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.tt b/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.tt deleted file mode 100644 index 7e3d8e7270..0000000000 --- a/test/Microsoft.TestPlatform.TestUtilities/NullableHelpers.tt +++ /dev/null @@ -1,45 +0,0 @@ -<#@ template debug="true" hostspecific="true" language="C#" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// -// This code is auto-generated. Changes to this file will be lost! -// This T4 file is copied in various projects because inclusion as link or through shared project -// doesn't allow to generate the C# file locally. If some modification is required, please update -// all instances. -// - -#nullable enable - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace <#= System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint") #>; - -internal static class StringUtils -{ - /// - [SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] - public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this string? value) - => string.IsNullOrEmpty(value); - - /// - [SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] - public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] this string? value) - => string.IsNullOrWhiteSpace(value); -} - -[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")] -internal static class TPDebug -{ - /// - [Conditional("DEBUG")] - public static void Assert([DoesNotReturnIf(false)] bool b) - => Debug.Assert(b); - - /// - [Conditional("DEBUG")] - public static void Assert([DoesNotReturnIf(false)] bool b, string message) - => Debug.Assert(b, message); -} diff --git a/test/TranslationLayer.UnitTests/DiscoveryEventsHandleConverterTests.cs b/test/TranslationLayer.UnitTests/DiscoveryEventsHandleConverterTests.cs index 423e2994fd..78301f4901 100644 --- a/test/TranslationLayer.UnitTests/DiscoveryEventsHandleConverterTests.cs +++ b/test/TranslationLayer.UnitTests/DiscoveryEventsHandleConverterTests.cs @@ -24,7 +24,7 @@ public DiscoveryEventsHandleConverterTests() [TestMethod] public void ConstructorShouldThrowArgumentExceptionIfTestDiscoveryEventHandlerIsNull() { - Assert.ThrowsException(() => new DiscoveryEventsHandleConverter(null)); + Assert.ThrowsException(() => new DiscoveryEventsHandleConverter(null!)); } [TestMethod] diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 925b9de123..27cb906d03 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -101,13 +101,13 @@ public async Task StartTestSessionAsyncShouldCallRequestSenderWithCorrectArgumen null, mockEventsHandler.Object, null)) - .Returns(Task.FromResult(testSessionInfo)); + .Returns(Task.FromResult(testSessionInfo)); Assert.AreEqual( (await _consoleWrapper.StartTestSessionAsync( _testSources, null, - mockEventsHandler.Object).ConfigureAwait(false)).TestSessionInfo, + mockEventsHandler.Object).ConfigureAwait(false))?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( @@ -135,14 +135,14 @@ public async Task StartTestSessionAsyncShouldCallRequestSenderWithCorrectArgumen testPlatformOptions, mockEventsHandler.Object, null)) - .Returns(Task.FromResult(testSessionInfo)); + .Returns(Task.FromResult(testSessionInfo)); Assert.AreEqual( (await _consoleWrapper.StartTestSessionAsync( _testSources, null, testPlatformOptions, - mockEventsHandler.Object).ConfigureAwait(false)).TestSessionInfo, + mockEventsHandler.Object).ConfigureAwait(false))?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( @@ -171,7 +171,7 @@ public async Task StartTestSessionAsyncShouldCallRequestSenderWithCorrectArgumen testPlatformOptions, mockEventsHandler.Object, mockTesthostLauncher.Object)) - .Returns(Task.FromResult(testSessionInfo)); + .Returns(Task.FromResult(testSessionInfo)); Assert.AreEqual( (await _consoleWrapper.StartTestSessionAsync( @@ -179,7 +179,7 @@ public async Task StartTestSessionAsyncShouldCallRequestSenderWithCorrectArgumen null, testPlatformOptions, mockEventsHandler.Object, - mockTesthostLauncher.Object).ConfigureAwait(false)).TestSessionInfo, + mockTesthostLauncher.Object).ConfigureAwait(false))?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index fe3c21ac6c..f6301485e4 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -109,7 +109,7 @@ public void StartTestSessionShouldCallRequestSenderWithCorrectArguments1() _consoleWrapper.StartTestSession( _testSources, null, - mockEventsHandler.Object).TestSessionInfo, + mockEventsHandler.Object)?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( @@ -144,7 +144,7 @@ public void StartTestSessionShouldCallRequestSenderWithCorrectArguments2() _testSources, null, testPlatformOptions, - mockEventsHandler.Object).TestSessionInfo, + mockEventsHandler.Object)?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( @@ -181,7 +181,7 @@ public void StartTestSessionShouldCallRequestSenderWithCorrectArguments3() null, testPlatformOptions, mockEventsHandler.Object, - mockTesthostLauncher.Object).TestSessionInfo, + mockTesthostLauncher.Object)?.TestSessionInfo, testSessionInfo); _mockRequestSender.Verify( diff --git a/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs b/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs index 62ec8daa99..5629c248ab 100644 --- a/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs +++ b/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs @@ -45,7 +45,7 @@ public bool DirectoryExists(string? path) { TPDebug.Assert(path is not null, "path is null"); // TODO: Check if any file has the directory in name. This will improve. - var directoryExists = Files.Select(f => Path.GetDirectoryName(f.Path)).Any(p => p != null && p.StartsWith(path)); + var directoryExists = Files.Select(f => Path.GetDirectoryName(f.Path)).Any(p => p != null && p.StartsWith(path!)); return directoryExists; } diff --git a/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs index f17ce830f4..3bafe85f41 100644 --- a/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs @@ -85,7 +85,7 @@ public void EnableDiagArgumentProcessorExecutorThrowsIfDiagArgumentIsNullOrEmpty [TestMethod] public void EnableDiagArgumentProcessorExecutorDoesNotThrowsIfFileDotOpenThrow() { - _mockFileHelper.Setup(fh => fh.DirectoryExists(Path.GetDirectoryName(_dummyFilePath))).Returns(true); + _mockFileHelper.Setup(fh => fh.DirectoryExists(Path.GetDirectoryName(_dummyFilePath)!)).Returns(true); _diagProcessor.Executor!.Value.Initialize(_dummyFilePath); } @@ -152,7 +152,7 @@ public void EnableDiagArgumentProcessorExecutorShouldInitializeTraceWithCorrectT [TestMethod] public void EnableDiagArgumentProcessorExecutorShouldCreateDirectoryOfLogFileIfNotExists() { - _mockFileHelper.Setup(fh => fh.DirectoryExists(Path.GetDirectoryName(_dummyFilePath))).Returns(false); + _mockFileHelper.Setup(fh => fh.DirectoryExists(Path.GetDirectoryName(_dummyFilePath)!)).Returns(false); _diagProcessor.Executor!.Value.Initialize(_dummyFilePath);