diff --git a/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs b/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs index 5b31aa212..3589be785 100644 --- a/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs +++ b/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs @@ -6,13 +6,14 @@ using System.IO; using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; +using System.Linq; namespace Microsoft.DotNet.Cli.Build.Tests { public class GivenDotnetBuildBuildsCsproj : TestBase { [Fact] - public void It_builds_a_runnable_output() + public void ItBuildsARunnableOutput() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssets.Get(testAppName) @@ -36,5 +37,40 @@ namespace Microsoft.DotNet.Cli.Build.Tests .Should().Pass() .And.HaveStdOutContaining("Hello World"); } + + [Fact] + public void ItRunsWhenRestoringToSpecificPackageDir() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + + string dir = "pkgs"; + string args = $"--packages {dir}"; + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should() + .Pass(); + + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .Execute(args) + .Should() + .Pass() + .And.NotHaveStdErr(); + + new BuildCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should().Pass(); + + var outputDll = Directory.EnumerateFiles(Path.Combine(rootPath, "bin"), "*.dll", SearchOption.AllDirectories).Single(); + + var outputRunCommand = new TestCommand("dotnet"); + + outputRunCommand.ExecuteWithCapturedOutput(outputDll) + .Should().Pass() + .And.HaveStdOutContaining("Hello World"); + } } } diff --git a/test/dotnet-pack.Tests/PackTests.cs b/test/dotnet-pack.Tests/PackTests.cs index 10e9cf3a6..661ce5fd8 100644 --- a/test/dotnet-pack.Tests/PackTests.cs +++ b/test/dotnet-pack.Tests/PackTests.cs @@ -207,6 +207,38 @@ namespace Microsoft.DotNet.Tools.Pack.Tests Assert.Equal("true", node.Value); } + [Fact] + public void ItPacksAppWhenRestoringToSpecificPackageDirectory() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + var rootDir = new DirectoryInfo(rootPath); + + string dir = "pkgs"; + string args = $"--packages {dir}"; + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should() + .Pass(); + + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .Execute(args) + .Should() + .Pass(); + + new PackCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + + rootDir + .GetDirectory("bin") + .Should().HaveFilesMatching("*.nupkg", SearchOption.AllDirectories); + } + private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir) { // copy all the files to temp dir diff --git a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs index 483b3d31a..b48022c26 100644 --- a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs +++ b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs @@ -75,5 +75,44 @@ namespace Microsoft.DotNet.Cli.Publish.Tests .Should().Pass() .And.HaveStdOutContaining("Hello World"); } + + [Fact] + public void ItPublishesAppWhenRestoringToSpecificPackageDirectory() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + var rootDir = new DirectoryInfo(rootPath); + + string dir = "pkgs"; + string args = $"--packages {dir}"; + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should() + .Pass(); + + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .Execute(args) + .Should() + .Pass(); + + new PublishCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput() + .Should().Pass(); + + var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); + var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; + + var outputProgram = rootDir + .GetDirectory("bin", configuration, "netcoreapp1.0", "publish", $"{rootDir.Name}.dll") + .FullName; + + new TestCommand(outputProgram) + .ExecuteWithCapturedOutput() + .Should().Pass() + .And.HaveStdOutContaining("Hello World"); + } } } diff --git a/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs new file mode 100644 index 000000000..6113b1485 --- /dev/null +++ b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs @@ -0,0 +1,89 @@ +// 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; +using System.Collections.Generic; +using System.IO; +using Microsoft.Build.Construction; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; +using FluentAssertions; +using System.Linq; + +namespace Microsoft.DotNet.Restore.Tests +{ + public class GivenThatIWantToRestoreApp : TestBase + { + [Fact] + public void ItRestoresAppToSpecificDirectory() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + + string dir = "pkgs"; + string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should() + .Pass(); + + string args = $"--packages \"{dir}\""; + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput(args) + .Should() + .Pass() + .And.NotHaveStdErr(); + + Directory.Exists(fullPath).Should().BeTrue(); + Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0); + } + + [Fact] + public void ItRestoresLibToSpecificDirectory() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + + string dir = "pkgs"; + string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute("-t lib") + .Should() + .Pass(); + + string args = $"--packages \"{dir}\""; + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput(args) + .Should() + .Pass() + .And.NotHaveStdErr(); + + Directory.Exists(fullPath).Should().BeTrue(); + Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0); + } + + [Fact] + public void ItRestoresTestAppToSpecificDirectory() + { + var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName; + + string dir = "pkgs"; + string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); + + string args = $"--packages \"{dir}\""; + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput(args) + .Should() + .Pass() + .And.NotHaveStdErr(); + + Directory.Exists(fullPath).Should().BeTrue(); + Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0); + } + } +} diff --git a/test/dotnet-restore.Tests/MSBuild.exe b/test/dotnet-restore.Tests/MSBuild.exe new file mode 100644 index 000000000..9bda258ef --- /dev/null +++ b/test/dotnet-restore.Tests/MSBuild.exe @@ -0,0 +1 @@ +https://github.com/Microsoft/msbuild/issues/927 diff --git a/test/dotnet-restore.Tests/MSBuild.exe.config b/test/dotnet-restore.Tests/MSBuild.exe.config new file mode 100644 index 000000000..9bda258ef --- /dev/null +++ b/test/dotnet-restore.Tests/MSBuild.exe.config @@ -0,0 +1 @@ +https://github.com/Microsoft/msbuild/issues/927 diff --git a/test/dotnet-restore.Tests/dotnet-restore.Tests.csproj b/test/dotnet-restore.Tests/dotnet-restore.Tests.csproj new file mode 100644 index 000000000..8f26f5b76 --- /dev/null +++ b/test/dotnet-restore.Tests/dotnet-restore.Tests.csproj @@ -0,0 +1,81 @@ + + + + + + netcoreapp1.0 + true + dotnet-restore.Tests + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + + + + + + + + + + + + + + true + + + true + + + true + + + true + + + true + + + true + + + + + + true + + + + + + $(CLI_NETSDK_Version) + All + + + 15.0.0-preview-20161024-02 + + + 2.2.0-beta4-build1194 + + + 1.0.1 + + + $(CLI_MSBuild_Version) + + + 2.2.0-beta4-build3444 + + + 1.0.1-beta-000933 + + + 4.0.0 + + + + + $(DefineConstants);RELEASE + + + + diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index 4f5df3aca..3070f4cb5 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -78,7 +78,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests } [Fact] - public void It_runs_portable_apps_from_a_different_path_after_building() + public void ItRunsPortableAppsFromADifferentPathAfterBuilding() { var testInstance = TestAssets.Get("MSBuildTestApp") .CreateInstance() @@ -98,7 +98,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests } [Fact] - public void It_runs_portable_apps_from_a_different_path_without_building() + public void ItRunsPortableAppsFromADifferentPathWithoutBuilding() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssets.Get(testAppName) @@ -113,6 +113,33 @@ namespace Microsoft.DotNet.Cli.Run.Tests .ExecuteWithCapturedOutput($"--project {projectFile.FullName}") .Should().Pass() .And.HaveStdOutContaining("Hello World!"); - } + } + + [Fact] + public void ItRunsAppWhenRestoringToSpecificPackageDirectory() + { + var rootPath = TestAssetsManager.CreateTestDirectory().Path; + + string dir = "pkgs"; + string args = $"--packages {dir}"; + + new NewCommand() + .WithWorkingDirectory(rootPath) + .Execute() + .Should() + .Pass(); + + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .Execute(args) + .Should() + .Pass(); + + new RunCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput() + .Should().Pass() + .And.HaveStdOutContaining("Hello World"); + } } } \ No newline at end of file diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index ddb3f6b52..9a06b5d4f 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -139,5 +139,36 @@ namespace Microsoft.DotNet.Cli.Test.Tests Directory.Delete(trxLoggerDirectory, true); } } + + [Fact(Skip = "https://github.com/dotnet/cli/issues/5035")] + public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory() + { + var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName; + + string dir = "pkgs"; + string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); + + string args = $"--packages \"{dir}\""; + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .Execute(args) + .Should() + .Pass(); + + new BuildCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput() + .Should() + .Pass() + .And.NotHaveStdErr(); + + CommandResult result = new DotnetTestCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput(); + + result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0."); + result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest"); + result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest"); + } } }