dotnet-installer/test/Microsoft.DotNet.ToolPackage.Tests/ToolConfigurationDeserializerTests.cs
Peter Huene aab9af71b8
Implement uninstall tool command.
This commit implements the `uninstall tool` command.

The `uninstall tool` command is responsible for uninstalling global tools that
are installed with the `install tool` command.

This commit heavily refactors the ToolPackage and ShellShim namespaces to
better support the operations required for the uninstall command.

Several string resources have been updated to be more informative or to correct
oddly structured sentences.

This commit also fixes `--version` on the install command not supporting ranges
and wildcards.

Fixes #8549.

Issue #8485 is partially fixed by this commit (`--prerelease` is not yet
implemented).
2018-02-19 22:46:16 -08:00

58 lines
2.2 KiB
C#

// 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 System.Linq;
using FluentAssertions;
using Microsoft.DotNet.Tools;
using NuGet.Protocol.Core.Types;
using Xunit;
namespace Microsoft.DotNet.ToolPackage.Tests
{
public class ToolConfigurationDeserializerTests
{
[Fact]
public void GivenXmlPathItShouldGetToolConfiguration()
{
ToolConfiguration toolConfiguration = ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsGolden.xml");
toolConfiguration.CommandName.Should().Be("sayhello");
toolConfiguration.ToolAssemblyEntryPoint.Should().Be("console.dll");
}
[Fact]
public void GivenMalformedPathItThrows()
{
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsMalformed.xml");
a.ShouldThrow<ToolConfigurationException>()
.And.Message.Should()
.Contain(string.Format(CommonLocalizableStrings.ToolSettingsInvalidXml, string.Empty));
}
[Fact]
public void GivenMissingContentItThrows()
{
Action a = () => ToolConfigurationDeserializer.Deserialize("DotnetToolSettingsMissing.xml");
a.ShouldThrow<ToolConfigurationException>()
.And.Message.Should()
.Contain(CommonLocalizableStrings.ToolSettingsMissingCommandName);
}
[Fact]
public void GivenInvalidCharAsFileNameItThrows()
{
var invalidCommandName = "na\0me";
Action a = () => new ToolConfiguration(invalidCommandName, "my.dll");
a.ShouldThrow<ToolConfigurationException>()
.And.Message.Should()
.Contain(
string.Format(
CommonLocalizableStrings.ToolSettingsInvalidCommandName,
invalidCommandName,
string.Join(", ", Path.GetInvalidFileNameChars().Select(c => $"'{c}'"))));
}
}
}