From 5016aea90c15cfb595dc262aa10cfe46c2c4759e Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Mon, 10 Oct 2016 18:01:59 -0700 Subject: [PATCH] Add tests --- .../TestDirWithNoProjects/global.json | 0 .../GivenThatIWantToMigrateTestApps.cs | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 TestAssets/TestProjects/TestDirWithNoProjects/global.json diff --git a/TestAssets/TestProjects/TestDirWithNoProjects/global.json b/TestAssets/TestProjects/TestDirWithNoProjects/global.json new file mode 100644 index 000000000..e69de29bb diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 0d0ff8cdd..9a2a74379 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -268,8 +268,28 @@ namespace Microsoft.DotNet.Migration.Tests outputsIdentical.Should().BeTrue(); VerifyAllMSBuildOutputsRunnable(projectDirectory); } + + [Theory] + // https://github.com/dotnet/cli/issues/4313 + [InlineData("TestDirWithNoProjects", true)] + [InlineData("TestDirWithNoProjects", false)] + public void It_migrates_no_projects_found(string projectDir, bool useGlobalJson) + { + // The migrate command should return 1 for failure. + const int ExpectedResult = 1; - private void VerifyMigration(IEnumerable expectedProjects, string rootDir) + var projectDirectory = TestAssetsManager.CreateTestInstance(projectDir, callingMethod: "It_migrates_no_projects_found").WithLockFiles().Path; + if (useGlobalJson) + { + MigrateProject(new[] { Path.Combine(projectDirectory, "global.json") }, ExpectedResult); + } + else + { + MigrateProject(new[] { projectDirectory }, ExpectedResult); + } + } + + private void VerifyMigration(IEnumerable expectedProjects, string rootDir) { var migratedProjects = Directory.EnumerateFiles(rootDir, "project.json", SearchOption.AllDirectories) .Where(s => Directory.EnumerateFiles(Path.GetDirectoryName(s), "*.csproj").Count() == 1) @@ -384,12 +404,12 @@ namespace Microsoft.DotNet.Migration.Tests result.Should().Pass(); } - private void MigrateProject(string[] migrateArgs) + private void MigrateProject(string[] migrateArgs, int expectedResult = 0) { var result = MigrateCommand.Run(migrateArgs); - result.Should().Be(0); + result.Should().Be(expectedResult); } private void DotnetNew(string projectDirectory, string dotnetNewType)