diff --git a/.editorconfig b/.editorconfig index 748af0581a..2afa770532 100644 --- a/.editorconfig +++ b/.editorconfig @@ -192,6 +192,10 @@ dotnet_diagnostic.CA1806.severity = warning # not default, increased severity to # CA1834: Consider using 'StringBuilder.Append(char)' when applicable dotnet_diagnostic.CA1834.severity = warning # not default, increased severity to ensure it is always applied +# IDE0190: Null check can be simplified +# Keep this in sync with the related C# rule: csharp_style_prefer_parameter_null_checking +dotnet_diagnostic.IDE0190.severity = warning # not default, increased severity to ensure it is applied + #### C# Coding Conventions #### # var preferences @@ -248,10 +252,14 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sil # Keep this in sync with the related .NET rule: IDE0065 csharp_using_directive_placement = inside_namespace:warning +# IDE0190: Null check can be simplified +# Keep this in sync with the related .NET rule: IDE0190 +csharp_style_prefer_parameter_null_checking = true # not default, increased severity to ensure it is applied + #### .NET Formatting Rules #### # IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = warning +dotnet_diagnostic.IDE0055.severity = suggestion # Downgraded to suggestion due to https://github.com/dotnet/roslyn/issues/59414 #### C# Formatting Rules #### diff --git a/global.json b/global.json index 17843464a9..d10f045e24 100644 --- a/global.json +++ b/global.json @@ -1,12 +1,12 @@ { "sdk": { - "version": "6.0.100", + "version": "6.0.300-preview.22110.5", "rollForward": "minor", "allowPrerelease": false, "architecture": "x64" }, "tools": { - "dotnet": "6.0.100" + "dotnet": "6.0.300-preview.22110.5" }, "msbuild-sdks": { "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22103.1", diff --git a/scripts/build.sh b/scripts/build.sh index 40f6c644b4..d6e2e6bf73 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -199,7 +199,7 @@ function install_cli() # Skip download of dotnet toolset if REPO API is enabled local failed=false local install_script="$TP_TOOLS_DIR/dotnet-install.sh" - local remote_path="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh" + local remote_path="https://dot.net/v1/dotnet-install.sh" log "Installing dotnet cli..." local start=$SECONDS @@ -212,12 +212,12 @@ function install_cli() fi chmod u+x $install_script # Get netcoreapp1.1 shared components - $install_script --runtime dotnet --version "2.1.0" --channel "release/2.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 - $install_script --runtime dotnet --version "3.1.0" --channel "release/3.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 - $install_script --runtime dotnet --version "5.0.1" --channel "release/5.0.1" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 + $install_script --runtime dotnet --version "2.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 + $install_script --runtime dotnet --version "3.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 + $install_script --runtime dotnet --version "5.0.1" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 log "install_cli: Get the latest dotnet cli toolset..." - $install_script --install-dir "$TP_DOTNET_DIR" --no-path --channel "main" --version $DOTNET_CLI_VERSION + $install_script --install-dir "$TP_DOTNET_DIR" --no-path --version $DOTNET_CLI_VERSION log " ---- dotnet x64" diff --git a/scripts/common.lib.ps1 b/scripts/common.lib.ps1 index 62bb54ce7d..ab145c9af3 100644 --- a/scripts/common.lib.ps1 +++ b/scripts/common.lib.ps1 @@ -81,7 +81,7 @@ function Install-DotNetCli { $timer = Start-Timer Write-Log "Install-DotNetCli: Get dotnet-install.ps1 script..." - $dotnetInstallRemoteScript = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1" + $dotnetInstallRemoteScript = "https://dot.net/v1/dotnet-install.ps1" $dotnetInstallScript = Join-Path $env:TP_TOOLS_DIR "dotnet-install.ps1" if (-not (Test-Path $env:TP_TOOLS_DIR)) { New-Item $env:TP_TOOLS_DIR -Type Directory | Out-Null diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs index c85c40d3af..765093ffe0 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs @@ -84,13 +84,8 @@ public static void GetManagedName(MethodBase method, out string managedTypeName, /// More information about and can be found in /// the RFC. /// - public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName, out string[] hierarchyValues) + public static void GetManagedName(MethodBase method!!, out string managedTypeName, out string managedMethodName, out string[] hierarchyValues) { - if (method == null) - { - throw new ArgumentNullException(nameof(method)); - } - if (!ReflectionHelpers.IsMethod(method)) { throw new NotSupportedException(nameof(method)); diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index a5c16318a8..325218b656 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -353,13 +353,8 @@ public void Dispose() /// /// Invoked when test run is complete /// - public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection runContextAttachments, ICollection executorUris) + public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs!!, TestRunChangedEventArgs lastChunkArgs, ICollection runContextAttachments, ICollection executorUris) { - if (runCompleteArgs == null) - { - throw new ArgumentNullException(nameof(runCompleteArgs)); - } - bool isAborted = runCompleteArgs.IsAborted; bool isCanceled = runCompleteArgs.IsCanceled; diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 8efda7dc00..9d3115d4a8 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -84,13 +84,9 @@ protected TestPlatform( /// public IDiscoveryRequest CreateDiscoveryRequest( IRequestData requestData, - DiscoveryCriteria discoveryCriteria, + DiscoveryCriteria discoveryCriteria!!, TestPlatformOptions options) { - if (discoveryCriteria == null) - { - throw new ArgumentNullException(nameof(discoveryCriteria)); - } // Update cache with Extension folder's files. AddExtensionAssemblies(discoveryCriteria.RunSettings); @@ -120,14 +116,9 @@ public IDiscoveryRequest CreateDiscoveryRequest( /// public ITestRunRequest CreateTestRunRequest( IRequestData requestData, - TestRunCriteria testRunCriteria, + TestRunCriteria testRunCriteria!!, TestPlatformOptions options) { - if (testRunCriteria == null) - { - throw new ArgumentNullException(nameof(testRunCriteria)); - } - AddExtensionAssemblies(testRunCriteria.TestRunSettings); var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); @@ -162,14 +153,9 @@ public ITestRunRequest CreateTestRunRequest( /// public bool StartTestSession( IRequestData requestData, - StartTestSessionCriteria testSessionCriteria, + StartTestSessionCriteria testSessionCriteria!!, ITestSessionEventsHandler eventsHandler) { - if (testSessionCriteria == null) - { - throw new ArgumentNullException(nameof(testSessionCriteria)); - } - AddExtensionAssemblies(testSessionCriteria.RunSettings); var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testSessionCriteria.RunSettings); diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs index ad1563ba21..e6f581485e 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs @@ -57,13 +57,8 @@ public static Type GetTestExtensionType(string extensionTypeName) /// Return type of the test extension /// Data type of the extension to be instantiated /// Test extension instance - public static T CreateTestExtension(Type extensionType) + public static T CreateTestExtension(Type extensionType!!) { - if (extensionType == null) - { - throw new ArgumentNullException(nameof(extensionType)); - } - EqtTrace.Info("TestPluginManager.CreateTestExtension: Attempting to load test extension: " + extensionType); try diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/LazyExtension.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/LazyExtension.cs index 6095d3942e..5a5b1fd02e 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/LazyExtension.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/LazyExtension.cs @@ -32,13 +32,8 @@ public class LazyExtension /// /// Test extension Instance /// test extension metadata - public LazyExtension(TExtension instance, TMetadata metadata) + public LazyExtension(TExtension instance!!, TMetadata metadata) { - if (instance == null) - { - throw new ArgumentNullException(nameof(instance)); - } - if (metadata == null) { throw new ArgumentNullException(nameof(instance)); @@ -54,10 +49,10 @@ public LazyExtension(TExtension instance, TMetadata metadata) /// /// Test plugin to instantiated on demand. /// Metadata type to instantiate on demand - public LazyExtension(TestPluginInformation pluginInfo, Type metadataType) + public LazyExtension(TestPluginInformation pluginInfo!!, Type metadataType!!) { - TestPluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo)); - _metadataType = metadataType ?? throw new ArgumentNullException(nameof(metadataType)); + TestPluginInfo = pluginInfo; + _metadataType = metadataType; IsExtensionCreated = false; } @@ -66,14 +61,9 @@ public LazyExtension(TestPluginInformation pluginInfo, Type metadataType) /// /// Test plugin to instantiated on demand /// Test extension metadata - public LazyExtension(TestPluginInformation pluginInfo, TMetadata metadata) + public LazyExtension(TestPluginInformation pluginInfo!!, TMetadata metadata!!) { - if (metadata == null) - { - throw new ArgumentNullException(nameof(metadata)); - } - - TestPluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo)); + TestPluginInfo = pluginInfo; _metadata = metadata; IsExtensionCreated = false; } @@ -83,14 +73,9 @@ public LazyExtension(TestPluginInformation pluginInfo, TMetadata metadata) /// /// Test extension creator delegate /// test extension metadata - public LazyExtension(Func creator, TMetadata metadata) + public LazyExtension(Func creator!!, TMetadata metadata!!) { - if (metadata == null) - { - throw new ArgumentNullException(nameof(metadata)); - } - - _extensionCreator = creator ?? throw new ArgumentNullException(nameof(creator)); + _extensionCreator = creator; _metadata = metadata; IsExtensionCreated = false; } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IDataCollectorAttachmentsProcessorsFactory.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IDataCollectorAttachmentsProcessorsFactory.cs index 55f35b3bed..c1dd608aab 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IDataCollectorAttachmentsProcessorsFactory.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IDataCollectorAttachmentsProcessorsFactory.cs @@ -39,9 +39,9 @@ internal class DataCollectorAttachmentProcessor /// public IDataCollectorAttachmentProcessor DataCollectorAttachmentProcessorInstance { get; private set; } - public DataCollectorAttachmentProcessor(string friendlyName, IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessor) + public DataCollectorAttachmentProcessor(string friendlyName, IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessor!!) { FriendlyName = string.IsNullOrEmpty(friendlyName) ? throw new ArgumentException("Invalid FriendlyName", nameof(friendlyName)) : friendlyName; - DataCollectorAttachmentProcessorInstance = dataCollectorAttachmentProcessor ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentProcessor)); + DataCollectorAttachmentProcessorInstance = dataCollectorAttachmentProcessor; } } diff --git a/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs b/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs index 889a951584..5a494d2ad6 100644 --- a/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs +++ b/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs @@ -176,13 +176,8 @@ internal void EnableEvents() /// Raises a test run message event to the enabled loggers. /// /// Arguments to be raised. - internal void RaiseTestRunMessage(TestRunMessageEventArgs args) + internal void RaiseTestRunMessage(TestRunMessageEventArgs args!!) { - if (args == null) - { - throw new ArgumentNullException(nameof(args)); - } - CheckDisposed(); // Sending 0 size as this event is not expected to contain any data. diff --git a/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs b/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs index 6704e928ad..518d03888b 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs @@ -37,18 +37,8 @@ public static class FakesUtilities /// test sources /// runsettings /// updated runsettings for fakes - public static string GenerateFakesSettingsForRunConfiguration(string[] sources, string runSettingsXml) + public static string GenerateFakesSettingsForRunConfiguration(string[] sources!!, string runSettingsXml!!) { - if (sources == null) - { - throw new ArgumentNullException(nameof(sources)); - } - - if (runSettingsXml == null) - { - throw new ArgumentNullException(nameof(runSettingsXml)); - } - var doc = new XmlDocument(); using (var xmlReader = XmlReader.Create( new StringReader(runSettingsXml), diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs b/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs index 55bcac0cb7..5bcbc51cab 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs @@ -88,13 +88,8 @@ public static void Write(this IOutput output, string message, OutputLevel level, /// Format string for the message type. /// Format string for the error message. /// Arguments to format into the format string. - private static void Output(IOutput output, OutputLevel level, string messageTypeFormat, string format, params object[] args) + private static void Output(IOutput output!!, OutputLevel level, string messageTypeFormat, string format, params object[] args) { - if (output == null) - { - throw new ArgumentNullException(nameof(output)); - } - output.WriteLine(Format(messageTypeFormat, format, args), level); } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Utilities/JobQueue.cs b/src/Microsoft.TestPlatform.CoreUtilities/Utilities/JobQueue.cs index 8bf7dd4459..ace90a0e10 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Utilities/JobQueue.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Utilities/JobQueue.cs @@ -101,9 +101,9 @@ public class JobQueue : IDisposable /// The max Queue Size. /// The enable Bounds. /// The exception Logger. - public JobQueue(Action processJob, string displayName, int maxQueueLength, int maxQueueSize, bool enableBounds, Action exceptionLogger) + public JobQueue(Action processJob!!, string displayName, int maxQueueLength, int maxQueueSize, bool enableBounds, Action exceptionLogger) { - _processJob = processJob ?? throw new ArgumentNullException(nameof(processJob)); + _processJob = processJob; if (string.IsNullOrWhiteSpace(displayName)) { diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Utilities/MulticastDelegateUtilities.cs b/src/Microsoft.TestPlatform.CoreUtilities/Utilities/MulticastDelegateUtilities.cs index 58ac06ddc8..43063fa145 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Utilities/MulticastDelegateUtilities.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Utilities/MulticastDelegateUtilities.cs @@ -39,13 +39,8 @@ public static void SafeInvoke(this Delegate delegates, object sender, EventArgs /// Sender to use when raising the event. /// Arguments to provide. /// Name to use when tracing out errors. - public static void SafeInvoke(this Delegate delegates, object sender, object args, string traceDisplayName) + public static void SafeInvoke(this Delegate delegates, object sender, object args!!, string traceDisplayName) { - if (args == null) - { - throw new ArgumentNullException(nameof(args)); - } - if (string.IsNullOrWhiteSpace(traceDisplayName)) { throw new ArgumentNullException(nameof(traceDisplayName)); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs index 18548977ab..72bf6a3294 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs @@ -37,10 +37,10 @@ internal class TestRunAttachmentsProcessingManager : ITestRunAttachmentsProcessi /// /// Initializes a new instance of the class. /// - public TestRunAttachmentsProcessingManager(ITestPlatformEventSource testPlatformEventSource, IDataCollectorAttachmentsProcessorsFactory dataCollectorAttachmentsProcessorsFactory) + public TestRunAttachmentsProcessingManager(ITestPlatformEventSource testPlatformEventSource!!, IDataCollectorAttachmentsProcessorsFactory dataCollectorAttachmentsProcessorsFactory!!) { - _testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); - _dataCollectorAttachmentsProcessorsFactory = dataCollectorAttachmentsProcessorsFactory ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsProcessorsFactory)); + _testPlatformEventSource = testPlatformEventSource; + _dataCollectorAttachmentsProcessorsFactory = dataCollectorAttachmentsProcessorsFactory; } /// @@ -209,9 +209,9 @@ private class AttachmentsProcessingMessageLogger : IMessageLogger { private readonly ITestRunAttachmentsProcessingEventsHandler _eventsHandler; - public AttachmentsProcessingMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler) + public AttachmentsProcessingMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler!!) { - _eventsHandler = eventsHandler ?? throw new ArgumentNullException(nameof(eventsHandler)); + _eventsHandler = eventsHandler; } public void SendMessage(TestMessageLevel testMessageLevel, string message) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs index 71261c64ff..9709f2a9da 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs @@ -33,9 +33,9 @@ internal class ParallelRunDataAggregator #endregion - public ParallelRunDataAggregator(string runSettingsXml) + public ParallelRunDataAggregator(string runSettingsXml!!) { - RunSettings = runSettingsXml ?? throw new ArgumentNullException(nameof(runSettingsXml)); + RunSettings = runSettingsXml; ElapsedTime = TimeSpan.Zero; RunContextAttachments = new Collection(); RunCompleteArgsAttachments = new List(); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestHostManagerFactory.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestHostManagerFactory.cs index d49bf6ae41..17075119a0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestHostManagerFactory.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestHostManagerFactory.cs @@ -28,9 +28,9 @@ public class TestHostManagerFactory : ITestHostManagerFactory /// /// Provide common services and data for a discovery/run request. /// - public TestHostManagerFactory(IRequestData requestData) + public TestHostManagerFactory(IRequestData requestData!!) { - _requestData = requestData ?? throw new System.ArgumentNullException(nameof(requestData)); + _requestData = requestData; } /// diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs index ea85a37815..2703b9282f 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs @@ -76,13 +76,8 @@ protected BlameLogger(IOutput output, IBlameReaderWriter blameReaderWriter) /// /// Events that can be registered for. /// Test Run Directory - public void Initialize(TestLoggerEvents events, string testRunDictionary) + public void Initialize(TestLoggerEvents events!!, string testRunDictionary) { - if (events == null) - { - throw new ArgumentNullException(nameof(events)); - } - events.TestRunComplete += TestRunCompleteHandler; } @@ -91,13 +86,8 @@ public void Initialize(TestLoggerEvents events, string testRunDictionary) /// /// Sender /// TestRunCompleteEventArgs - private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) + private void TestRunCompleteHandler(object sender!!, TestRunCompleteEventArgs e) { - if (sender == null) - { - throw new ArgumentNullException(nameof(sender)); - } - ValidateArg.NotNull(sender, nameof(sender)); ValidateArg.NotNull(e, nameof(e)); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/CrashDumperFactory.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/CrashDumperFactory.cs index 2e1f7a4f13..903ace668d 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/CrashDumperFactory.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/CrashDumperFactory.cs @@ -15,13 +15,8 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector; internal class CrashDumperFactory : ICrashDumperFactory { - public ICrashDumper Create(string targetFramework) + public ICrashDumper Create(string targetFramework!!) { - if (targetFramework is null) - { - throw new ArgumentNullException(nameof(targetFramework)); - } - EqtTrace.Info($"CrashDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}."); var tfm = NuGetFramework.Parse(targetFramework); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/HangDumperFactory.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/HangDumperFactory.cs index 7b89d5c745..234d4e6bc6 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/HangDumperFactory.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/HangDumperFactory.cs @@ -16,13 +16,8 @@ internal class HangDumperFactory : IHangDumperFactory { public Action LogWarning { get; set; } - public IHangDumper Create(string targetFramework) + public IHangDumper Create(string targetFramework!!) { - if (targetFramework is null) - { - throw new ArgumentNullException(nameof(targetFramework)); - } - EqtTrace.Info($"HangDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}."); var procdumpOverride = Environment.GetEnvironmentVariable("VSTEST_DUMP_FORCEPROCDUMP")?.Trim(); var netdumpOverride = Environment.GetEnvironmentVariable("VSTEST_DUMP_FORCENETDUMP")?.Trim(); diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs index 9b70adeb91..263ba80638 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs @@ -103,13 +103,8 @@ public HtmlLogger(IFileHelper fileHelper, IHtmlTransformer htmlTransformer, public string HtmlFilePath { get; private set; } /// - public void Initialize(TestLoggerEvents events, string testResultsDirPath) + public void Initialize(TestLoggerEvents events!!, string testResultsDirPath) { - if (events == null) - { - throw new ArgumentNullException(nameof(events)); - } - if (string.IsNullOrEmpty(testResultsDirPath)) { throw new ArgumentNullException(nameof(testResultsDirPath)); @@ -130,13 +125,8 @@ public void Initialize(TestLoggerEvents events, string testResultsDirPath) } /// - public void Initialize(TestLoggerEvents events, Dictionary parameters) + public void Initialize(TestLoggerEvents events, Dictionary parameters!!) { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - if (parameters.Count == 0) { throw new ArgumentException("No default parameters added", nameof(parameters)); diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/CollectorDataEntry.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/CollectorDataEntry.cs index b42853569d..f142ff2e58 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/CollectorDataEntry.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/CollectorDataEntry.cs @@ -184,13 +184,8 @@ public void Save(XmlElement element, XmlTestStoreParameters parameters) /// Adds a data attachment to the list of data attachments /// /// The attachment to add - internal void AddAttachment(IDataAttachment attachment) + internal void AddAttachment(IDataAttachment attachment!!) { - if (attachment == null) - { - throw new ArgumentNullException(nameof(attachment)); - } - _attachments.Add(attachment); } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs index 69268a9a4e..c66158f510 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs @@ -103,13 +103,8 @@ internal TrxLogger(IFileHelper fileHelper, TrxFileHelper trxFileHelper) #region ITestLogger /// - public void Initialize(TestLoggerEvents events, string testResultsDirPath) + public void Initialize(TestLoggerEvents events!!, string testResultsDirPath) { - if (events == null) - { - throw new ArgumentNullException(nameof(events)); - } - if (string.IsNullOrEmpty(testResultsDirPath)) { throw new ArgumentNullException(nameof(testResultsDirPath)); @@ -125,13 +120,8 @@ public void Initialize(TestLoggerEvents events, string testResultsDirPath) } /// - public void Initialize(TestLoggerEvents events, Dictionary parameters) + public void Initialize(TestLoggerEvents events, Dictionary parameters!!) { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - if (parameters.Count == 0) { throw new ArgumentException("No default parameters added", nameof(parameters)); diff --git a/src/Microsoft.TestPlatform.ObjectModel/Adapter/TestPlatformFormatException.cs b/src/Microsoft.TestPlatform.ObjectModel/Adapter/TestPlatformFormatException.cs index 3597cbc796..5cd5f0a529 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Adapter/TestPlatformFormatException.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Adapter/TestPlatformFormatException.cs @@ -89,13 +89,8 @@ public string FilterValue /// /// Serialization info to add to /// not used - public override void GetObjectData(SerializationInfo info, StreamingContext context) + public override void GetObjectData(SerializationInfo info!!, StreamingContext context) { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - base.GetObjectData(info, context); info.AddValue("FilterValue", FilterValue); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/InvokedDataCollector.cs b/src/Microsoft.TestPlatform.ObjectModel/InvokedDataCollector.cs index 65c070264d..b18c6618f5 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/InvokedDataCollector.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/InvokedDataCollector.cs @@ -17,12 +17,12 @@ public sealed class InvokedDataCollector : IEquatable /// Data collector assembly qualified name /// Data collector file path /// True if data collector registers an attachment processor - public InvokedDataCollector(Uri uri, string friendlyName, string assemblyQualifiedName, string filePath, bool hasAttachmentProcessor) + public InvokedDataCollector(Uri uri!!, string friendlyName!!, string assemblyQualifiedName!!, string filePath!!, bool hasAttachmentProcessor) { - Uri = uri ?? throw new ArgumentNullException(nameof(uri)); - FriendlyName = friendlyName ?? throw new ArgumentNullException(nameof(friendlyName)); - AssemblyQualifiedName = assemblyQualifiedName ?? throw new ArgumentNullException(nameof(assemblyQualifiedName)); ; - FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); ; + Uri = uri; + FriendlyName = friendlyName; + AssemblyQualifiedName = assemblyQualifiedName; ; + FilePath = filePath; ; HasAttachmentProcessor = hasAttachmentProcessor; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestResultEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestResultEventArgs.cs index caa1d4992d..f5598003c4 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestResultEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestResultEventArgs.cs @@ -20,9 +20,9 @@ public class TestResultEventArgs : EventArgs /// /// Test Result for the event. /// - public TestResultEventArgs(TestResult result) + public TestResultEventArgs(TestResult result!!) { - Result = result ?? throw new ArgumentNullException(nameof(result)); + Result = result; } #endregion diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs b/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs index ef59ae83b6..8de2ae8510 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs @@ -25,9 +25,9 @@ public sealed class TestResult : TestObject /// Initializes a new instance of the class. /// /// The test case the result is for. - public TestResult(TestCase testCase) + public TestResult(TestCase testCase!!) { - TestCase = testCase ?? throw new ArgumentNullException(nameof(testCase)); + TestCase = testCase; Messages = new Collection(); Attachments = new Collection(); diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/FilterHelper.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/FilterHelper.cs index aea2e0f04a..823f0b494b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/FilterHelper.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/FilterHelper.cs @@ -23,13 +23,8 @@ public static class FilterHelper /// /// The input string that contains the text to convert. /// A string of characters with special characters converted to their escaped form. - public static string Escape(string str) + public static string Escape(string str!!) { - if (str == null) - { - throw new ArgumentNullException(nameof(str)); - } - if (str.IndexOfAny(SpecialCharacters) < 0) { return str; @@ -54,13 +49,8 @@ public static string Escape(string str) /// /// The input string that contains the text to convert. /// A filter string of characters with any escaped characters converted to their un-escaped form. - public static string Unescape(string str) + public static string Unescape(string str!!) { - if (str == null) - { - throw new ArgumentNullException(nameof(str)); - } - if (str.IndexOf(EscapeCharacter) < 0) { return str; diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs index b32f79b5da..d1a6dc9260 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs @@ -63,18 +63,8 @@ public static XmlReaderSettings ReaderSettings /// XPathNavigable representation of a runsettings file /// The data Collector Uri. /// True if there is a datacollector configured. - public static bool ContainsDataCollector(IXPathNavigable runSettingDocument, string dataCollectorUri) + public static bool ContainsDataCollector(IXPathNavigable runSettingDocument!!, string dataCollectorUri!!) { - if (runSettingDocument == null) - { - throw new ArgumentNullException(nameof(runSettingDocument)); - } - - if (dataCollectorUri == null) - { - throw new ArgumentNullException(nameof(dataCollectorUri)); - } - var navigator = runSettingDocument.CreateNavigator(); var nodes = navigator.Select("/RunSettings/DataCollectionRunSettings/DataCollectors/DataCollector"); @@ -123,18 +113,8 @@ public static IList GetDataCollectorsFriendlyName(string runsettingsXml) /// /// runSettingDocument /// settings - public static void InsertDataCollectorsNode(IXPathNavigable runSettingDocument, DataCollectorSettings settings) + public static void InsertDataCollectorsNode(IXPathNavigable runSettingDocument!!, DataCollectorSettings settings!!) { - if (runSettingDocument == null) - { - throw new ArgumentNullException(nameof(runSettingDocument)); - } - - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - var navigator = runSettingDocument.CreateNavigator(); MoveToDataCollectorsNode(ref navigator); diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/RollingFileTraceListener.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/RollingFileTraceListener.cs index 0cbf9a2db9..81c0d6a96f 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/RollingFileTraceListener.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/RollingFileTraceListener.cs @@ -316,14 +316,9 @@ internal sealed class TallyKeepingFileStreamWriter : StreamWriter /// /// The to write to. /// - public TallyKeepingFileStreamWriter(FileStream stream) + public TallyKeepingFileStreamWriter(FileStream stream!!) : base(stream) { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } - Tally = stream.Length; } @@ -336,19 +331,9 @@ public TallyKeepingFileStreamWriter(FileStream stream) /// /// The to use. /// - public TallyKeepingFileStreamWriter(FileStream stream, Encoding encoding) + public TallyKeepingFileStreamWriter(FileStream stream!!, Encoding encoding!!) : base(stream, encoding) { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } - - if (encoding == null) - { - throw new ArgumentNullException(nameof(encoding)); - } - Tally = stream.Length; } diff --git a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs index b3f3552787..de15c31785 100644 --- a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs @@ -23,13 +23,8 @@ public static class ClientUtilities /// /// Xml Document containing Runsettings xml /// Path of the .runsettings xml file - public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument, string path) + public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument!!, string path) { - if (xmlDocument == null) - { - throw new ArgumentNullException(nameof(xmlDocument)); - } - if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs index fe2f719a35..baab144d25 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/DiscoveryEventsHandleConverter.cs @@ -5,7 +5,6 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer; -using System; using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -25,9 +24,9 @@ public class DiscoveryEventsHandleConverter : ITestDiscoveryEventsHandler2 /// Converts the ITestDiscoveryEventsHandler to ITestDiscoveryEventsHandler2 /// /// - public DiscoveryEventsHandleConverter(ITestDiscoveryEventsHandler testDiscoveryEventsHandler) + public DiscoveryEventsHandleConverter(ITestDiscoveryEventsHandler testDiscoveryEventsHandler!!) { - _testDiscoveryEventsHandler = testDiscoveryEventsHandler ?? throw new ArgumentNullException(nameof(testDiscoveryEventsHandler)); + _testDiscoveryEventsHandler = testDiscoveryEventsHandler; } /// diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 672f26b6ba..4f30b3881f 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -179,13 +179,8 @@ protected static IOutput Output /// /// Events that can be registered for. /// Test Run Directory - public void Initialize(TestLoggerEvents events, string testRunDirectory) + public void Initialize(TestLoggerEvents events!!, string testRunDirectory) { - if (events == null) - { - throw new ArgumentNullException(nameof(events)); - } - if (Output == null) { Output = ConsoleOutput.Instance; @@ -211,13 +206,8 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) // events.DiscoveredTests += DiscoveredTestsHandler; } - public void Initialize(TestLoggerEvents events, Dictionary parameters) + public void Initialize(TestLoggerEvents events, Dictionary parameters!!) { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - if (parameters.Count == 0) { throw new ArgumentException("No default parameters added", nameof(parameters)); diff --git a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs index ee66c21af1..b4a6496bf9 100644 --- a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs @@ -311,18 +311,8 @@ private static string GetMissingNodesTextIfAny(string existingPath, string fullp /// XPathNavigable representation of a runsettings file /// The data Collector friendly name. /// True if there is a datacollector configured. - private static bool ContainsDataCollectorWithFriendlyName(IXPathNavigable runSettingDocument, string dataCollectorFriendlyName) + private static bool ContainsDataCollectorWithFriendlyName(IXPathNavigable runSettingDocument!!, string dataCollectorFriendlyName!!) { - if (runSettingDocument == null) - { - throw new ArgumentNullException(nameof(runSettingDocument)); - } - - if (dataCollectorFriendlyName == null) - { - throw new ArgumentNullException(nameof(dataCollectorFriendlyName)); - } - var navigator = runSettingDocument.CreateNavigator(); var nodes = navigator.Select("/RunSettings/DataCollectionRunSettings/DataCollectors/DataCollector");