2017-03-03 05:04:03 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Build.Construction;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|
|
|
|
{
|
2016-09-23 00:16:37 +00:00
|
|
|
|
public class GivenThatIWantToMigrateTFMs : TestBase
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2017-02-16 21:10:19 +00:00
|
|
|
|
[Fact(Skip="Emitting this until x-targeting full support is in")]
|
2016-12-19 02:45:35 +00:00
|
|
|
|
public void MigratingNetcoreappProjectDoesNotPopulateTargetFrameworkIdentifierAndTargetFrameworkVersion()
|
2016-09-15 22:54:10 +00:00
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2016-09-15 22:54:10 +00:00
|
|
|
|
.FromTestAssetBase("TestAppWithRuntimeOptions")
|
|
|
|
|
.WithCustomProperty("buildOptions", new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "emitEntryPoint", "false" }
|
|
|
|
|
})
|
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
|
|
|
|
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
2016-09-16 23:37:48 +00:00
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
new[] { projectContext },
|
|
|
|
|
mockProj,
|
2016-09-16 23:37:48 +00:00
|
|
|
|
mockProj.AddItemGroup(),
|
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
2016-09-15 22:54:10 +00:00
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(0);
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 21:30:56 +00:00
|
|
|
|
[Fact]
|
2016-12-19 02:45:35 +00:00
|
|
|
|
public void MigratingMultiTFMProjectPopulatesTargetFrameworksWithShortTfms()
|
2016-09-15 22:54:10 +00:00
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2016-09-15 22:54:10 +00:00
|
|
|
|
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
|
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
2016-09-23 00:16:37 +00:00
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
2016-09-15 22:54:10 +00:00
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
2016-09-16 23:37:48 +00:00
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
2016-09-16 23:37:48 +00:00
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
2016-09-15 22:54:10 +00:00
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
|
2016-09-16 23:37:48 +00:00
|
|
|
|
mockProj.Properties.First(p => p.Name == "TargetFrameworks")
|
|
|
|
|
.Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
|
2016-09-15 22:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 22:07:35 +00:00
|
|
|
|
[Fact]
|
2017-02-17 19:30:20 +00:00
|
|
|
|
public void MigratingCoreAndDesktopTFMsDoesNoAddRuntimeIdentifiersOrRuntimeIdentifierWhenTheProjectDoesNothaveAnyAlready()
|
2016-11-15 22:07:35 +00:00
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2017-01-12 01:05:12 +00:00
|
|
|
|
.FromTestAssetBase("PJAppWithMultipleFrameworks")
|
2016-11-15 22:07:35 +00:00
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
2016-11-15 22:07:35 +00:00
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
2016-11-15 22:07:35 +00:00
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
|
|
|
|
|
2017-02-17 19:30:20 +00:00
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0);
|
2017-01-05 22:01:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 21:30:56 +00:00
|
|
|
|
[Fact]
|
2016-12-19 02:45:35 +00:00
|
|
|
|
public void MigrateTFMRuleDoesNotAddRuntimesWhenMigratingDesktopTFMsWithRuntimesAlready()
|
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2016-12-19 02:45:35 +00:00
|
|
|
|
.FromTestAssetBase("TestAppWithMultipleFrameworksAndRuntimes")
|
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
|
|
|
|
var migrationSettings =
|
|
|
|
|
MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
2016-12-19 02:45:35 +00:00
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 22:01:30 +00:00
|
|
|
|
[Fact]
|
2017-02-17 19:30:20 +00:00
|
|
|
|
public void MigratingProjectWithFullFrameworkTFMsDoesNotAddRuntimeIdentifiersOrRuntimeIdentiferWhenNoRuntimesExistAlready()
|
2017-01-05 22:01:30 +00:00
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2017-02-28 21:11:34 +00:00
|
|
|
|
.FromTestAssetBase("AppWith4netTfm0Rid")
|
2017-01-05 22:01:30 +00:00
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
|
|
|
|
var migrationSettings =
|
|
|
|
|
MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
2017-01-05 22:01:30 +00:00
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
|
2017-02-17 19:30:20 +00:00
|
|
|
|
mockProj.Properties.Where(p => p.Name == "RuntimeIdentifier").Should().HaveCount(0);
|
2017-01-05 22:01:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 02:45:35 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MigratingSingleTFMProjectPopulatesTargetFramework()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2016-08-23 20:50:05 +00:00
|
|
|
|
.FromTestAssetBase("TestAppWithRuntimeOptions")
|
2016-08-22 19:24:10 +00:00
|
|
|
|
.WithCustomProperty("buildOptions", new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "emitEntryPoint", "false" }
|
|
|
|
|
})
|
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
2016-09-23 00:16:37 +00:00
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
|
|
|
|
// Run BuildOptionsRule
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
2016-09-16 23:37:48 +00:00
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
2017-03-03 05:04:03 +00:00
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
2016-09-16 23:37:48 +00:00
|
|
|
|
mockProj.AddPropertyGroup());
|
2016-09-19 16:16:36 +00:00
|
|
|
|
|
2016-09-16 23:37:48 +00:00
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
2016-09-23 00:16:37 +00:00
|
|
|
|
Console.WriteLine(mockProj.RawXml);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-10-18 22:00:37 +00:00
|
|
|
|
mockProj.Properties.Count(p => p.Name == "TargetFramework").Should().Be(1);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
2017-01-12 01:05:12 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes()
|
|
|
|
|
{
|
|
|
|
|
var testDirectory = Temp.CreateDirectory().Path;
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testPJ = new ProjectJsonBuilder(TestAssets)
|
2017-01-12 01:05:12 +00:00
|
|
|
|
.FromTestAssetBase("PJLibWithMultipleFrameworks")
|
|
|
|
|
.SaveToDisk(testDirectory);
|
|
|
|
|
|
|
|
|
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
|
|
|
|
|
var migrationSettings =
|
|
|
|
|
MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
|
|
|
|
|
var migrationInputs = new MigrationRuleInputs(
|
|
|
|
|
projectContexts,
|
|
|
|
|
mockProj,
|
|
|
|
|
mockProj.AddItemGroup(),
|
|
|
|
|
mockProj.AddPropertyGroup());
|
|
|
|
|
|
|
|
|
|
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
|
|
|
|
|
|
|
|
|
|
var reason = "Should not add runtime identifiers for libraries";
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0, reason);
|
|
|
|
|
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0, reason);
|
|
|
|
|
}
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|