Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;
Expand All @@ -31,7 +32,7 @@ public class TestContextImplementation : UTF.TestContext, ITestContext
/// <summary>
/// List of result files associated with the test
/// </summary>
private IList<string> testResultFiles;
private readonly IList<string> testResultFiles;

/// <summary>
/// Properties
Expand Down Expand Up @@ -213,6 +214,22 @@ public UTF.TestContext Context
}
}

/// <summary>
/// Adds a file name to the list in TestResult.ResultFileNames
/// </summary>
/// <param name="fileName">
/// The file Name.
/// </param>
public override void AddResultFile(string fileName)
{
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentException("The parameter should not be null or empty.", "fileName");
}

this.testResultFiles.Add(Path.GetFullPath(fileName));
}

/// <summary>
/// Set the unit-test outcome
/// </summary>
Expand Down Expand Up @@ -255,12 +272,21 @@ public void AddProperty(string propertyName, string propertyValue)
}

/// <summary>
/// Returning null as this feature is not supported in ASP .net and UWP
/// Result files attached
/// </summary>
/// <returns>List of result files. Null presently.</returns>
/// <returns>List of result files generated in run.</returns>
public IList<string> GetResultFiles()
{
return null;
if (this.testResultFiles.Count == 0)
{
return null;
}

IList<string> results = this.testResultFiles.ToList();

this.testResultFiles.Clear();

return results;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;
Expand All @@ -29,6 +30,11 @@ public class TestContextImplementation : UTF.TestContext, ITestContext
private static readonly string FullyQualifiedTestClassNameLabel = "FullyQualifiedTestClassName";
private static readonly string TestNameLabel = "TestName";

/// <summary>
/// List of result files associated with the test
/// </summary>
private readonly IList<string> testResultFiles;

/// <summary>
/// Properties
/// </summary>
Expand Down Expand Up @@ -61,6 +67,7 @@ public TestContextImplementation(ITestMethod testMethod, StringWriter writer, ID
this.testMethod = testMethod;
this.properties = new Dictionary<string, object>(properties);
this.stringWriter = writer;
this.testResultFiles = new List<string>();
this.CancellationTokenSource = new CancellationTokenSource();
this.InitializeProperties();
}
Expand Down Expand Up @@ -133,6 +140,16 @@ public UTF.TestContext Context
}
}

public override void AddResultFile(string fileName)
{
if (string.IsNullOrEmpty(fileName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can skip adding any code here and keep this function as a no-op for PlaformServices.Portable.
Note - PlatformServices.Portable is used just at compile time, and it will get replaced by PlatformServices.Desktop/Netcore at runtime depending on the target framework for your test project.

Since, desktop TestContext already has a implementation for AddResultsFile(), we just need to add implementation in NetCoreTestContext and we should be good to know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic! good to know that. I'm pushing in a few mins

{
throw new ArgumentException("The parameter should not be null or empty.", "fileName");
}

this.testResultFiles.Add(Path.GetFullPath(fileName));
}

/// <summary>
/// Set the unit-test outcome
/// </summary>
Expand Down Expand Up @@ -174,15 +191,6 @@ public void AddProperty(string propertyName, string propertyValue)
this.properties.Add(propertyName, propertyValue);
}

/// <summary>
/// Returning null as this feature is not supported in ASP .net and UWP
/// </summary>
/// <returns>List of result files. Null presently.</returns>
public IList<string> GetResultFiles()
{
return null;
}

/// <summary>
/// When overridden in a derived class, used to write trace messages while the
/// test is running.
Expand Down Expand Up @@ -230,6 +238,15 @@ public override void WriteLine(string format, params object[] args)
}
}

/// <summary>
/// Returns null as this feature is not supported in ASP .net and UWP
/// </summary>
/// <returns>List of result files. Null presently.</returns>
public IList<string> GetResultFiles()
{
return null;
}

/// <summary>
/// Gets messages from the testContext writeLines
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/TestFramework/Extension.Core/NetCoreTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public abstract class TestContext
/// </summary>
public virtual UnitTestOutcome CurrentTestOutcome => UnitTestOutcome.Unknown;

/// <summary>
/// Adds a file name to the list in TestResult.ResultFileNames
/// </summary>
/// <param name="fileName">
/// The file Name.
/// </param>
public abstract void AddResultFile(string fileName);

/// <summary>
/// Used to write trace messages while the test is running
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ namespace MSTestAdapter.PlatformServices.Tests.Services
using UnitTestOutcome = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Moq;
using MSTestAdapter.TestUtilities;
using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod;

[TestClass]
Expand Down