diff --git a/src/AttachVS/AttachVS.csproj b/src/AttachVS/AttachVS.csproj
index 92f4b64cb8..69b747e2a9 100644
--- a/src/AttachVS/AttachVS.csproj
+++ b/src/AttachVS/AttachVS.csproj
@@ -15,5 +15,8 @@
+
+
+
diff --git a/src/AttachVS/AttachVs.cs b/src/AttachVS/AttachVs.cs
index 7b6c28aaa4..a24c96bef7 100644
--- a/src/AttachVS/AttachVs.cs
+++ b/src/AttachVS/AttachVs.cs
@@ -3,6 +3,7 @@
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -196,13 +197,13 @@ private static bool AttachVs(Process vs, int pid)
var parent = process;
while (!IsVsOrNull(parent))
{
- parent = GetParentProcess(parent!);
+ parent = GetParentProcess(parent);
}
return parent;
}
- private static bool IsVsOrNull(Process? process)
+ private static bool IsVsOrNull([NotNullWhen(false)] Process? process)
{
if (process == null)
{
diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs
index 4288b9beb5..e69b72c5d4 100644
--- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs
+++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs
@@ -496,7 +496,7 @@ private void ConfigureEventSources(CollectorNameValueConfigurationManager collec
string? eventSourcesStr = collectorNameValueConfigurationManager[EventLogConstants.SettingEventSources];
if (!eventSourcesStr.IsNullOrEmpty())
{
- EventSources = ParseCommaSeparatedList(eventSourcesStr!);
+ EventSources = ParseCommaSeparatedList(eventSourcesStr);
EqtTrace.Verbose(
$"EventLogDataCollector configuration: {EventLogConstants.SettingEventSources}={EventSources}");
}
diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
index c6a48b6bf0..381e714a32 100644
--- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
+++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
@@ -180,7 +180,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.StartTestSession:
{
var testSessionPayload = _communicationManager.DeserializePayload(message);
- TPDebug.Assert(testSessionPayload is not null, "testSessionPayload is null");
StartTestSession(testSessionPayload, testRequestManager);
break;
}
@@ -188,7 +187,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.StopTestSession:
{
var testSessionPayload = _communicationManager.DeserializePayload(message);
- TPDebug.Assert(testSessionPayload is not null, "testSessionPayload is null");
StopTestSession(testSessionPayload, testRequestManager);
break;
}
@@ -196,7 +194,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.StartDiscovery:
{
var discoveryPayload = _dataSerializer.DeserializePayload(message);
- TPDebug.Assert(discoveryPayload is not null, "discoveryPayload is null");
StartDiscovery(discoveryPayload, testRequestManager);
break;
}
@@ -204,10 +201,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.GetTestRunnerProcessStartInfoForRunAll:
case MessageType.GetTestRunnerProcessStartInfoForRunSelected:
{
- var testRunPayload =
- _communicationManager.DeserializePayload(
- message);
- TPDebug.Assert(testRunPayload is not null, "testRunPayload is null");
+ var testRunPayload = _communicationManager.DeserializePayload(message);
StartTestRun(testRunPayload, testRequestManager, shouldLaunchTesthost: true);
break;
}
@@ -215,17 +209,14 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.TestRunAllSourcesWithDefaultHost:
case MessageType.TestRunSelectedTestCasesDefaultHost:
{
- var testRunPayload =
- _communicationManager.DeserializePayload(
- message);
+ var testRunPayload = _communicationManager.DeserializePayload(message);
StartTestRun(testRunPayload, testRequestManager, shouldLaunchTesthost: false);
break;
}
case MessageType.TestRunAttachmentsProcessingStart:
{
- var testRunAttachmentsProcessingPayload =
- _communicationManager.DeserializePayload(message);
+ var testRunAttachmentsProcessingPayload = _communicationManager.DeserializePayload(message);
StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager);
break;
}
@@ -462,6 +453,12 @@ private void StartTestRun(TestRunRequestPayload? testRunPayload, ITestRequestMan
{
testRequestManager.ResetOptions();
+ if (testRunPayload is null)
+ {
+ OnError(null);
+ return;
+ }
+
// We must avoid re-launching the test host if the test run payload already
// contains test session info. Test session info being present is an indicative
// of an already running test host spawned by a start test session call.
@@ -476,81 +473,105 @@ private void StartTestRun(TestRunRequestPayload? testRunPayload, ITestRequestMan
}
catch (Exception ex)
{
- EqtTrace.Error("DesignModeClient: Exception in StartTestRun: " + ex);
-
- var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
- _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
- var runCompletePayload = new TestRunCompletePayload()
- {
- TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, true, ex, null, null, TimeSpan.MinValue),
- LastRunTests = null
- };
-
- // Send run complete to translation layer
- _communicationManager.SendMessage(MessageType.ExecutionComplete, runCompletePayload);
+ OnError(ex);
}
});
+
+ void OnError(Exception? ex)
+ {
+ EqtTrace.Error("DesignModeClient.StartTestRun: " + ex ?? "payload was null");
+
+ var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex?.ToString() };
+ _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
+ var runCompletePayload = new TestRunCompletePayload()
+ {
+ TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, true, ex, null, null, TimeSpan.MinValue),
+ LastRunTests = null
+ };
+
+ // Send run complete to translation layer
+ _communicationManager.SendMessage(MessageType.ExecutionComplete, runCompletePayload);
+ }
}
- private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITestRequestManager testRequestManager)
+ private void StartDiscovery(DiscoveryRequestPayload? discoveryRequestPayload, ITestRequestManager testRequestManager)
{
- Task.Run(
- () =>
+ Task.Run(() =>
+ {
+ try
{
- try
+ testRequestManager.ResetOptions();
+ if (discoveryRequestPayload is null)
{
- testRequestManager.ResetOptions();
- testRequestManager.DiscoverTests(discoveryRequestPayload, new DesignModeTestEventsRegistrar(this), _protocolConfig);
+ OnError(null);
+ return;
}
- catch (Exception ex)
- {
- EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex);
- var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
- _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
+ testRequestManager.DiscoverTests(discoveryRequestPayload, new DesignModeTestEventsRegistrar(this), _protocolConfig);
+ }
+ catch (Exception ex)
+ {
+ OnError(ex);
+ }
+ });
+
+ void OnError(Exception? ex)
+ {
+ EqtTrace.Error("DesignModeClient.StartDiscovery: " + ex ?? "payload is null");
- var payload = new DiscoveryCompletePayload()
- {
- IsAborted = true,
- LastDiscoveredTests = null,
- TotalTests = -1
- };
+ var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex?.ToString() };
+ _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
- // Send run complete to translation layer
- _communicationManager.SendMessage(MessageType.DiscoveryComplete, payload);
- }
- });
+ var payload = new DiscoveryCompletePayload()
+ {
+ IsAborted = true,
+ LastDiscoveredTests = null,
+ TotalTests = -1
+ };
+
+ // Send run complete to translation layer
+ _communicationManager.SendMessage(MessageType.DiscoveryComplete, payload);
+ }
}
private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload? attachmentsProcessingPayload, ITestRequestManager testRequestManager)
{
- Task.Run(
- () =>
+ Task.Run(() =>
+ {
+ try
{
- try
+ if (attachmentsProcessingPayload is null)
{
- // TODO: Avoid throwing/catching NRE
- testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload!, new TestRunAttachmentsProcessingEventsHandler(_communicationManager), _protocolConfig);
+ OnError(null);
+ return;
}
- catch (Exception ex)
- {
- EqtTrace.Error("DesignModeClient: Exception in StartTestRunAttachmentsProcessing: " + ex);
- var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
- _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
+ testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload, new TestRunAttachmentsProcessingEventsHandler(_communicationManager), _protocolConfig);
+ }
+ catch (Exception ex)
+ {
+ OnError(ex);
+ }
+ });
+
+ void OnError(Exception? ex)
+ {
+ EqtTrace.Error("DesignModeClient.StartTestRunAttachmentsProcessing: " + ex ?? "payload is null");
- var payload = new TestRunAttachmentsProcessingCompletePayload()
- {
- Attachments = null
- };
+ var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex?.ToString() };
+ _communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
- // Send run complete to translation layer
- _communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload);
- }
- });
+ var payload = new TestRunAttachmentsProcessingCompletePayload()
+ {
+ Attachments = null
+ };
+
+ // Send run complete to translation layer
+ _communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload);
+ }
}
- private void StartTestSession(StartTestSessionPayload payload, ITestRequestManager requestManager)
+ private void StartTestSession(StartTestSessionPayload? payload, ITestRequestManager requestManager)
{
Task.Run(() =>
{
@@ -558,6 +579,12 @@ private void StartTestSession(StartTestSessionPayload payload, ITestRequestManag
try
{
+ if (payload is null)
+ {
+ OnError(eventsHandler, null);
+ return;
+ }
+
var customLauncher = payload.HasCustomHostLauncher
? DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(this, payload.IsDebuggingEnabled)
: null;
@@ -567,15 +594,20 @@ private void StartTestSession(StartTestSessionPayload payload, ITestRequestManag
}
catch (Exception ex)
{
- EqtTrace.Error("DesignModeClient: Exception in StartTestSession: " + ex);
-
- eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex.ToString());
- eventsHandler.HandleStartTestSessionComplete(new());
+ OnError(eventsHandler, ex);
}
});
+
+ static void OnError(TestSessionEventsHandler eventsHandler, Exception? ex)
+ {
+ EqtTrace.Error("DesignModeClient.StartTestSession: " + ex ?? "payload is null");
+
+ eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex?.ToString());
+ eventsHandler.HandleStartTestSessionComplete(new());
+ }
}
- private void StopTestSession(StopTestSessionPayload payload, ITestRequestManager requestManager)
+ private void StopTestSession(StopTestSessionPayload? payload, ITestRequestManager requestManager)
{
Task.Run(() =>
{
@@ -584,16 +616,27 @@ private void StopTestSession(StopTestSessionPayload payload, ITestRequestManager
try
{
requestManager.ResetOptions();
+ if (payload is null)
+ {
+ OnError(eventsHandler, null);
+ return;
+ }
+
requestManager.StopTestSession(payload, eventsHandler, _protocolConfig);
}
catch (Exception ex)
{
- EqtTrace.Error("DesignModeClient: Exception in StopTestSession: " + ex);
-
- eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex.ToString());
- eventsHandler.HandleStopTestSessionComplete(new(payload.TestSessionInfo));
+ OnError(eventsHandler, ex);
}
});
+
+ void OnError(TestSessionEventsHandler eventsHandler, Exception? ex)
+ {
+ EqtTrace.Error("DesignModeClient.StopTestSession: " + ex ?? "payload is null");
+
+ eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex?.ToString());
+ eventsHandler.HandleStopTestSessionComplete(new(payload?.TestSessionInfo));
+ }
}
#region IDisposable Support
diff --git a/src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs b/src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs
index ca9a470453..2396ef04d1 100644
--- a/src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs
+++ b/src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs
@@ -362,9 +362,9 @@ public void HandleRawMessage(string rawMessage)
? _dataSerializer.DeserializeMessage(rawMessage)
: null;
- if (string.Equals(message?.MessageType, MessageType.DiscoveryComplete))
+ if (MessageType.DiscoveryComplete.Equals(message?.MessageType))
{
- var discoveryCompletePayload = _dataSerializer.DeserializePayload(message!);
+ var discoveryCompletePayload = _dataSerializer.DeserializePayload(message);
rawMessage = UpdateRawMessageWithTelemetryInfo(discoveryCompletePayload, message) ?? rawMessage;
HandleLoggerManagerDiscoveryComplete(discoveryCompletePayload);
}
diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
index 2051479aaa..3265d9dab1 100644
--- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
+++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
@@ -52,7 +52,7 @@ public class TestRunRequest : ITestRunRequest, IInternalTestRunEventsHandler
///
/// Tracks the time taken by each run request
///
- private Stopwatch? _runRequestTimeTracker;
+ private readonly Stopwatch _runRequestTimeTracker = new();
private readonly IDataSerializer _dataSerializer;
@@ -146,10 +146,8 @@ public int ExecuteAsync()
_timer = new Timer(OnTestSessionTimeout, null, TimeSpan.FromMilliseconds(_testSessionTimeout), TimeSpan.FromMilliseconds(0));
}
- _runRequestTimeTracker = new Stopwatch();
-
// Start the stop watch for calculating the test run time taken overall
- _runRequestTimeTracker.Start();
+ _runRequestTimeTracker.Restart();
var testRunStartEvent = new TestRunStartEventArgs(TestRunCriteria);
LoggerManager.HandleTestRunStart(testRunStartEvent);
OnRunStart.SafeInvoke(this, testRunStartEvent, "TestRun.TestRunStart");
@@ -383,7 +381,7 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs, Test
try
{
- _runRequestTimeTracker?.Stop();
+ _runRequestTimeTracker.Stop();
if (lastChunkArgs != null)
{
@@ -401,7 +399,7 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs, Test
// This is required as TMI adapter is sending attachments as List which cannot be type casted to Collection.
runContextAttachments != null ? new Collection(runContextAttachments.ToList()) : null,
runCompleteArgs.InvokedDataCollectors,
- _runRequestTimeTracker!.Elapsed);
+ _runRequestTimeTracker.Elapsed);
// Add extensions discovered by vstest.console.
//
@@ -535,9 +533,9 @@ public void HandleRawMessage(string rawMessage)
var message = LoggerManager.LoggersInitialized || _requestData.IsTelemetryOptedIn ?
_dataSerializer.DeserializeMessage(rawMessage) : null;
- if (string.Equals(message?.MessageType, MessageType.ExecutionComplete))
+ if (MessageType.ExecutionComplete.Equals(message?.MessageType))
{
- var testRunCompletePayload = _dataSerializer.DeserializePayload(message!);
+ var testRunCompletePayload = _dataSerializer.DeserializePayload(message);
rawMessage = UpdateRawMessageWithTelemetryInfo(testRunCompletePayload, message) ?? rawMessage;
HandleLoggerManagerTestRunComplete(testRunCompletePayload);
}
diff --git a/src/Microsoft.TestPlatform.Client/TestSession/TestSessionEventsHandler.cs b/src/Microsoft.TestPlatform.Client/TestSession/TestSessionEventsHandler.cs
index cb1860e581..417a54cf7f 100644
--- a/src/Microsoft.TestPlatform.Client/TestSession/TestSessionEventsHandler.cs
+++ b/src/Microsoft.TestPlatform.Client/TestSession/TestSessionEventsHandler.cs
@@ -51,7 +51,7 @@ public void HandleStopTestSessionComplete(StopTestSessionCompleteEventArgs event
}
///
- public void HandleLogMessage(TestMessageLevel level, string message)
+ public void HandleLogMessage(TestMessageLevel level, string? message)
{
var messagePayload = new TestMessagePayload()
{
diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs
index 3af41a41f9..4794071dc1 100644
--- a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs
+++ b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs
@@ -136,7 +136,8 @@ public Message DeserializeMessage(string rawMessage)
// Unit tests also provide a Message in places where using the deserializer would actually
// produce a VersionedMessage or VersionedMessageWithRawMessage.
var serializerV1 = GetPayloadSerializer(null);
- return Deserialize(serializerV1, message.Payload!);
+ TPDebug.Assert(message.Payload is not null, "Payload should not be null");
+ return Deserialize(serializerV1, message.Payload);
}
var versionedMessage = (VersionedMessage)message;
@@ -146,7 +147,8 @@ public Message DeserializeMessage(string rawMessage)
{
// When fast json is disabled, then the message is a VersionedMessage
// with JToken payload.
- return Deserialize(payloadSerializer, message.Payload!);
+ TPDebug.Assert(message.Payload is not null, "Payload should not be null");
+ return Deserialize(payloadSerializer, message.Payload);
}
// When fast json is enabled then the message is also a subtype of VersionedMessage, but
@@ -167,7 +169,10 @@ public Message DeserializeMessage(string rawMessage)
// PERF: When payloadSerializer1 was resolved we need to deserialize JToken, and then deserialize that.
// This is still better than deserializing the JToken in DeserializeMessage because here we know that the payload
// will actually be used.
- return Deserialize(payloadSerializer, Deserialize(rawMessage!).Payload!);
+ TPDebug.Assert(rawMessage is not null, "rawMessage should not be null");
+ var rawMessagePayload = Deserialize(rawMessage).Payload;
+ TPDebug.Assert(rawMessagePayload is not null, "rawMessagePayload should not be null");
+ return Deserialize(payloadSerializer, rawMessagePayload);
}
}
diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs
index abae753465..1d9b118a18 100644
--- a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs
+++ b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs
@@ -367,7 +367,7 @@ public void SendRawMessage(string rawMessage)
break;
}
- if (_socket!.Poll(STREAMREADTIMEOUT, SelectMode.SelectRead) == true)
+ if (_socket.Poll(STREAMREADTIMEOUT, SelectMode.SelectRead) == true)
{
str = ReceiveRawMessage();
success = true;
diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs
index 1e539858e4..a99ba997fa 100644
--- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs
+++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs
@@ -567,7 +567,14 @@ private void OnDiscoveryMessageReceived(ITestDiscoveryEventsHandler2 discoveryEv
discoveryEventsHandler.HandleRawMessage(rawMessage);
var data = _dataSerializer.DeserializeMessage(rawMessage);
- switch (data!.MessageType)
+ if (data is null)
+ {
+ EqtTrace.Error("TestRequestSender.OnDiscoveryMessageReceived: Deserialized message is null: {0}", rawMessage);
+ OnDiscoveryAbort(discoveryEventsHandler, null, false);
+ return;
+ }
+
+ switch (data.MessageType)
{
case MessageType.TestCasesFound:
var testCases = _dataSerializer.DeserializePayload>(data);
diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/DataCollectorAttachmentProcessorWrapper.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/DataCollectorAttachmentProcessorWrapper.cs
index 2af2a241aa..5e65455982 100644
--- a/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/DataCollectorAttachmentProcessorWrapper.cs
+++ b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/DataCollectorAttachmentProcessorWrapper.cs
@@ -85,13 +85,13 @@ public bool LoadExtension(string filePath, Uri dataCollectorUri)
{
var dataCollectorExtensionManager = DataCollectorExtensionManager.Create(filePath, true, new MessageLogger(this, nameof(LoadExtension)));
var dataCollectorExtension = dataCollectorExtensionManager.TryGetTestExtension(dataCollectorUri);
- if (dataCollectorExtension is null || dataCollectorExtension?.Metadata.HasAttachmentProcessor == false)
+ if (dataCollectorExtension is null || dataCollectorExtension.Metadata.HasAttachmentProcessor == false)
{
TraceInfo($"DataCollectorAttachmentsProcessorsFactory: DataCollectorExtension not found for uri '{dataCollectorUri}'");
return false;
}
- Type attachmentProcessorType = ((DataCollectorConfig)dataCollectorExtension!.TestPluginInfo).AttachmentsProcessorType;
+ Type attachmentProcessorType = ((DataCollectorConfig)dataCollectorExtension.TestPluginInfo).AttachmentsProcessorType;
try
{
_dataCollectorAttachmentProcessorInstance = TestPluginManager.CreateTestExtension(attachmentProcessorType);
diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs
index c557b9f6cb..4176ad160c 100644
--- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs
+++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs
@@ -134,12 +134,10 @@ public override void Initialize(
if (_configurationElement != null)
{
- var collectDumpNode = _configurationElement[Constants.DumpModeKey];
- _collectProcessDumpOnCrash = collectDumpNode != null;
-
- if (_collectProcessDumpOnCrash)
+ if (_configurationElement[Constants.DumpModeKey] is XmlElement collectDumpNode)
{
- ValidateAndAddCrashProcessDumpParameters(collectDumpNode!);
+ _collectProcessDumpOnCrash = true;
+ ValidateAndAddCrashProcessDumpParameters(collectDumpNode);
// enabling dumps on MacOS needs to be done explicitly https://github.com/dotnet/runtime/pull/40105
_environmentVariables.Add(new KeyValuePair("COMPlus_DbgEnableElfDumpOnMacOS", "1"));
@@ -153,16 +151,23 @@ public override void Initialize(
var dumpPath = Path.Combine(dumpDirectory, $"%e_%p_%t_crashdump.dmp");
_environmentVariables.Add(new KeyValuePair("COMPlus_DbgMiniDumpName", dumpPath));
}
+ else
+ {
+ _collectProcessDumpOnCrash = false;
+ }
- var collectHangBasedDumpNode = _configurationElement[Constants.CollectDumpOnTestSessionHang];
- _collectProcessDumpOnHang = collectHangBasedDumpNode != null;
- if (_collectProcessDumpOnHang)
+ if (_configurationElement[Constants.CollectDumpOnTestSessionHang] is XmlElement collectHangBasedDumpNode)
{
+ _collectProcessDumpOnHang = true;
// enabling dumps on MacOS needs to be done explicitly https://github.com/dotnet/runtime/pull/40105
_environmentVariables.Add(new KeyValuePair("COMPlus_DbgEnableElfDumpOnMacOS", "1"));
ValidateAndAddHangProcessDumpParameters(collectHangBasedDumpNode!);
}
+ else
+ {
+ _collectProcessDumpOnHang = false;
+ }
var tfm = _configurationElement[Constants.TargetFramework]?.InnerText;
if (!tfm.IsNullOrWhiteSpace())
diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
index 1d31b1a9d5..ffad661e04 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
@@ -152,7 +152,6 @@ public void Initialize(TestLoggerEvents events, Dictionary para
public void TestMessageHandler(object? sender, TestRunMessageEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
-
TPDebug.Assert(TestRunDetails != null, "Initialize must be called before this method.");
switch (e.Level)
@@ -189,7 +188,6 @@ public void TestMessageHandler(object? sender, TestRunMessageEventArgs e)
public void TestResultHandler(object? sender, TestResultEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
-
TPDebug.Assert(ResultCollectionDictionary != null && TestRunDetails != null && Results != null, "Initialize must be called before this method.");
var testResult = new ObjectModel.TestResult
@@ -256,7 +254,6 @@ private void AddToParentResult(Guid parentExecutionId, ObjectModel.TestResult te
{
TPDebug.Assert(Results != null, "Initialize must be called before this method.");
-
if (Results.TryGetValue(parentExecutionId, out var parentTestResult))
{
if (parentTestResult.InnerTestResults == null)
diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Collection.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Collection.cs
index 36cf091257..564fb53320 100644
--- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Collection.cs
+++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Collection.cs
@@ -15,7 +15,7 @@ namespace Microsoft.TestPlatform.Extensions.TrxLogger.Utility;
/// Base class for Eqt Collections.
/// Fast collection, default implementations (Add/Remove/etc) do not allow null items and ignore duplicates.
///
-internal class EqtBaseCollection : ICollection, IXmlTestStore
+internal class EqtBaseCollection : ICollection, IXmlTestStore where T : notnull
{
#region private classes
///
@@ -91,7 +91,7 @@ public virtual void Add(T item)
{
EqtAssert.ParameterNotNull(item, nameof(item));
- if (!_container.Contains(item!))
+ if (!_container.Contains(item))
{
_container.Add(item!, null); // Do not want to xml-persist the value.
}
@@ -110,9 +110,9 @@ public virtual bool Contains(T item)
public virtual bool Remove(T item)
{
EqtAssert.ParameterNotNull(item, nameof(item)); // This is to be consistent with Add...
- if (_container.Contains(item!))
+ if (_container.Contains(item))
{
- _container.Remove(item!);
+ _container.Remove(item);
return true;
}
diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs
index 8d57e144cd..0b4382463b 100644
--- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs
+++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs
@@ -446,6 +446,7 @@ public void SaveIEnumerable(IEnumerable? list, XmlElement element, string listXm
/// Generic parameter
///
public void SaveList(IList list, XmlElement element, string listXmlElement, string itemLocation, string itemElementName, XmlTestStoreParameters parameters)
+ where V : notnull
{
if (list == null || list.Count <= 0)
{
@@ -456,7 +457,7 @@ public void SaveList(IList list, XmlElement element, string listXmlElement
TPDebug.Assert(listElement != null, "EnsureLocationExists should have returned a node");
foreach (V item in list)
{
- XmlElement itemXml = CreateElement(listElement, itemElementName, item!);
+ XmlElement itemXml = CreateElement(listElement, itemElementName, item);
SaveObject(item, itemXml, itemLocation, parameters);
}
}
diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs
index 1f3e69450c..e6bc1da63b 100644
--- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs
+++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs
@@ -380,7 +380,7 @@ private IEnumerable FilterExtensionsBasedOnVersion(IEnumerable e
TPDebug.Assert(IsInitialized, "Initialize must be called before FilterExtensionsBasedOnVersion");
Dictionary selectedExtensions = new();
- Dictionary highestFileVersions = new();
+ Dictionary highestFileVersions = new();
Dictionary conflictingExtensions = new();
foreach (var extensionFullPath in extensions)
diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs
index eb7c7c198a..4a4ed73a19 100644
--- a/src/vstest.console/CommandLine/Executor.cs
+++ b/src/vstest.console/CommandLine/Executor.cs
@@ -305,20 +305,22 @@ private int IdentifyDuplicateArguments(IEnumerable argumentP
// Check each processor.
foreach (var processor in argumentProcessors)
{
- if (!processor.Metadata.Value.AllowMultiple)
+ if (processor.Metadata.Value.AllowMultiple)
{
- if (!commandSeenCount.TryGetValue(processor.Metadata.Value.CommandName, out int count))
- {
- commandSeenCount.Add(processor.Metadata.Value.CommandName, 1);
- }
- else if (count == 1)
- {
- result = 1;
+ continue;
+ }
- // Update the count so we do not print the error out for this argument multiple times.
- commandSeenCount[processor.Metadata.Value.CommandName] = ++count;
- Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName));
- }
+ if (!commandSeenCount.TryGetValue(processor.Metadata.Value.CommandName, out int count))
+ {
+ commandSeenCount.Add(processor.Metadata.Value.CommandName, 1);
+ }
+ else if (count == 1)
+ {
+ result = 1;
+
+ // Update the count so we do not print the error out for this argument multiple times.
+ commandSeenCount[processor.Metadata.Value.CommandName] = ++count;
+ Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName));
}
}
return result;
diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs
index 623e50e292..b81ab0551c 100644
--- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs
+++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs
@@ -453,6 +453,7 @@ public void DesignModeClientConnectShouldCallRequestManagerForAttachmentsProcess
var startAttachmentsProcessing = new Message { MessageType = MessageType.TestRunAttachmentsProcessingStart, Payload = JToken.FromObject(payload) };
_mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true);
_mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startAttachmentsProcessing);
+ _mockCommunicationManager.Setup(cm => cm.DeserializePayload(It.IsAny())).Returns(payload);
_mockTestRequestManager
.Setup(