Skip to content

Commit 55a7b50

Browse files
authored
use some null coalescing (#5062)
1 parent 196d737 commit 55a7b50

6 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private bool TryGetMessage(string singleLine, out string name, out string?[] dat
224224
{
225225
var parts = singleLine.Split(_messageSplitterArray, StringSplitOptions.None);
226226
name = parts[1];
227-
data = parts.Skip(2).Take(parts.Length).Select(p => p == null ? null : p.Replace("~~~~", "\r").Replace("!!!!", "\n")).ToArray();
227+
data = parts.Skip(2).Take(parts.Length).Select(p => p?.Replace("~~~~", "\r").Replace("!!!!", "\n")).ToArray();
228228
return true;
229229
}
230230

src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int ExecuteAsync()
121121
_executionStartTime = DateTime.UtcNow;
122122

123123
// Collecting Number of sources Sent For Execution
124-
var numberOfSources = (uint)(TestRunCriteria.Sources != null ? TestRunCriteria.Sources.Count() : 0);
124+
var numberOfSources = (uint)(TestRunCriteria.Sources?.Count() ?? 0);
125125
_requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfSourcesSentForRun, numberOfSources);
126126

127127
EqtTrace.Info("TestRunRequest.ExecuteAsync: Starting run with settings:{0}", TestRunCriteria);

src/Microsoft.TestPlatform.CrossPlatEngine/Utilities/TestSourcesUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal class TestSourcesUtility
4545
internal static string? GetDefaultCodebasePath(Dictionary<string, IEnumerable<string>?> adapterSourceMap)
4646
{
4747
var source = GetSources(adapterSourceMap)?.FirstOrDefault();
48-
return source != null ? Path.GetDirectoryName(source) : null;
48+
return Path.GetDirectoryName(source);
4949
}
5050

5151
/// <summary>
@@ -56,6 +56,6 @@ internal class TestSourcesUtility
5656
internal static string? GetDefaultCodebasePath(IEnumerable<TestCase> tests)
5757
{
5858
var source = GetSources(tests)?.FirstOrDefault();
59-
return source != null ? Path.GetDirectoryName(source) : null;
59+
return Path.GetDirectoryName(source);
6060
}
6161
}

src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public override bool Equals(object? obj)
119119

120120
return other != null
121121
&& SessionId.Equals(other.SessionId)
122-
&& (TestExecId == null ? other.TestExecId == null : TestExecId.Equals(other.TestExecId));
122+
&& (TestExecId?.Equals(other.TestExecId) ?? other.TestExecId == null);
123123
}
124124

125125
public override int GetHashCode()

src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,7 @@ private void HandleCustomHostLaunch(ITestHostLauncher? customHostLauncher, Messa
14281428
{
14291429
var testProcessStartInfo = _dataSerializer.DeserializePayload<TestProcessStartInfo>(message);
14301430

1431-
ackPayload.HostProcessId = customHostLauncher != null
1432-
? customHostLauncher.LaunchTestHost(testProcessStartInfo!)
1433-
: -1;
1431+
ackPayload.HostProcessId = customHostLauncher?.LaunchTestHost(testProcessStartInfo!) ?? -1;
14341432
}
14351433
catch (Exception ex)
14361434
{

test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Extension/RunnnerInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override string ToString()
6060
$"Runner = {RunnerFramework}",
6161
$"TargetFramework = {TargetFramework}",
6262
string.IsNullOrEmpty(InIsolationValue) ? "InProcess" : "InIsolation",
63-
VSTestConsoleInfo == null ? null : VSTestConsoleInfo.ToString(),
63+
VSTestConsoleInfo?.ToString(),
6464
TestHostInfo == null ? null : string.Join(",", TestHostInfo),
6565
AdapterInfo == null ? null : string.Join(",", AdapterInfo)
6666
}.Where(s => s != null));

0 commit comments

Comments
 (0)