Add mstest support (#4572)

* Migrate: auto-injected dependencies should overwrite existing dependency version if present

* WIP adding new mstest templates

* Auto-inject mstest dependencies when testrunner is set to mstest

* WIP trying to get new web test to work

* Get dotnet new -t Web test to pass

* Remove whitespace and accidentally added (redundant) tests

* Shorten test method name
This commit is contained in:
Justin Goshi 2016-11-02 08:49:45 -10:00 committed by GitHub
parent 80ec02b4da
commit d1772f6ed4
10 changed files with 169 additions and 24 deletions

View file

@ -9,5 +9,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string TestSdkPackageVersion = "15.0.0-preview-20161024-02";
public const string XUnitPackageVersion = "2.2.0-beta3-build3402";
public const string XUnitRunnerPackageVersion = "2.2.0-beta4-build1188";
public const string MstestTestAdapterVersion = "1.1.3-preview";
public const string MstestTestFrameworkVersion = "1.0.4-preview";
}
}

View file

@ -19,6 +19,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk";
public const string XUnitPackageName = "xunit";
public const string XUnitRunnerPackageName = "xunit.runner.visualstudio";
public const string MstestTestAdapterName = "MSTest.TestAdapter";
public const string MstestTestFrameworkName = "MSTest.TestFramework";
public const string NetStandardPackageName = "NETStandard.Library";
public const string NetStandardPackageVersion = "1.6.0";
@ -46,6 +48,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{ XUnitRunnerPackageName, new PackageDependencyInfo {
Name = XUnitRunnerPackageName,
Version = ConstantPackageVersions.XUnitRunnerPackageVersion } },
{ MstestTestAdapterName, new PackageDependencyInfo {
Name = MstestTestAdapterName,
Version = ConstantPackageVersions.MstestTestAdapterVersion } },
{ MstestTestFrameworkName, new PackageDependencyInfo {
Name = MstestTestFrameworkName,
Version = ConstantPackageVersions.MstestTestFrameworkVersion } },
};
public static readonly IDictionary<string, PackageDependencyInfo> ProjectToolPackages =

View file

@ -135,6 +135,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
noFrameworkPackageReferenceItemGroup,
mergeExisting: false);
}
else if (project.TestRunner.Equals("mstest", StringComparison.OrdinalIgnoreCase))
{
_transformApplicator.Execute(
PackageDependencyInfoTransform().Transform(
new PackageDependencyInfo
{
Name = PackageConstants.MstestTestAdapterName,
Version = ConstantPackageVersions.MstestTestAdapterVersion
}),
noFrameworkPackageReferenceItemGroup,
mergeExisting: false);
_transformApplicator.Execute(
PackageDependencyInfoTransform().Transform(
new PackageDependencyInfo
{
Name = PackageConstants.MstestTestFrameworkName,
Version = ConstantPackageVersions.MstestTestFrameworkVersion
}),
noFrameworkPackageReferenceItemGroup,
mergeExisting: false);
}
break;
case ProjectType.Library:
if (!project.HasDependency(

View file

@ -0,0 +1,34 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161029-1</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0-preview-20161024-02</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>1.1.3-preview</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>1.0.4-preview</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tests
{
[TestClass]
public class TestClass
{
[TestMethod]
public void TestMethodPassing()
{
Assert.IsTrue(true);
}
}
}

View file

@ -138,7 +138,8 @@ namespace Microsoft.DotNet.Tools.New
new { Name = "Console", isMsBuild = true },
new { Name = "Web", isMsBuild = true },
new { Name = "Lib", isMsBuild = true },
new { Name = "Xunittest", isMsBuild = true }
new { Name = "mstest", isMsBuild = true },
new { Name = "xunittest", isMsBuild = true }
}
};

View file

@ -10,8 +10,8 @@
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;netstandardapp1.5;portable-net45+win8;portable-net45+wp80+win8+wpa81+dnxcore50</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" Exclude="commands\dotnet-new\CSharp_Console\**;commands\dotnet-new\CSharp_Web\**;commands\dotnet-new\CSharp_Lib\**;commands\dotnet-new\CSharp_xunittest\**" />
<EmbeddedResource Include="commands\dotnet-new\CSharp_Console.zip;commands\dotnet-new\CSharp_Lib.zip;commands\dotnet-new\CSharp_Web.zip;commands\dotnet-new\CSharp_xunittest.zip" />
<Compile Include="**\*.cs" Exclude="commands\dotnet-new\CSharp_Console\**;commands\dotnet-new\CSharp_Web\**;commands\dotnet-new\CSharp_Lib\**;commands\dotnet-new\CSharp_mstest\**;commands\dotnet-new\CSharp_xunittest\**" />
<EmbeddedResource Include="commands\dotnet-new\CSharp_Console.zip;commands\dotnet-new\CSharp_Lib.zip;commands\dotnet-new\CSharp_Web.zip;commands\dotnet-new\CSharp_mstest.zip;commands\dotnet-new\CSharp_xunittest.zip" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />

