2017-11-27 18:45:43 +00:00
|
|
|
// 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.Diagnostics;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using FluentAssertions;
|
2017-12-04 22:13:24 +00:00
|
|
|
using Microsoft.DotNet.Configurer;
|
2018-01-13 17:40:48 +00:00
|
|
|
using Microsoft.DotNet.Tools;
|
2017-11-27 18:45:43 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Microsoft.Extensions.DependencyModel.Tests;
|
|
|
|
using Xunit;
|
|
|
|
|
2017-12-04 22:13:24 +00:00
|
|
|
namespace Microsoft.DotNet.ShellShim.Tests
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
|
|
|
public class LinuxEnvironmentPathTests
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath()
|
|
|
|
{
|
|
|
|
var fakeReporter = new FakeReporter();
|
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2017-11-27 18:45:43 +00:00
|
|
|
fakeReporter,
|
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"PATH", ""}
|
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
// similar to https://code.visualstudio.com/docs/setup/mac
|
|
|
|
fakeReporter.Message.Should().Be(
|
2018-01-13 17:40:48 +00:00
|
|
|
string.Format(
|
|
|
|
CommonLocalizableStrings.EnvironmentPathLinuxManualInstruction,
|
|
|
|
"/myhome/executable/path", "/myhome/executable/path"));
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists()
|
|
|
|
{
|
|
|
|
var fakeReporter = new FakeReporter();
|
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2017-11-27 18:45:43 +00:00
|
|
|
fakeReporter,
|
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
2017-12-04 22:13:24 +00:00
|
|
|
{"PATH", @"/myhome/executable/path"}
|
2017-11-27 18:45:43 +00:00
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
fakeReporter.Message.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout()
|
|
|
|
{
|
|
|
|
var fakeReporter = new FakeReporter();
|
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2017-11-27 18:45:43 +00:00
|
|
|
fakeReporter,
|
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"PATH", @""}
|
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
linuxEnvironmentPath.AddPackageExecutablePathToUserPath();
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
2017-12-04 22:13:24 +00:00
|
|
|
fakeReporter.Message.Should()
|
2018-01-13 17:40:48 +00:00
|
|
|
.Be(CommonLocalizableStrings.EnvironmentPathLinuxNeedLogout);
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|