From ccf922f2d5fc1999e2cc4c7e73aebd2122691edd Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 24 Dec 2024 05:37:10 +1100 Subject: [PATCH] merge some conditional expressions (#4436) --- .../Tasks/DotnetMuxerLocator.cs | 2 +- .../CommandLine/CommandLineOptionsProxy.cs | 5 ++--- .../OutputDevice/TerminalOutputDevice.cs | 4 +--- .../AssemblyResolverTests.cs | 4 ++-- .../Services/MSTestAdapterSettingsTests.cs | 2 +- .../ServerMode/FormatterUtilitiesTests.cs | 4 +--- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/DotnetMuxerLocator.cs b/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/DotnetMuxerLocator.cs index 5f6d7e4bb0..11a28f280b 100644 --- a/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/DotnetMuxerLocator.cs +++ b/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/DotnetMuxerLocator.cs @@ -369,7 +369,7 @@ public bool TryGetDotnetPathByArchitecture( } } - return archType is null ? throw new InvalidOperationException("Invalid image") : archType; + return archType ?? throw new InvalidOperationException("Invalid image"); } // See https://opensource.apple.com/source/xnu/xnu-2050.18.24/EXTERNAL_HEADERS/mach-o/loader.h diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProxy.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProxy.cs index ee83a5664e..fd5d11df3d 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProxy.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProxy.cs @@ -8,9 +8,8 @@ internal sealed class CommandLineOptionsProxy : ICommandLineOptions private ICommandLineOptions? _commandLineOptions; public bool IsOptionSet(string optionName) - => _commandLineOptions is null - ? throw new InvalidOperationException(Resources.PlatformResources.CommandLineOptionsNotReady) - : _commandLineOptions.IsOptionSet(optionName); + => _commandLineOptions?.IsOptionSet(optionName) ?? + throw new InvalidOperationException(Resources.PlatformResources.CommandLineOptionsNotReady); public bool TryGetOptionArgumentList(string optionName, [NotNullWhen(true)] out string[]? arguments) => _commandLineOptions is null diff --git a/src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs b/src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs index a82729dc54..f5424d4ede 100644 --- a/src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs +++ b/src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs @@ -151,9 +151,7 @@ await _policiesService.RegisterOnAbortCallbackAsync( // func. : () => _isVSTestMode || _isListTests || _isServerMode ? false - : _testHostControllerInfo.IsCurrentProcessTestHostController == null - ? null - : !_testHostControllerInfo.IsCurrentProcessTestHostController; + : !_testHostControllerInfo.IsCurrentProcessTestHostController; // This is single exe run, don't show all the details of assemblies and their summaries. _terminalTestReporter = new TerminalTestReporter(_console, new() diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/AssemblyResolverTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/AssemblyResolverTests.cs index dea7166c83..d721d4c831 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/AssemblyResolverTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/AssemblyResolverTests.cs @@ -204,7 +204,7 @@ public TestableAssemblyResolver(IList directories) public Func, string, bool, Assembly> SearchAssemblySetter { get; internal set; } - protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter == null ? base.DoesDirectoryExist(path) : DoesDirectoryExistSetter(path); + protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter?.Invoke(path) ?? base.DoesDirectoryExist(path); protected override string[] GetDirectories(string path) => GetDirectoriesSetter == null ? base.GetDirectories(path) : GetDirectoriesSetter(path); @@ -212,7 +212,7 @@ protected override Assembly SearchAssembly(List searchDirectorypaths, st ? base.SearchAssembly(searchDirectorypaths, name, isReflectionOnly) : SearchAssemblySetter(searchDirectorypaths, name, isReflectionOnly); - protected override bool DoesFileExist(string filePath) => DoesFileExistSetter == null ? base.DoesFileExist(filePath) : DoesFileExistSetter(filePath); + protected override bool DoesFileExist(string filePath) => DoesFileExistSetter?.Invoke(filePath) ?? base.DoesFileExist(filePath); protected override Assembly LoadAssemblyFrom(string path) => LoadAssemblyFromSetter == null ? base.LoadAssemblyFrom(path) : LoadAssemblyFromSetter(path); diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/MSTestAdapterSettingsTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/MSTestAdapterSettingsTests.cs index d08d236425..b39f3966d3 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/MSTestAdapterSettingsTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/MSTestAdapterSettingsTests.cs @@ -383,7 +383,7 @@ public TestableMSTestAdapterSettings() public Func ExpandEnvironmentVariablesSetter { get; set; } - protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter == null ? base.DoesDirectoryExist(path) : DoesDirectoryExistSetter(path); + protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter?.Invoke(path) ?? base.DoesDirectoryExist(path); protected override string ExpandEnvironmentVariables(string path) => ExpandEnvironmentVariablesSetter == null ? base.ExpandEnvironmentVariables(path) : ExpandEnvironmentVariablesSetter(path); } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs index dc2fef3b58..1e99ae1ed8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs @@ -133,9 +133,7 @@ private static void CustomAssert(Type type, object instanceDeserialized, object } public static string? FormatSerializerTypes(MethodInfo methodInfo, object?[]? data) - => data is not null - ? (data[0] as Type)?.Name - : null; + => (data?[0] as Type)?.Name; private static void AssertSerialize(Type type, string instanceSerialized) {