d6cab4af58
* Move dotnet-new templates to Sdk attribute * Update to MSBuild 15.1.0-preview-000454-01 To pick up a fix for Microsoft/msbuild#1431. * Fix template newlines * Fix casing on Microsoft.Net.Sdk * Move migration test csproj's to Sdk attribute * Disable parallel sdk restore Each SDK restore operation will try to manipulate the same assets.json file since the dependency name&version are injected into a common csproj file. This can cause runtime failures when two NuGets try to restore the project at once. * Make casing of SDK 'NET' and not 'Net' * Remove redundatn imports * Fix test string * Additional race * Replacing the SDK with the Web.Sdk when it is a Web project. * Fixing the test by writting the csproj before running the migration rule.
95 lines
No EOL
3.9 KiB
C#
95 lines
No EOL
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using FluentAssertions;
|
|
using Microsoft.Build.Construction;
|
|
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
|
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]
|
|
public void It_copies_ProjectDirectory_contents_to_OutputDirectory_when_the_directories_are_different()
|
|
{
|
|
var testProjectDirectory = TestAssetsManager
|
|
.CreateTestInstance("PJTestAppSimple", callingMethod: "z")
|
|
.Path;
|
|
|
|
var outputDirectory = Temp.CreateDirectory().Path;
|
|
|
|
var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory);
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, mockProj);
|
|
|
|
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
|
|
projectMigrator.Migrate(testSettings);
|
|
|
|
foreach (var projectDirectoryRelativeFilePath in projectDirectoryRelativeFilePaths)
|
|
{
|
|
File.Exists(Path.Combine(outputDirectory, projectDirectoryRelativeFilePath)).Should().BeTrue();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void It_has_error_when_migrating_a_deprecated_projectJson()
|
|
{
|
|
var testProjectDirectory =
|
|
TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
|
|
.Path;
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
var testSettings = new MigrationSettings(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 'packInclude' option is deprecated. Use 'files' in 'packOptions' instead. (line: 6, file:");
|
|
errorMessage.Should().Contain("The 'compilationOptions' option is deprecated. Use 'buildOptions' instead. (line: 3, file:");
|
|
}
|
|
|
|
[Fact]
|
|
public void It_has_error_when_migrating_a_non_csharp_app()
|
|
{
|
|
var testProjectDirectory =
|
|
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
|
|
.Path;
|
|
|
|
var mockProj = ProjectRootElement.Create();
|
|
var testSettings = new MigrationSettings(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("MIGRATE20013::Non-Csharp App: Cannot migrate project");
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |