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;
|
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(
|
2017-12-04 22:13:24 +00:00
|
|
|
$"Cannot find the tools executable path. Please ensure /myhome/executable/path is added to your PATH.{Environment.NewLine}" +
|
2017-11-27 18:45:43 +00:00
|
|
|
$"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}" +
|
2017-12-04 22:13:24 +00:00
|
|
|
$"export PATH=\"$PATH:/myhome/executable/path\"{Environment.NewLine}" +
|
2017-11-27 18:45:43 +00:00
|
|
|
$"EOF");
|
|
|
|
}
|
|
|
|
|
|
|
|
[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()
|
|
|
|
.Be(
|
|
|
|
"Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.");
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|