Merge pull request #4550 from dotnet/dev/jgoshi/migrateTests
Migrate: add package dependencies to test projects
This commit is contained in:
commit
c0135d75be
5 changed files with 139 additions and 2 deletions
|
@ -9,6 +9,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
public const string SdkPackageName = "Microsoft.NET.Sdk";
|
public const string SdkPackageName = "Microsoft.NET.Sdk";
|
||||||
public const string WebSdkPackageName = "Microsoft.NET.Sdk.Web";
|
public const string WebSdkPackageName = "Microsoft.NET.Sdk.Web";
|
||||||
|
public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk";
|
||||||
|
public const string TestSdkPackageVersion = "15.0.0-preview-20161024-02";
|
||||||
|
public const string XUnitPackageName = "xunit";
|
||||||
|
public const string XUnitPackageVersion = "2.2.0-beta3-build3402";
|
||||||
|
public const string XUnitRunnerPackageName = "xunit.runner.visualstudio";
|
||||||
|
public const string XUnitRunnerPackageVersion = "2.2.0-beta4-build1188";
|
||||||
|
|
||||||
public static readonly IDictionary<string, string> AspProjectDependencyToolsPackages = new Dictionary<string, string> {
|
public static readonly IDictionary<string, string> AspProjectDependencyToolsPackages = new Dictionary<string, string> {
|
||||||
{"Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools"},
|
{"Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools"},
|
||||||
|
|
|
@ -18,6 +18,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
projectType = ProjectType.Web;
|
projectType = ProjectType.Web;
|
||||||
}
|
}
|
||||||
|
else if (project.IsTestProject)
|
||||||
|
{
|
||||||
|
projectType = ProjectType.Test;
|
||||||
|
}
|
||||||
|
|
||||||
return projectType;
|
return projectType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
internal enum ProjectType
|
internal enum ProjectType
|
||||||
{
|
{
|
||||||
Console,
|
Console,
|
||||||
Web
|
Web,
|
||||||
|
Test
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -86,7 +86,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
MigrationSettings migrationSettings,
|
MigrationSettings migrationSettings,
|
||||||
ProjectItemGroupElement noFrameworkPackageReferenceItemGroup)
|
ProjectItemGroupElement noFrameworkPackageReferenceItemGroup)
|
||||||
{
|
{
|
||||||
var type = migrationRuleInputs.DefaultProjectContext.ProjectFile.GetProjectType();
|
var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;
|
||||||
|
var type = project.GetProjectType();
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ProjectType.Web:
|
case ProjectType.Web:
|
||||||
|
@ -101,6 +102,40 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
noFrameworkPackageReferenceItemGroup,
|
noFrameworkPackageReferenceItemGroup,
|
||||||
mergeExisting: false);
|
mergeExisting: false);
|
||||||
break;
|
break;
|
||||||
|
case ProjectType.Test:
|
||||||
|
_transformApplicator.Execute(
|
||||||
|
PackageDependencyInfoTransform().Transform(
|
||||||
|
new PackageDependencyInfo
|
||||||
|
{
|
||||||
|
Name = PackageConstants.TestSdkPackageName,
|
||||||
|
Version = PackageConstants.TestSdkPackageVersion
|
||||||
|
}),
|
||||||
|
noFrameworkPackageReferenceItemGroup,
|
||||||
|
mergeExisting: false);
|
||||||
|
|
||||||
|
if (project.TestRunner.Equals("xunit", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
_transformApplicator.Execute(
|
||||||
|
PackageDependencyInfoTransform().Transform(
|
||||||
|
new PackageDependencyInfo
|
||||||
|
{
|
||||||
|
Name = PackageConstants.XUnitPackageName,
|
||||||
|
Version = PackageConstants.XUnitPackageVersion
|
||||||
|
}),
|
||||||
|
noFrameworkPackageReferenceItemGroup,
|
||||||
|
mergeExisting: false);
|
||||||
|
|
||||||
|
_transformApplicator.Execute(
|
||||||
|
PackageDependencyInfoTransform().Transform(
|
||||||
|
new PackageDependencyInfo
|
||||||
|
{
|
||||||
|
Name = PackageConstants.XUnitRunnerPackageName,
|
||||||
|
Version = PackageConstants.XUnitRunnerPackageVersion
|
||||||
|
}),
|
||||||
|
noFrameworkPackageReferenceItemGroup,
|
||||||
|
mergeExisting: false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,5 +257,96 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
items = itemGroup.First().Items.ToArray();
|
items = itemGroup.First().Items.ToArray();
|
||||||
items[0].Include.Should().Be("System");
|
items[0].Include.Should().Be("System");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void It_migrates_test_projects_to_have_test_sdk()
|
||||||
|
{
|
||||||
|
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"));
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => (i.Include == "xunit" && i.ItemType == "PackageReference"));
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void It_migrates_test_projects_to_have_test_sdk_and_xunit_packagedependencies()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||||
|
{
|
||||||
|
""buildOptions"": {
|
||||||
|
""emitEntryPoint"": true
|
||||||
|
},
|
||||||
|
""frameworks"": {
|
||||||
|
""netcoreapp1.0"": {}
|
||||||
|
},
|
||||||
|
""testRunner"": ""xunit""
|
||||||
|
}");
|
||||||
|
|
||||||
|
mockProj.Items.Should().ContainSingle(
|
||||||
|
i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference"));
|
||||||
|
|
||||||
|
mockProj.Items.Should().ContainSingle(
|
||||||
|
i => (i.Include == "xunit" && i.ItemType == "PackageReference"));
|
||||||
|
|
||||||
|
mockProj.Items.Should().ContainSingle(
|
||||||
|
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs)
|
||||||
|
{
|
||||||
|
foreach (var packageSpec in packageSpecs)
|
||||||
|
{
|
||||||
|
var packageName = packageSpec.Item1;
|
||||||
|
var packageVersion = packageSpec.Item2;
|
||||||
|
var packageTFM = packageSpec.Item3;
|
||||||
|
|
||||||
|
var items = mockProj.Items
|
||||||
|
.Where(i => i.ItemType == "PackageReference")
|
||||||
|
.Where(i => string.IsNullOrEmpty(packageTFM) || i.ConditionChain().Any(c => c.Contains(packageTFM)))
|
||||||
|
.Where(i => i.Include == packageName)
|
||||||
|
.Where(i => i.GetMetadataWithName("Version").Value == packageVersion);
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmitsToolReferences(ProjectRootElement mockProj, params Tuple<string, string>[] toolSpecs)
|
||||||
|
{
|
||||||
|
foreach (var toolSpec in toolSpecs)
|
||||||
|
{
|
||||||
|
var packageName = toolSpec.Item1;
|
||||||
|
var packageVersion = toolSpec.Item2;
|
||||||
|
|
||||||
|
var items = mockProj.Items
|
||||||
|
.Where(i => i.ItemType == "DotNetCliToolReference")
|
||||||
|
.Where(i => i.Include == packageName)
|
||||||
|
.Where(i => i.GetMetadataWithName("Version").Value == packageVersion);
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProjectRootElement RunPackageDependenciesRuleOnPj(string s, string testDirectory = null)
|
||||||
|
{
|
||||||
|
testDirectory = testDirectory ?? Temp.CreateDirectory().Path;
|
||||||
|
return TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]
|
||||||
|
{
|
||||||
|
new MigratePackageDependenciesAndToolsRule()
|
||||||
|
}, s, testDirectory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue