Skip to content

Commit

Permalink
TestContext: Unify SetOutcome behavior across all target frameworks (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Dec 12, 2022
1 parent 2683cc3 commit c2648ee
Showing 1 changed file with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -15,7 +14,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Expand Down Expand Up @@ -56,7 +54,7 @@ public class TestContextImplementation : TestContext, ITestContext
/// <summary>
/// Unit test outcome.
/// </summary>
private UTF.UnitTestOutcome _outcome;
private UnitTestOutcome _outcome;

#if NETFRAMEWORK
/// <summary>
Expand Down Expand Up @@ -107,13 +105,7 @@ public TestContextImplementation(ITestMethod testMethod, StringWriter stringWrit
#region TestContext impl

/// <inheritdoc/>
public override UTF.UnitTestOutcome CurrentTestOutcome
{
get
{
return _outcome;
}
}
public override UnitTestOutcome CurrentTestOutcome => _outcome;

#if NETFRAMEWORK
/// <inheritdoc/>
Expand Down Expand Up @@ -166,7 +158,7 @@ public override UTF.UnitTestOutcome CurrentTestOutcome
public override string TestName => base.TestName!;
#endif

public UTF.TestContext Context => this;
public TestContext Context => this;

/// <inheritdoc/>
public override void AddResultFile(string fileName)
Expand Down Expand Up @@ -295,13 +287,9 @@ public override void WriteLine(string format, params object?[] args)
/// Set the unit-test outcome.
/// </summary>
/// <param name="outcome">The test outcome.</param>
public void SetOutcome(UTF.UnitTestOutcome outcome)
public void SetOutcome(UnitTestOutcome outcome)
{
#if NETFRAMEWORK
_outcome = ToUTF(outcome);
#else
_outcome = outcome;
#endif
}

/// <summary>
Expand Down Expand Up @@ -395,29 +383,4 @@ public void ClearDiagnosticMessages()
}

#endregion

#if NETFRAMEWORK
/// <summary>
/// Converts the parameter outcome to UTF outcome.
/// </summary>
/// <param name="outcome">The UTF outcome.</param>
/// <returns>test outcome.</returns>
private static UTF.UnitTestOutcome ToUTF(UTF.UnitTestOutcome outcome)
{
switch (outcome)
{
case UnitTestOutcome.Error:
case UnitTestOutcome.Failed:
case UnitTestOutcome.Inconclusive:
case UnitTestOutcome.Passed:
case UnitTestOutcome.Timeout:
case UnitTestOutcome.InProgress:
return outcome;

default:
Debug.Fail("Unknown outcome " + outcome);
return UnitTestOutcome.Unknown;
}
}
#endif
}

0 comments on commit c2648ee

Please sign in to comment.