dotnet-installer/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs

200 lines
8.7 KiB
C#
Raw Normal View History

2016-08-22 12:24:10 -07:00
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration;
using Microsoft.DotNet.Internal.ProjectModel;
2016-08-22 12:24:10 -07: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 13:50:05 -07:00
using Microsoft.DotNet.ProjectJsonMigration.Rules;
2016-08-22 12:24:10 -07:00
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
2016-09-22 17:16:37 -07:00
public class GivenThatIWantToMigrateTFMs : TestBase
2016-08-22 12:24:10 -07:00
{
2016-09-19 09:16:36 -07:00
[Fact(Skip="Emitting this until x-targetting full support is in")]
public void MigratingNetcoreappProjectDoesNotPopulateTargetFrameworkIdentifierAndTargetFrameworkVersion()
2016-09-15 15:54:10 -07:00
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestAppWithRuntimeOptions")
.WithCustomProperty("buildOptions", new Dictionary<string, string>
{
{ "emitEntryPoint", "false" }
})
.SaveToDisk(testDirectory);
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
2016-09-16 16:37:48 -07:00
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
2016-09-15 15:54:10 -07:00
mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(0);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(0);
}
2016-09-22 14:30:56 -07:00
[Fact]
public void MigratingMultiTFMProjectPopulatesTargetFrameworksWithShortTfms()
2016-09-15 15:54:10 -07:00
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
.SaveToDisk(testDirectory);
2016-09-22 17:16:37 -07:00
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
2016-09-15 15:54:10 -07:00
var mockProj = ProjectRootElement.Create();
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
2016-09-16 16:37:48 -07:00
var migrationInputs = new MigrationRuleInputs(
2016-09-22 17:16:37 -07:00
projectContexts,
2016-09-16 16:37:48 -07:00
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
2016-09-15 15:54:10 -07:00
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
2016-09-16 16:37:48 -07:00
mockProj.Properties.First(p => p.Name == "TargetFrameworks")
.Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
2016-09-15 15:54:10 -07:00
}
[Fact]
public void MigratingCoreAndDesktopTFMsDoesNoAddRuntimeIdentifiersOrRuntimeIdentifierWhenTheProjectDoesNothaveAnyAlready()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("PJAppWithMultipleFrameworks")
.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);
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0);
}
2016-09-22 14:30:56 -07:00
[Fact]
public void MigrateTFMRuleDoesNotAddRuntimesWhenMigratingDesktopTFMsWithRuntimesAlready()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestAppWithMultipleFrameworksAndRuntimes")
.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);
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
}
[Fact]
public void MigratingProjectWithFullFrameworkTFMsDoesNotAddRuntimeIdentifiersOrRuntimeIdentiferWhenNoRuntimesExistAlready()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestAppWithMultipleFullFrameworksOnly")
.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);
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
mockProj.Properties.Where(p => p.Name == "RuntimeIdentifier").Should().HaveCount(0);
}
[Fact]
public void MigratingSingleTFMProjectPopulatesTargetFramework()
2016-08-22 12:24:10 -07:00
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
2016-08-23 13:50:05 -07:00
.FromTestAssetBase("TestAppWithRuntimeOptions")
2016-08-22 12:24:10 -07:00
.WithCustomProperty("buildOptions", new Dictionary<string, string>
{
{ "emitEntryPoint", "false" }
})
.SaveToDisk(testDirectory);
2016-09-22 17:16:37 -07:00
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
2016-08-22 12:24:10 -07:00
var mockProj = ProjectRootElement.Create();
// Run BuildOptionsRule
var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
2016-09-16 16:37:48 -07:00
var migrationInputs = new MigrationRuleInputs(
2016-09-22 17:16:37 -07:00
projectContexts,
2016-09-16 16:37:48 -07:00
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
2016-09-19 09:16:36 -07:00
2016-09-16 16:37:48 -07:00
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
2016-09-22 17:16:37 -07:00
Console.WriteLine(mockProj.RawXml);
2016-08-22 12:24:10 -07:00
mockProj.Properties.Count(p => p.Name == "TargetFramework").Should().Be(1);
2016-08-22 12:24:10 -07:00
}
[Fact]
public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.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 12:24:10 -07:00
}
}