diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs index 6a0597418..75df5fb9e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs @@ -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"; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs index 6317b2a71..6226ad52a 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs @@ -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 ProjectToolPackages = diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index c6a3ff2e2..633ee3107 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -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( diff --git a/src/dotnet/commands/dotnet-new/CSharp_mstest/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_mstest/$projectName$.csproj new file mode 100644 index 000000000..5562e106f --- /dev/null +++ b/src/dotnet/commands/dotnet-new/CSharp_mstest/$projectName$.csproj @@ -0,0 +1,34 @@ + + + + + Exe + netcoreapp1.0 + + + + + + + + + + 1.0.1 + + + 1.0.0-alpha-20161029-1 + All + + + 15.0.0-preview-20161024-02 + + + 1.1.3-preview + + + 1.0.4-preview + + + + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-new/CSharp_mstest/Tests.cs b/src/dotnet/commands/dotnet-new/CSharp_mstest/Tests.cs new file mode 100644 index 000000000..8cc5ed786 --- /dev/null +++ b/src/dotnet/commands/dotnet-new/CSharp_mstest/Tests.cs @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Tests +{ + [TestClass] + public class TestClass + { + [TestMethod] + public void TestMethodPassing() + { + Assert.IsTrue(true); + } + } +} diff --git a/src/dotnet/commands/dotnet-new/Program.cs b/src/dotnet/commands/dotnet-new/Program.cs index 847ba33a0..007bd7af6 100644 --- a/src/dotnet/commands/dotnet-new/Program.cs +++ b/src/dotnet/commands/dotnet-new/Program.cs @@ -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 } } }; diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 33adc44f7..0cba9b130 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -10,8 +10,8 @@ $(PackageTargetFallback);dnxcore50;netstandardapp1.5;portable-net45+win8;portable-net45+wp80+win8+wpa81+dnxcore50 - - + + diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 4170568fe..35a9abd5e 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -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] diff --git a/test/dotnet-new.Tests/GivenThatIWantANewCSLIbrary.cs b/test/dotnet-new.Tests/GivenThatIWantANewCSAppWithSpecifiedType.cs similarity index 55% rename from test/dotnet-new.Tests/GivenThatIWantANewCSLIbrary.cs rename to test/dotnet-new.Tests/GivenThatIWantANewCSAppWithSpecifiedType.cs index 0ecc19308..4e62fd75a 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewCSLIbrary.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewCSAppWithSpecifiedType.cs @@ -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) diff --git a/test/dotnet-new.Tests/NuGet.tempaspnetpatch.config b/test/dotnet-new.Tests/NuGet.tempaspnetpatch.config new file mode 100644 index 000000000..41ba66505 --- /dev/null +++ b/test/dotnet-new.Tests/NuGet.tempaspnetpatch.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file