diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs index e3f32359a1..47494d11a6 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs @@ -224,7 +224,7 @@ private bool TryGetMessage(string singleLine, out string name, out string?[] dat { var parts = singleLine.Split(_messageSplitterArray, StringSplitOptions.None); name = parts[1]; - data = parts.Skip(2).Take(parts.Length).Select(p => p == null ? null : p.Replace("~~~~", "\r").Replace("!!!!", "\n")).ToArray(); + data = parts.Skip(2).Take(parts.Length).Select(p => p?.Replace("~~~~", "\r").Replace("!!!!", "\n")).ToArray(); return true; } diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index 0f2f9d19ee..b7b65dc764 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -121,7 +121,7 @@ public int ExecuteAsync() _executionStartTime = DateTime.UtcNow; // Collecting Number of sources Sent For Execution - var numberOfSources = (uint)(TestRunCriteria.Sources != null ? TestRunCriteria.Sources.Count() : 0); + var numberOfSources = (uint)(TestRunCriteria.Sources?.Count() ?? 0); _requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfSourcesSentForRun, numberOfSources); EqtTrace.Info("TestRunRequest.ExecuteAsync: Starting run with settings:{0}", TestRunCriteria); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Utilities/TestSourcesUtility.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Utilities/TestSourcesUtility.cs index d33f25f262..f13e422514 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Utilities/TestSourcesUtility.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Utilities/TestSourcesUtility.cs @@ -45,7 +45,7 @@ internal class TestSourcesUtility internal static string? GetDefaultCodebasePath(Dictionary?> adapterSourceMap) { var source = GetSources(adapterSourceMap)?.FirstOrDefault(); - return source != null ? Path.GetDirectoryName(source) : null; + return Path.GetDirectoryName(source); } /// @@ -56,6 +56,6 @@ internal class TestSourcesUtility internal static string? GetDefaultCodebasePath(IEnumerable tests) { var source = GetSources(tests)?.FirstOrDefault(); - return source != null ? Path.GetDirectoryName(source) : null; + return Path.GetDirectoryName(source); } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectionContext.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectionContext.cs index 8357d18063..495fe298c8 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectionContext.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectionContext.cs @@ -119,7 +119,7 @@ public override bool Equals(object? obj) return other != null && SessionId.Equals(other.SessionId) - && (TestExecId == null ? other.TestExecId == null : TestExecId.Equals(other.TestExecId)); + && (TestExecId?.Equals(other.TestExecId) ?? other.TestExecId == null); } public override int GetHashCode() diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index e7aad2c655..e72355cd5b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -1428,9 +1428,7 @@ private void HandleCustomHostLaunch(ITestHostLauncher? customHostLauncher, Messa { var testProcessStartInfo = _dataSerializer.DeserializePayload(message); - ackPayload.HostProcessId = customHostLauncher != null - ? customHostLauncher.LaunchTestHost(testProcessStartInfo!) - : -1; + ackPayload.HostProcessId = customHostLauncher?.LaunchTestHost(testProcessStartInfo!) ?? -1; } catch (Exception ex) { diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Extension/RunnnerInfo.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Extension/RunnnerInfo.cs index a13fbf2274..b052591c78 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Extension/RunnnerInfo.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Extension/RunnnerInfo.cs @@ -60,7 +60,7 @@ public override string ToString() $"Runner = {RunnerFramework}", $"TargetFramework = {TargetFramework}", string.IsNullOrEmpty(InIsolationValue) ? "InProcess" : "InIsolation", - VSTestConsoleInfo == null ? null : VSTestConsoleInfo.ToString(), + VSTestConsoleInfo?.ToString(), TestHostInfo == null ? null : string.Join(",", TestHostInfo), AdapterInfo == null ? null : string.Join(",", AdapterInfo) }.Where(s => s != null));