Skip to content

Commit

Permalink
use some null coalescing (#5062)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored May 23, 2024
1 parent 196d737 commit 55a7b50
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class TestSourcesUtility
internal static string? GetDefaultCodebasePath(Dictionary<string, IEnumerable<string>?> adapterSourceMap)
{
var source = GetSources(adapterSourceMap)?.FirstOrDefault();
return source != null ? Path.GetDirectoryName(source) : null;
return Path.GetDirectoryName(source);
}

/// <summary>
Expand All @@ -56,6 +56,6 @@ internal class TestSourcesUtility
internal static string? GetDefaultCodebasePath(IEnumerable<TestCase> tests)
{
var source = GetSources(tests)?.FirstOrDefault();
return source != null ? Path.GetDirectoryName(source) : null;
return Path.GetDirectoryName(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,7 @@ private void HandleCustomHostLaunch(ITestHostLauncher? customHostLauncher, Messa
{
var testProcessStartInfo = _dataSerializer.DeserializePayload<TestProcessStartInfo>(message);

ackPayload.HostProcessId = customHostLauncher != null
? customHostLauncher.LaunchTestHost(testProcessStartInfo!)
: -1;
ackPayload.HostProcessId = customHostLauncher?.LaunchTestHost(testProcessStartInfo!) ?? -1;
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 55a7b50

Please sign in to comment.