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 System;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
2017-01-26 19:00:50 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Common;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenAProjectMigrator : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2016-12-09 03:53:35 +00:00
|
|
|
|
public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent()
|
2016-08-23 20:50:05 +00:00
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testProjectDirectory = TestAssets.Get("PJTestAppSimple")
|
|
|
|
|
.CreateInstance(callingMethod: "z")
|
|
|
|
|
.WithSourceFiles().Root.FullName;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
var outputDirectory = Temp.CreateDirectory().Path;
|
|
|
|
|
|
|
|
|
|
var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory);
|
|
|
|
|
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, outputDirectory, mockProj);
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
|
|
|
|
projectMigrator.Migrate(testSettings);
|
|
|
|
|
|
|
|
|
|
foreach (var projectDirectoryRelativeFilePath in projectDirectoryRelativeFilePaths)
|
|
|
|
|
{
|
|
|
|
|
File.Exists(Path.Combine(outputDirectory, projectDirectoryRelativeFilePath)).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 20:53:29 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItHasWarningWhenMigratingADeprecatedProjectJson()
|
|
|
|
|
{
|
|
|
|
|
var testProjectDirectory = TestAssets
|
2017-01-29 01:14:17 +00:00
|
|
|
|
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompile")
|
2017-01-26 20:53:29 +00:00
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.Root
|
|
|
|
|
.GetDirectory("project")
|
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
mockProj);
|
|
|
|
|
|
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
|
|
|
|
var report = projectMigrator.Migrate(testSettings);
|
|
|
|
|
|
|
|
|
|
var projectReport = report.ProjectMigrationReports.First();
|
|
|
|
|
var warningMessage = projectReport.Warnings.First();
|
|
|
|
|
warningMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
|
|
|
|
|
warningMessage.Should().Contain("The 'compile' option is deprecated. Use 'compile' in 'buildOptions' instead. (line: 3, file:");
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 19:00:50 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson()
|
|
|
|
|
{
|
|
|
|
|
var testProjectDirectory = TestAssets
|
2017-01-29 01:14:17 +00:00
|
|
|
|
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedNamedResource")
|
2017-01-26 19:00:50 +00:00
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.Root
|
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
mockProj);
|
|
|
|
|
|
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
|
|
|
|
var report = projectMigrator.Migrate(testSettings);
|
|
|
|
|
|
|
|
|
|
var projectReport = report.ProjectMigrationReports.First();
|
|
|
|
|
var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();
|
|
|
|
|
errorMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
|
|
|
|
|
errorMessage.Should().Contain("The 'namedResource' option is deprecated. Use 'embed' in 'buildOptions' instead. (line: 3, file:");
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
[Fact]
|
2016-12-09 03:53:35 +00:00
|
|
|
|
public void ItHasErrorWhenMigratingANonCsharpApp()
|
2016-08-23 20:50:05 +00:00
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testProjectDirectory = TestAssets.Get("FSharpTestProjects")
|
|
|
|
|
.CreateInstance(callingMethod: "z")
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.Root.GetDirectory("TestApp").FullName;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
2016-12-07 21:49:15 +00:00
|
|
|
|
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, mockProj);
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
2016-10-04 21:59:04 +00:00
|
|
|
|
var report = projectMigrator.Migrate(testSettings);
|
|
|
|
|
var projectReport = report.ProjectMigrationReports.First();
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
2016-10-04 21:59:04 +00:00
|
|
|
|
var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();
|
|
|
|
|
errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project");
|
2016-08-23 20:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:53:35 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItHasErrorWhenMigratingAProjectJsonWithoutAFrameworks()
|
|
|
|
|
{
|
2016-12-09 04:06:55 +00:00
|
|
|
|
var testInstance = TestAssets.Get(
|
2017-03-03 04:35:20 +00:00
|
|
|
|
"NonRestoredTestProjects",
|
2016-12-09 04:06:55 +00:00
|
|
|
|
"TestLibraryWithProjectFileWithoutFrameworks")
|
|
|
|
|
.CreateInstance()
|
2016-12-09 03:53:35 +00:00
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
|
|
|
|
|
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
|
|
|
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
testProjectDirectory,
|
|
|
|
|
mockProj);
|
|
|
|
|
|
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
|
|
|
|
var report = projectMigrator.Migrate(testSettings);
|
|
|
|
|
|
|
|
|
|
var projectReport = report.ProjectMigrationReports.First();
|
|
|
|
|
|
2016-12-09 04:06:55 +00:00
|
|
|
|
projectReport.Errors.First().GetFormattedErrorMessage()
|
|
|
|
|
.Should().Contain("MIGRATE1013::No Project:")
|
|
|
|
|
.And.Contain($"The project.json specifies no target frameworks in {testProjectDirectory}");
|
2016-12-09 03:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
private IEnumerable<string> EnumerateFilesWithRelativePath(string testProjectDirectory)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
Directory.EnumerateFiles(testProjectDirectory, "*", SearchOption.AllDirectories)
|
|
|
|
|
.Select(file => PathUtility.GetRelativePath(testProjectDirectory, file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class FakeEmptyMigrationRule : IMigrationRule
|
|
|
|
|
{
|
|
|
|
|
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-03 04:35:20 +00:00
|
|
|
|
}
|