Add install tool command (#8132)

* compose all the parts

* Fix on obtain and shim maker for better end to end experience
  * Fix error when there is space in the middle of path of nuget config
  * Fix path in profile.d is the tmp home path during install
  * better handle of ~home
  * remove profile.d file in uninstall script
  * Fix test since it looks up current directory
  * folder structure inside nupkg to tools/TFM/RID/mytool.dll
  * Add check for config file existence
  * Rename name space to Microsoft.DotNet.ShellShim
  * Rename name space to Microsoft.DotNet.ToolPackage
This commit is contained in:
William Lee 2017-12-04 14:13:24 -08:00 committed by GitHub
parent ea74bf1614
commit 55f62d9d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 587 additions and 204 deletions

View file

@ -82,9 +82,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-clean.Tests", "dotne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.TestFramework", "Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj", "{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ToolPackageObtainer.Tests", "Microsoft.DotNet.ToolPackageObtainer.Tests\Microsoft.DotNet.ToolPackageObtainer.Tests.csproj", "{C2A907A3-677B-4C73-9AA4-E53613E13C78}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ShellShim.Tests", "Microsoft.DotNet.ShellShim.Tests\Microsoft.DotNet.ShellShim.Tests.csproj", "{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ShellShimMaker.Tests", "Microsoft.DotNet.ShellShimMaker.Tests\Microsoft.DotNet.ShellShimMaker.Tests.csproj", "{1146EAAC-E434-404A-8198-B4F0CB23BC57}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ToolPackage.Tests", "Microsoft.DotNet.ToolPackage.Tests\Microsoft.DotNet.ToolPackage.Tests.csproj", "{453C809B-40FC-4A93-93B8-DE449D48B9FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -540,30 +540,30 @@ Global
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x64.Build.0 = Release|Any CPU
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x86.ActiveCfg = Release|Any CPU
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x86.Build.0 = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|x64.ActiveCfg = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|x64.Build.0 = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|x86.ActiveCfg = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Debug|x86.Build.0 = Debug|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|Any CPU.Build.0 = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|x64.ActiveCfg = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|x64.Build.0 = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|x86.ActiveCfg = Release|Any CPU
{C2A907A3-677B-4C73-9AA4-E53613E13C78}.Release|x86.Build.0 = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|x64.ActiveCfg = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|x64.Build.0 = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|x86.ActiveCfg = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Debug|x86.Build.0 = Debug|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|Any CPU.Build.0 = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|x64.ActiveCfg = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|x64.Build.0 = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|x86.ActiveCfg = Release|Any CPU
{1146EAAC-E434-404A-8198-B4F0CB23BC57}.Release|x86.Build.0 = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|x64.ActiveCfg = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|x64.Build.0 = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|x86.ActiveCfg = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Debug|x86.Build.0 = Debug|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|Any CPU.Build.0 = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|x64.ActiveCfg = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|x64.Build.0 = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|x86.ActiveCfg = Release|Any CPU
{1BBF0DFE-2138-4E29-BFA1-49A2F0B4C913}.Release|x86.Build.0 = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|x64.ActiveCfg = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|x64.Build.0 = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|x86.ActiveCfg = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Debug|x86.Build.0 = Debug|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|Any CPU.Build.0 = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|x64.ActiveCfg = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|x64.Build.0 = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|x86.ActiveCfg = Release|Any CPU
{453C809B-40FC-4A93-93B8-DE449D48B9FF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
internal class FakeEnvironmentProvider : IEnvironmentProvider
{

View file

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
internal class FakeFile : IFile
{

View file

@ -4,7 +4,7 @@
using System;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
internal class FakeReporter : IReporter
{

View file

@ -6,11 +6,12 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.DependencyModel.Tests;
using Xunit;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
public class LinuxEnvironmentPathTests
{
@ -19,7 +20,7 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
{
var fakeReporter = new FakeReporter();
var linuxEnvironmentPath = new LinuxEnvironmentPath(
@"executable\path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>
@ -32,11 +33,11 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
// similar to https://code.visualstudio.com/docs/setup/mac
fakeReporter.Message.Should().Be(
$"Cannot find the tools executable path. Please ensure executable\\path is added to your PATH.{Environment.NewLine}" +
$"Cannot find the tools executable path. Please ensure /myhome/executable/path is added to your PATH.{Environment.NewLine}" +
$"If you are using bash. You can do this by running the following command:{Environment.NewLine}{Environment.NewLine}" +
$"cat << EOF >> ~/.bash_profile{Environment.NewLine}" +
$"# Add .NET Core SDK tools{Environment.NewLine}" +
$"export PATH=\"$PATH:executable\\path\"{Environment.NewLine}" +
$"export PATH=\"$PATH:/myhome/executable/path\"{Environment.NewLine}" +
$"EOF");
}
@ -45,12 +46,12 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
{
var fakeReporter = new FakeReporter();
var linuxEnvironmentPath = new LinuxEnvironmentPath(
@"executable\path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>
{
{"PATH", @"executable\path"}
{"PATH", @"/myhome/executable/path"}
}),
FakeFile.Empty);
@ -64,7 +65,7 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
{
var fakeReporter = new FakeReporter();
var linuxEnvironmentPath = new LinuxEnvironmentPath(
@"executable\path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>
@ -76,7 +77,9 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
fakeReporter.Message.Should().Be("Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.");
fakeReporter.Message.Should()
.Be(
"Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.");
}
}
}

View file

@ -6,11 +6,12 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.DependencyModel.Tests;
using Xunit;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
public class OsxEnvironmentPathTests
{
@ -19,8 +20,7 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
{
var fakeReporter = new FakeReporter();
var osxEnvironmentPath = new OSXEnvironmentPath(
@"~/executable/path",
@"/Users/name/executable/path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>
@ -33,23 +33,22 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
// similar to https://code.visualstudio.com/docs/setup/mac
fakeReporter.Message.Should().Be(
$"Cannot find the tools executable path. Please ensure /Users/name/executable/path is added to your PATH.{Environment.NewLine}" +
$"Cannot find the tools executable path. Please ensure /myhome/executable/path is added to your PATH.{Environment.NewLine}" +
$"If you are using bash, You can do this by running the following command:{Environment.NewLine}{Environment.NewLine}" +
$"cat << EOF >> ~/.bash_profile{Environment.NewLine}" +
$"# Add .NET Core SDK tools{Environment.NewLine}" +
$"export PATH=\"$PATH:/Users/name/executable/path\"{Environment.NewLine}" +
$"export PATH=\"$PATH:/myhome/executable/path\"{Environment.NewLine}" +
$"EOF");
}
[Theory]
[InlineData("/Users/name/executable/path")]
[InlineData("/myhome/executable/path")]
[InlineData("~/executable/path")]
public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists(string existingPath)
{
var fakeReporter = new FakeReporter();
var osxEnvironmentPath = new OSXEnvironmentPath(
@"~/executable/path",
@"/Users/name/executable/path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>
@ -68,8 +67,7 @@ namespace Microsoft.DotNet.ShellShimMaker.Tests
{
var fakeReporter = new FakeReporter();
var osxEnvironmentPath = new OSXEnvironmentPath(
@"~/executable/path",
@"/Users/name/executable/path",
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
fakeReporter,
new FakeEnvironmentProvider(
new Dictionary<string, string>

View file

@ -12,7 +12,7 @@ using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.ShellShimMaker.Tests
namespace Microsoft.DotNet.ShellShim.Tests
{
public class ShellShimMakerTests : TestBase
{

View file

@ -24,13 +24,13 @@
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<None Update="DotnetToolsConfigMissing.xml">
<None Update="DotnetToolSettingsMissing.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="DotnetToolsConfigMalformed.xml">
<None Update="DotnetToolSettingsMalformed.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="DotnetToolsConfigGolden.xml">
<None Update="DotnetToolSettingsGolden.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestAssetLocalNugetFeed/*.*">
@ -47,7 +47,7 @@
<PropertyGroup>
<testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalTool</testAssetSourceRoot>
</PropertyGroup>
<Copy SourceFiles="SampleGlobalTool/DotnetToolsConfig.xml" DestinationFolder="$(testAssetSourceRoot)" />
<Copy SourceFiles="SampleGlobalTool/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />
<MSBuild BuildInParallel="False" Projects="SampleGlobalTool/consoledemo.csproj" Targets="Restore;Build;Publish" Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/">
</MSBuild>
<MSBuild BuildInParallel="False" Projects="SampleGlobalTool/consoledemo.csproj" Targets="pack" Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)/TestAssetLocalNugetFeed">

View file

@ -7,7 +7,7 @@
<authors>testauthor</authors>
</metadata>
<files>
<file src="bin\Release\netcoreapp2.1\publish\*.*" target="tools\netcoreapp2.1\" />
<file src="DotnetToolsConfig.xml" target="tools\DotnetToolsConfig.xml" />
<file src="bin\Release\netcoreapp2.1\publish\*.*" target="tools\netcoreapp2.1\any\" />
<file src="DotnetToolSettings.xml" target="tools\DotnetToolSettings.xml" />
</files>
</package>

View file

@ -9,14 +9,14 @@ using FluentAssertions;
using NuGet.Protocol.Core.Types;
using Xunit;
namespace Microsoft.DotNet.ToolPackageObtainer.Tests
namespace Microsoft.DotNet.ToolPackage.Tests
{
public class ToolConfigurationDeserializerTests
{
[Fact]
public void GivenXmlPathItShouldGetToolConfiguration()
{
ToolConfiguration toolConfiguration = ToolConfigurationDeserializer.Deserialize("DotnetToolsConfigGolden.xml");
ToolConfiguration toolConfiguration = ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsGolden.xml");
toolConfiguration.CommandName.Should().Be("sayhello");
toolConfiguration.ToolAssemblyEntryPoint.Should().Be("console.dll");
@ -25,28 +25,28 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
[Fact]
public void GivenMalformedPathItThrows()
{
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolsConfigMalformed.xml");
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsMalformed.xml");
a.ShouldThrow<ToolConfigurationException>()
.And.Message.Should()
.Contain("Failed to retrive tool configuration exception, configuration is malformed xml");
.Contain("The tool's settings file is invalid xml");
}
[Fact]
public void GivenMissingContentItThrows()
{
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolsConfigMissing.xml");
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsMissing.xml");
a.ShouldThrow<ToolConfigurationException>()
.And.Message.Should()
.Contain("Configuration content error");
.Contain("The tool's settings file contains error");
}
[Fact]
public void GivenInvalidCharAsFileNameItThrows()
{
Action a = () => new ToolConfiguration("na***me", "my.dll");
Action a = () => new ToolConfiguration("na\0me", "my.dll");
a.ShouldThrow<ArgumentException>()
.And.Message.Should()
.Contain("Cannot contain following character");
.Contain("Contains one or more invalid characters");
}
}
}

View file

@ -7,9 +7,10 @@ using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.EnvironmentAbstractions;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Tools.Install.Tool;
using Xunit;
namespace Microsoft.DotNet.ToolPackageObtainer.Tests
namespace Microsoft.DotNet.ToolPackage.Tests
{
public class ToolPackageObtainerTests : TestBase
{
@ -60,6 +61,7 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
.GetParentPath()
.GetParentPath()
.GetParentPath()
.GetParentPath()
.WithFile("project.assets.json").Value;
File.Exists(assetJsonPath)
@ -78,13 +80,10 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
Directory.CreateDirectory(tempProjectDirectory.Value);
/*
* No nuget config means you don't need nuget config passed in during call
* NuGet needs a way to find the package, in production, it will keep look up folders for Nuget.Config
* and use the feed there.
* In test, we don't want NuGet to keep look up, so we just copy paste beside the project.
* In test, we don't want NuGet to keep look up, so we point current directory to nugetconfig.
*/
File.Copy(nugetConfigPath.Value,
tempProjectDirectory.WithFile("nuget.config").Value);
Directory.SetCurrentDirectory(nugetConfigPath.GetDirectoryPath().Value);
var packageObtainer =
new ToolPackageObtainer(
@ -135,6 +134,29 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
.BeTrue(executable + " should have the executable");
}
[Fact]
public void GivenAllButNoPackageVersionAndInvokeTwiceItShouldNotThrow()
{
var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed();
var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName());
var packageObtainer =
ConstructDefaultPackageObtainer(toolsPath);
packageObtainer.ObtainAndReturnExecutablePath(
packageId: TestPackageId,
nugetconfig: nugetConfigPath,
targetframework: _testTargetframework);
Action secondCall = () => packageObtainer.ObtainAndReturnExecutablePath(
packageId: TestPackageId,
nugetconfig: nugetConfigPath,
targetframework: _testTargetframework);
secondCall.ShouldNotThrow();
}
[Fact]
public void GivenAllButNoTargetFrameworkItCanDownloadThePackage()
{
@ -166,6 +188,25 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
.BeTrue(executable + " should have the executable");
}
[Fact]
public void GivenNonExistentNugetConfigFileItThrows()
{
var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName());
var packageObtainer =
ConstructDefaultPackageObtainer(toolsPath);
Action a = () => packageObtainer.ObtainAndReturnExecutablePath(
packageId: TestPackageId,
packageVersion: TestPackageVersion,
nugetconfig: new FilePath("NonExistent.file"),
targetframework: _testTargetframework);
a.ShouldThrow<PackageObtainException>()
.And
.Message.Should().Contain("does not exist");
}
private static readonly Func<FilePath> GetUniqueTempProjectPathEachTest = () =>
{
var tempProjectDirectory =
@ -187,18 +228,24 @@ namespace Microsoft.DotNet.ToolPackageObtainer.Tests
private static FilePath WriteNugetConfigFileToPointToTheFeed()
{
var nugetConfigName = Path.GetRandomFileName() + ".config";
var nugetConfigName = "nuget.config";
var executeDirectory =
Path.GetDirectoryName(
System.Reflection
.Assembly
.GetExecutingAssembly()
.Location);
var tempPathForNugetConfigWithWhiteSpace =
Path.Combine(Path.GetTempPath(),
Path.GetRandomFileName() + " " + Path.GetRandomFileName());
Directory.CreateDirectory(tempPathForNugetConfigWithWhiteSpace);
NuGetConfig.Write(
directory: executeDirectory,
directory: tempPathForNugetConfigWithWhiteSpace,
configname: nugetConfigName,
localFeedPath: Path.Combine(executeDirectory, "TestAssetLocalNugetFeed"));
return new FilePath(Path.GetFullPath(nugetConfigName));
return new FilePath(Path.GetFullPath(Path.Combine(tempPathForNugetConfigWithWhiteSpace, nugetConfigName)));
}
private readonly string _testTargetframework = BundledTargetFramework.GetTargetFrameworkMoniker();

View file

@ -0,0 +1,52 @@
// 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.Linq;
using FluentAssertions;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Xunit;
using Xunit.Abstractions;
using Parser = Microsoft.DotNet.Cli.Parser;
namespace Microsoft.DotNet.Tests.ParserTests
{
public class InstallToolParserTests
{
private readonly ITestOutputHelper output;
public InstallToolParserTests(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void InstallGlobaltoolParserCanGetPackageIdAndPackageVersion()
{
var command = Parser.Instance;
var result = command.Parse("dotnet install tool console.test.app --version 1.0.1");
var parseResult = result["dotnet"]["install"]["tool"];
var packageId = parseResult.Arguments.Single();
var packageVersion = parseResult.ValueOrDefault<string>("version");
packageId.Should().Be("console.test.app");
packageVersion.Should().Be("1.0.1");
}
[Fact]
public void InstallGlobaltoolParserCanGetFollowingArguments()
{
var command = Parser.Instance;
var result =
command.Parse(
@"dotnet install tool console.test.app --version 1.0.1 --framework netcoreapp2.0 --configfile C:\TestAssetLocalNugetFeed");
var parseResult = result["dotnet"]["install"]["tool"];
parseResult.ValueOrDefault<string>("configfile").Should().Be(@"C:\TestAssetLocalNugetFeed");
parseResult.ValueOrDefault<string>("framework").Should().Be("netcoreapp2.0");
}
}
}