Merge pull request #4979 from livarcocc/migrate_pj_without_frameworks

Show proper error message when migrating PJ without frameworks section.
This commit is contained in:
Livar 2016-12-09 10:14:22 -08:00 committed by GitHub
commit 08527184b2
4 changed files with 41 additions and 6 deletions

View file

@ -0,0 +1,8 @@
{
"dependencies": {
"Microsoft.VisualStudio.Web.CodeGeneration.Tools" : {
"version": "1.0.0-preview2-final",
"type": "build"
}
}
}

View file

@ -24,7 +24,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{
get
{
return ProjectContexts.First();
return ProjectContexts.FirstOrDefault();
}
}

View file

@ -55,7 +55,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{
new ProjectMigrationReport(
rootSettings.ProjectDirectory,
rootInputs?.DefaultProjectContext.GetProjectName(),
rootInputs?.DefaultProjectContext?.GetProjectName(),
new List<MigrationError> {e.Error},
null)
});
@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{
if (!projectContexts.Any())
{
MigrationErrorCodes.MIGRATE1013($"No projects found in {projectDirectory}").Throw();
MigrationErrorCodes.MIGRATE1013($"The project.json specifies no target frameworks in {projectDirectory}").Throw();
}
var defaultProjectContext = projectContexts.First();

View file

@ -16,7 +16,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public class GivenAProjectMigrator : TestBase
{
[Fact]
public void It_copies_ProjectDirectory_contents_to_OutputDirectory_when_the_directories_are_different()
public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent()
{
var testProjectDirectory = TestAssetsManager
.CreateTestInstance("PJTestAppSimple", callingMethod: "z")
@ -39,7 +39,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
[Fact]
public void It_has_error_when_migrating_a_deprecated_projectJson()
public void ItHasErrorWhenMigratingADeprecatedProjectJson()
{
var testProjectDirectory =
TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
@ -60,7 +60,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
[Fact]
public void It_has_error_when_migrating_a_non_csharp_app()
public void ItHasErrorWhenMigratingANonCsharpApp()
{
var testProjectDirectory =
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
@ -77,6 +77,33 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project");
}
[Fact]
public void ItHasErrorWhenMigratingAProjectJsonWithoutAFrameworks()
{
var testInstance = TestAssets.Get(
"NonRestoredTestProjects",
"TestLibraryWithProjectFileWithoutFrameworks")
.CreateInstance()
.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();
projectReport.Errors.First().GetFormattedErrorMessage()
.Should().Contain("MIGRATE1013::No Project:")
.And.Contain($"The project.json specifies no target frameworks in {testProjectDirectory}");
}
private IEnumerable<string> EnumerateFilesWithRelativePath(string testProjectDirectory)
{
return