Skip to content

Commit

Permalink
Fix writing to trx when error has no message (#2364)
Browse files Browse the repository at this point in the history
Fixes intialization of error info that would require errors to have error message and not just stack trace. This is triggered for example by Assert.Fail() in nUnit that provides a null error message. Removed the constructor that we don't need, and enabled initialization in both setters to avoid failing.

Fixes #2319
  • Loading branch information
nohwnd authored Mar 18, 2020
1 parent 7e62090 commit 94501bb
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,6 @@ internal sealed class TestResultErrorInfo : IXmlTestStore
[StoreXmlSimpleField("StackTrace", "")]
private string stackTrace;

/// <summary>
/// Initializes a new instance of the <see cref="TestResultErrorInfo"/> class.
/// </summary>
/// <param name="message">
/// The message.
/// </param>
public TestResultErrorInfo(string message)
{
Debug.Assert(message != null, "message is null");
this.message = message;
}

/// <summary>
/// Gets or sets the message.
Expand Down Expand Up @@ -370,20 +359,28 @@ public TestResultId Id
/// </summary>
public string ErrorMessage
{
get { return (this.errorInfo == null) ? string.Empty : this.errorInfo.Message; }
set { this.errorInfo = new TestResultErrorInfo(value); }
get { return this.errorInfo?.Message ?? string.Empty; }
set
{
if (this.errorInfo == null)
this.errorInfo = new TestResultErrorInfo();

this.errorInfo.Message = value;
}
}

/// <summary>
/// Gets or sets the error stack trace.
/// </summary>
public string ErrorStackTrace
{
get { return (this.errorInfo == null) ? string.Empty : this.errorInfo.StackTrace; }
get { return this.errorInfo?.StackTrace ?? string.Empty; }

set
{
Debug.Assert(this.errorInfo != null, "errorInfo is null");
if (this.errorInfo == null)
this.errorInfo = new TestResultErrorInfo();

this.errorInfo.StackTrace = value;
}
}
Expand Down

0 comments on commit 94501bb

Please sign in to comment.