Ensure dotnet restore --packages is working (#5008)

* add dotnet restore --packages tests

* add dotnet build, publish, pack, dotnet-test test

* Shorten the test name in attempt to fix test failure

* fix whitespaces
This commit is contained in:
Krzysztof Wicher 2016-12-18 00:45:25 -08:00 committed by Piotr Puszkiewicz
parent 9ad164a9dd
commit 476a83eb1a
9 changed files with 341 additions and 4 deletions

View file

@ -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");
}
}
}

View file

@ -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

View file

@ -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");
}
}
}

View file

@ -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);
}
}
}

View file

@ -0,0 +1 @@
https://github.com/Microsoft/msbuild/issues/927

View file

@ -0,0 +1 @@
https://github.com/Microsoft/msbuild/issues/927

View file

@ -0,0 +1,81 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dotnet-restore.Tests</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<EmbeddedResource Include="compiler\resources\**\*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Tools.Tests.Utilities\Microsoft.DotNet.Tools.Tests.Utilities.csproj" />
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Configurer\Microsoft.DotNet.Configurer.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\Microsoft.DotNet.ProjectJsonMigration.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Archive\Microsoft.DotNet.Archive.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime">
<FromP2P>true</FromP2P>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>$(CLI_NETSDK_Version)</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0-preview-20161024-02</Version>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<Version>2.2.0-beta4-build1194</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build">
<Version>$(CLI_MSBuild_Version)</Version>
</PackageReference>
<PackageReference Include="xunit">
<Version>2.2.0-beta4-build3444</Version>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions">
<Version>1.0.1-beta-000933</Version>
</PackageReference>
<PackageReference Include="FluentAssertions">
<Version>4.0.0</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -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");
}
}
}

View file

@ -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");
}
}
}