View file

@ -269,7 +269,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
""frameworks"": {
""netcoreapp1.0"": {}
},
""testRunner"": ""mstest""
""testRunner"": ""somerunner""
}");
mockProj.Items.Should().ContainSingle(
@ -282,6 +282,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Items.Should().NotContain(
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestAdapter" && i.ItemType == "PackageReference"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestFramework" && i.ItemType == "PackageReference"));
}
[Fact]
@ -312,6 +318,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
i => (i.Include == "xunit.runner.visualstudio" &&
i.ItemType == "PackageReference" &&
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestAdapter" && i.ItemType == "PackageReference"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestFramework" && i.ItemType == "PackageReference"));
}
[Fact]
@ -345,6 +357,48 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
i => (i.Include == "xunit.runner.visualstudio" &&
i.ItemType == "PackageReference" &&
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestAdapter" && i.ItemType == "PackageReference"));
mockProj.Items.Should().NotContain(
i => (i.Include == "MSTest.TestFramework" && i.ItemType == "PackageReference"));
}
[Fact]
public void It_migrates_test_projects_to_have_test_sdk_and_mstest_packagedependencies()
{
var mockProj = RunPackageDependenciesRuleOnPj(@"
{
""buildOptions"": {
""emitEntryPoint"": true
},
""frameworks"": {
""netcoreapp1.0"": {}
},
""testRunner"": ""mstest""
}");
mockProj.Items.Should().ContainSingle(
i => (i.Include == "Microsoft.NET.Test.Sdk" &&
i.ItemType == "PackageReference" &&
i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02"));
mockProj.Items.Should().ContainSingle(
i => (i.Include == "MSTest.TestAdapter" &&
i.ItemType == "PackageReference" &&
i.GetMetadataWithName("Version").Value == "1.1.3-preview"));
mockProj.Items.Should().ContainSingle(
i => (i.Include == "MSTest.TestFramework" &&
i.ItemType == "PackageReference" &&
i.GetMetadataWithName("Version").Value == "1.0.4-preview"));
mockProj.Items.Should().NotContain(
i => (i.Include == "xunit" && i.ItemType == "PackageReference"));
mockProj.Items.Should().NotContain(
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
}
[Theory]

View file

@ -13,33 +13,32 @@ using FluentAssertions;
namespace Microsoft.DotNet.New.Tests
{
public class GivenThatIWantANewCSLibrary : TestBase
public class GivenThatIWantANewCSAppWithSpecifiedType : TestBase
{
[Fact]
public void When_library_created_Then_project_restores()
[Theory]
[InlineData("Console", false)]
[InlineData("Lib", false)]
[InlineData("Web", true)]
[InlineData("Mstest", false)]
[InlineData("XUnittest", false)]
public void When_dotnet_build_is_invoked_then_project_restores_and_builds_without_warnings(
string projectType,
bool useNuGetConfigForAspNet)
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var rootPath = TestAssetsManager.CreateTestDirectory(callingMethod: "i").Path;
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute("new --type lib")
.Execute($"new --type {projectType}")
.Should().Pass();
if (useNuGetConfigForAspNet)
{
File.Copy("NuGet.tempaspnetpatch.config", Path.Combine(rootPath, "NuGet.Config"));
}
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute("restore /p:SkipInvalidConfigurations=true")
.Execute($"restore /p:SkipInvalidConfigurations=true")
.Should().Pass();
}
[Fact]
public void When_dotnet_build_is_invoked_Then_library_builds_without_warnings()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute("new --type lib");
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute("restore /p:SkipInvalidConfigurations=true");
var buildResult = new TestCommand("dotnet")
.WithWorkingDirectory(rootPath)

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="aspnet101" value="https://www.myget.org/F/aspnet101/api/v3/index.json" />
<add key="dotnet-web" value="https://dotnet.myget.org/F/dotnet-web/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>