Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing 'AddResultFile' for NetCore TestContext #609

Merged
merged 8 commits into from
Apr 29, 2019
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(Resource.Common_CannotBeNullOrEmpty, "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 @@ -133,6 +133,19 @@ 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)
{
// No-op function
// will be replaced at runtime time by PlatformServices Desktop/NetCore
// depending the target framework
}

/// <summary>
/// Set the unit-test outcome
/// </summary>
Expand Down Expand Up @@ -174,15 +187,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 +234,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 @@ -19,7 +19,6 @@
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10FileOperationsTests.cs" Link="Services\ns10FileOperationsTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10DiaSessionOperationsTests.cs" Link="Services\ns10DiaSessionOperationsTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10ReflectionOperationsTests.cs" Link="Services\ns10ReflectionOperationsTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10TestContextImplementationTests.cs" Link="Services\ns10TestContextImplementationTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10TestSourceHostTests.cs" Link="Services\ns10TestSourceHostTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10TestSourceTests.cs" Link="Services\ns10TestSourceTests.cs" />
<Compile Include="..\PlatformServices.Shared.Unit.Tests\netstandard1.0\ns10ThreadOperationsTests.cs" Link="Services\ns10ThreadOperationsTests.cs" />
Expand Down
Loading