Skip to content

Commit

Permalink
Added support for ManagedType and ManagedMethod.
Browse files Browse the repository at this point in the history
Added support for `ManagedType` and `ManagedMethod` into various classes. Also centralized TestPlarform version, and some refactoring.
  • Loading branch information
Haplois committed Nov 2, 2020
1 parent 50217a2 commit df1e301
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 80 deletions.
24 changes: 24 additions & 0 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,31 @@ function Create-NugetPackages
Write-Log "Create-NugetPackages: Complete. {$(Get-ElapsedTime($timer))}"
}

function Replace-InFile($File, $RegEx, $ReplaceWith) {
$content = Get-Content -Raw -Encoding utf8 $File
$newContent = ($content -replace $RegEx,$ReplaceWith)
if($content.Equals($ReplaceWith)) {
return
}

Write-Verbose "Updating TestPlatform version in $_"
$newContent | Set-Content -Encoding utf8 $file -NoNewline
}

function Sync-PackageVersions {
$testPlarformVersion = (([XML](Get-Content $PSScriptRoot\build\TestFx.Settings.targets)).Project.PropertyGroup[1].TestPlatfromVersion).InnerText
$packageRegex = '(?mi)<package id="Microsoft\.TestPlatform\.([0-9a-z.]+)" version="([0-9a-z.-]*)"'
$sourceRegex = '(?mi)(.+[a-z =]+\@\")Microsoft\.TestPlatform\.([0-9.-a-z]+)\";'

(Get-ChildItem "$PSScriptRoot\..\src\*packages.config","$PSScriptRoot\..\test\*packages.config" -Recurse) | ForEach-Object {
Replace-InFile -File $_ -RegEx $packageRegex -ReplaceWith "<package id=`"Microsoft.TestPlatform.`$1`" version=`"$testPlarformVersion`""
}

Replace-InFile -File "$PSScriptRoot\..\test\E2ETests\Automation.CLI\CLITestBase.cs" -RegEx $sourceRegex -ReplaceWith "`$1Microsoft.TestPlatform.$testPlarformVersion`";"
}

Print-Help
Sync-PackageVersions
Perform-Restore
Perform-Build
Create-NugetPackages
1 change: 1 addition & 0 deletions scripts/build/TestFx.Settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Import Project="$(RepoRoot)packages\MicroBuild.Core.0.2.0\build\MicroBuild.Core.props" Condition="Exists('$(RepoRoot)packages\MicroBuild.Core.0.2.0\build\MicroBuild.Core.props')" />

<PropertyGroup>
<TestPlatfromVersion Condition=" '$(TestPlatfromVersion)' == '' ">16.9.0-preview-20201021-10</TestPlatfromVersion>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/TestFx.targets
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- Signing and Localization. -->
<ItemGroup Condition="$(IsTest) == '' or $(IsTest) == 'false'">
<FilesToSign Include="$(OutDir)\$(AssemblyName).dll" Condition="'$(IsVsixProj)' == '' or '$(IsVsixProj)' != 'true'">
<Authenticode>Microsoft402400</Authenticode>
<Authenticode>Microsoft400</Authenticode>
<StrongName>StrongName</StrongName>
</FilesToSign>

Expand All @@ -59,7 +59,7 @@
<Target Name="GatherLocalizedOutputsForSigning" DependsOnTargets="TestFxLocalization">
<ItemGroup>
<FilesToSign Include="$(OutDir)\**\$(AssemblyName).resources.dll">
<Authenticode>Microsoft402400</Authenticode>
<Authenticode>Microsoft400</Authenticode>
<StrongName>StrongName</StrongName>
</FilesToSign>
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ $TFT_Pattern = $Pattern
$TFT_Parallel = $Parallel
$TFT_All = $All
$TestFramework = ".NETCoreApp,Version=v1.0"
$VSTestConsoleRelativePath = "Microsoft.TestPlatform.15.0.1\tools\net46\vstest.console.exe"

#
# Prints help text for the switches this script supports.
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/Discovery/TypeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInT
// This allows void returning async test method to be valid test method. Though they will be executed similar to non-async test method.
var isAsync = ReflectHelper.MatchReturnType(method, typeof(Task));

var testMethod = new TestMethod(method.Name, this.type.FullName, this.assemblyName, isAsync);
var testMethod = new TestMethod(method, method.Name, this.type.FullName, this.assemblyName, isAsync);

if (!method.DeclaringType.FullName.Equals(this.type.FullName))
{
Expand Down
7 changes: 4 additions & 3 deletions src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,16 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Concurrent">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\System.Collections.Concurrent.dll</HintPath>
Expand Down
23 changes: 22 additions & 1 deletion src/Adapter/MSTest.CoreAdapter/ObjectModel/TestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel
{
using System;
using System.Diagnostics;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.FullyQualifiedNameUtilities;

using MSTestAdapter.PlatformServices.Interface.ObjectModel;

Expand All @@ -28,7 +31,7 @@ public sealed class TestMethod : ITestMethod

#endregion

public TestMethod(string name, string fullClassName, string assemblyName, bool isAsync)
public TestMethod(string name, string fullClassName, string assemblyName, bool isAsync)
{
if (string.IsNullOrEmpty(assemblyName))
{
Expand All @@ -44,6 +47,20 @@ public TestMethod(string name, string fullClassName, string assemblyName, bool
this.IsAsync = isAsync;
}

public TestMethod(MethodBase method, string name, string fullClassName, string assemblyName, bool isAsync)
: this(name, fullClassName, assemblyName, isAsync)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}

FullyQualifiedNameHelper.GetFullyQualifiedName(method, out var managedType, out var managedMethod);

this.ManagedType = managedType;
this.ManagedMethod = managedMethod;
}

/// <summary>
/// Gets the name of the test method
/// </summary>
Expand Down Expand Up @@ -102,5 +119,9 @@ public string DeclaringClassFullName
/// Gets a value indicating whether specifies test method is async
/// </summary>
public bool IsAsync { get; private set; }

public string ManagedType { get; }

public string ManagedMethod { get; }
}
}
15 changes: 13 additions & 2 deletions src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,21 @@ internal TestCase ToTestCase()
this.TestMethod.FullClassName,
this.TestMethod.Name);

TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName);
testCase.DisplayName = string.IsNullOrEmpty(this.DisplayName) ? this.TestMethod.Name : this.DisplayName;
TestCase testCase;

if (string.IsNullOrWhiteSpace(this.TestMethod.ManagedType) || string.IsNullOrWhiteSpace(this.TestMethod.ManagedMethod))
{
testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName);
}
else
{
testCase = new TestCase(fullName, this.TestMethod.ManagedType, this.TestMethod.ManagedMethod, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName);
}

testCase.DisplayName = string.IsNullOrEmpty(this.DisplayName) ? this.TestMethod.Name : this.DisplayName;
testCase.SetPropertyValue(TestAdapter.Constants.TestClassNameProperty, this.TestMethod.FullClassName);
testCase.SetPropertyValue(TestCaseProperties.ManagedType, this.TestMethod.ManagedType);
testCase.SetPropertyValue(TestCaseProperties.ManagedMethod, this.TestMethod.ManagedMethod);

// Set declaring type if present so the correct method info can be retrieved
if (this.TestMethod.DeclaringClassFullName != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\net45\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\net45\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\net45\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="NuGet.Frameworks, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\NuGet.Frameworks.5.0.0\lib\net40\NuGet.Frameworks.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
using System.IO;
using System.Linq;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;

using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;

/// <summary>
Expand Down Expand Up @@ -208,6 +210,24 @@ public override string FullyQualifiedTestClassName
}
}

/// <inheritdoc/>
public override string ManagedType
{
get
{
return this.GetStringPropertyValue(TestContextPropertyStrings.ManagedType);
}
}

/// <inheritdoc/>
public override string ManagedMethod
{
get
{
return this.GetStringPropertyValue(TestContextPropertyStrings.ManagedMethod);
}
}

/// <inheritdoc/>
public override string TestName
{
Expand Down Expand Up @@ -450,40 +470,16 @@ private static UTF.UnitTestOutcome ToUTF(UTF.UnitTestOutcome outcome)
switch (outcome)
{
case UTF.UnitTestOutcome.Error:
{
return UTF.UnitTestOutcome.Error;
}

case UTF.UnitTestOutcome.Failed:
{
return UTF.UnitTestOutcome.Failed;
}

case UTF.UnitTestOutcome.Inconclusive:
{
return UTF.UnitTestOutcome.Inconclusive;
}

case UTF.UnitTestOutcome.Passed:
{
return UTF.UnitTestOutcome.Passed;
}

case UTF.UnitTestOutcome.Timeout:
{
return UTF.UnitTestOutcome.Timeout;
}

case UTF.UnitTestOutcome.InProgress:
{
return UTF.UnitTestOutcome.InProgress;
}
return outcome;

default:
{
Debug.Fail("Unknown outcome " + outcome);
return UTF.UnitTestOutcome.Unknown;
}
Debug.Fail("Unknown outcome " + outcome);
return UTF.UnitTestOutcome.Unknown;
}
}

Expand All @@ -505,6 +501,8 @@ private string GetStringPropertyValue(string propertyName)
private void InitializeProperties()
{
this.properties[TestContextPropertyStrings.FullyQualifiedTestClassName] = this.testMethod.FullClassName;
this.properties[TestContextPropertyStrings.ManagedType] = this.testMethod.ManagedType;
this.properties[TestContextPropertyStrings.ManagedMethod] = this.testMethod.ManagedMethod;
this.properties[TestContextPropertyStrings.TestName] = this.testMethod.Name;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Adapter/PlatformServices.Interface/ObjectModel/ITestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,21 @@ public interface ITestMethod
/// Gets a value indicating whether test method is async
/// </summary>
bool IsAsync { get; }

/// <summary>
/// Gets the fully specified type name metadata format.
/// </summary>
/// <example>
/// <code>NamespaceA.NamespaceB.ClassName`1+InnerClass`2</code>
/// </example>
string ManagedType { get; }

/// <summary>
/// Gets the fully specified method name metadata format.
/// </summary>
/// <example>
/// <code>MethodName`2(ParamTypeA,ParamTypeB,…)</code>
/// </example>
string ManagedMethod { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ComponentModel.Primitives.4.3.0\lib\netstandard1.0\System.ComponentModel.Primitives.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="16.9.0-preview-20201021-10" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(TestPlatfromVersion)" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
/// </remarks>
public class TestContextImplementation : UTF.TestContext, ITestContext
{
private static readonly string FullyQualifiedTestClassNameLabel = "FullyQualifiedTestClassName";
private static readonly string TestNameLabel = "TestName";
private static readonly string FullyQualifiedTestClassNameLabel = nameof(FullyQualifiedTestClassName);
private static readonly string ManagedTypeLabel = nameof(ManagedType);
private static readonly string ManagedMethodLabel = nameof(ManagedMethod);
private static readonly string TestNameLabel = nameof(TestName);

/// <summary>
/// List of result files associated with the test
Expand Down Expand Up @@ -444,6 +446,8 @@ private string GetStringPropertyValue(string propertyName)
private void InitializeProperties()
{
this.properties[FullyQualifiedTestClassNameLabel] = this.testMethod.FullClassName;
this.properties[ManagedTypeLabel] = this.testMethod.ManagedType;
this.properties[ManagedMethodLabel] = this.testMethod.ManagedMethod;
this.properties[TestNameLabel] = this.testMethod.Name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.16.9.0-preview-20201021-10\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ComponentModel.Primitives.4.3.0\lib\netstandard1.0\System.ComponentModel.Primitives.dll</HintPath>
Expand Down
Loading

0 comments on commit df1e301

Please sign in to comment.