diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs index 1cd6e3dd05..6413beab1f 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs @@ -81,9 +81,9 @@ internal static class FailedTestResultMessageFieldsId public const ushort Duration = 4; public const ushort Reason = 5; public const ushort ExceptionMessageList = 6; - public const ushort StandardOutput = 8; - public const ushort ErrorOutput = 9; - public const ushort SessionUid = 10; + public const ushort StandardOutput = 7; + public const ushort ErrorOutput = 8; + public const ushort SessionUid = 9; } internal static class ExceptionMessageFieldsId diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/TestResultMessagesSerializer.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/TestResultMessagesSerializer.cs index d62e8cb50b..5701b9c340 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/TestResultMessagesSerializer.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/TestResultMessagesSerializer.cs @@ -215,7 +215,7 @@ private static List ReadFailedTestMessagesPayload(Strea for (int i = 0; i < length; i++) { string? uid = null, displayName = null, reason = null, sessionUid = null, standardOutput = null, errorOutput = null; - List exceptionMessages = []; + ExceptionMessage[] exceptionMessages = []; byte? state = null; long? duration = null; @@ -249,42 +249,8 @@ private static List ReadFailedTestMessagesPayload(Strea break; case FailedTestResultMessageFieldsId.ExceptionMessageList: - { - int length2 = ReadInt(stream); - for (int k = 0; k < length2; k++) - { - int fieldCount2 = ReadShort(stream); - - string? errorMessage = null; - string? errorType = null; - string? stackTrace = null; - - for (int l = 0; l < fieldCount2; l++) - { - int fieldId2 = ReadShort(stream); - int fieldSize2 = ReadInt(stream); - - switch (fieldId2) - { - case ExceptionMessageFieldsId.ErrorMessage: - errorMessage = ReadStringValue(stream, fieldSize2); - break; - - case ExceptionMessageFieldsId.ErrorType: - errorType = ReadStringValue(stream, fieldSize2); - break; - - case ExceptionMessageFieldsId.StackTrace: - stackTrace = ReadStringValue(stream, fieldSize2); - break; - } - } - - exceptionMessages.Add(new ExceptionMessage(errorMessage, errorType, stackTrace)); - } - - break; - } + exceptionMessages = ReadExceptionMessagesPayload(stream); + break; case FailedTestResultMessageFieldsId.StandardOutput: standardOutput = ReadStringValue(stream, fieldSize); @@ -304,12 +270,52 @@ private static List ReadFailedTestMessagesPayload(Strea } } - failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, exceptionMessages.ToArray(), standardOutput, errorOutput, sessionUid)); + failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, exceptionMessages, standardOutput, errorOutput, sessionUid)); } return failedTestResultMessages; } + private static ExceptionMessage[] ReadExceptionMessagesPayload(Stream stream) + { + var exceptionMessages = new List(); + + int length = ReadInt(stream); + for (int i = 0; i < length; i++) + { + int fieldCount = ReadShort(stream); + + string? errorMessage = null; + string? errorType = null; + string? stackTrace = null; + + for (int j = 0; j < fieldCount; j++) + { + int fieldId = ReadShort(stream); + int fieldSize = ReadInt(stream); + + switch (fieldId) + { + case ExceptionMessageFieldsId.ErrorMessage: + errorMessage = ReadStringValue(stream, fieldSize); + break; + + case ExceptionMessageFieldsId.ErrorType: + errorType = ReadStringValue(stream, fieldSize); + break; + + case ExceptionMessageFieldsId.StackTrace: + stackTrace = ReadStringValue(stream, fieldSize); + break; + } + } + + exceptionMessages.Add(new ExceptionMessage(errorMessage, errorType, stackTrace)); + } + + return exceptionMessages.ToArray(); + } + public void Serialize(object objectToSerialize, Stream stream) { RoslynDebug.Assert(stream.CanSeek, "We expect a seekable stream.");