public void GivenPathNotSetItAddsToEnvironment() { var reporter = new BufferedReporter(); var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools"); var pathValue = @"/usr/bin"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); IFileSystem fileSystem = new FileSystemMockBuilder().Build(); fileSystem.Directory.CreateDirectory("/etc/profile.d"); provider .Setup(p => p.GetEnvironmentVariable("PATH")) .Returns(pathValue); var environmentPath = new LinuxEnvironmentPath( toolsPath, reporter, provider.Object, fileSystem.File); environmentPath.AddPackageExecutablePathToUserPath(); reporter.Lines.Should().BeEmpty(); fileSystem .File .ReadAllText(LinuxEnvironmentPath.DotnetCliToolsProfilePath) .Should() .Be($"export PATH=\"$PATH:{toolsPath.PathWithDollar}\""); }
public void GivenPathSetItDoesNotAddPathToEnvironment() { var reporter = new BufferedReporter(); var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools"); var pathValue = @"/usr/bin"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); var fileSystem = new FileSystemMockBuilder().Build().File; provider .Setup(p => p.GetEnvironmentVariable("PATH")) .Returns(pathValue + ":" + toolsPath.Path); var environmentPath = new LinuxEnvironmentPath( toolsPath, reporter, provider.Object, fileSystem); environmentPath.AddPackageExecutablePathToUserPath(); reporter.Lines.Should().BeEmpty(); fileSystem .Exists(LinuxEnvironmentPath.DotnetCliToolsProfilePath) .Should() .Be(false); }
public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists() { var reporter = new BufferedReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( new BashPathUnderHomeDirectory("/myhome", "executable/path"), reporter, new FakeEnvironmentProvider( new Dictionary <string, string> { { "PATH", @"/myhome/executable/path" } }), FakeFile.Empty); linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should().BeEmpty(); }
public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists() { var fakeReporter = new FakeReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( @"executable\path", fakeReporter, new FakeEnvironmentProvider( new Dictionary <string, string> { { "PATH", @"executable\path" } }), FakeFile.Empty); linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist(); fakeReporter.Message.Should().BeEmpty(); }
public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout() { var fakeReporter = new FakeReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( @"executable\path", fakeReporter, new FakeEnvironmentProvider( new Dictionary <string, string> { { "PATH", @"" } }), FakeFile.Empty); linuxEnvironmentPath.AddPackageExecutablePathToUserPath(); 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."); }
public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout() { var reporter = new BufferedReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( new BashPathUnderHomeDirectory("/myhome", "executable/path"), reporter, new FakeEnvironmentProvider( new Dictionary <string, string> { { "PATH", @"" } }), FakeFile.Empty); linuxEnvironmentPath.AddPackageExecutablePathToUserPath(); linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should() .Equal(CommonLocalizableStrings.EnvironmentPathLinuxNeedLogout); }
public void GivenPathSetItPrintsNothing(string toolsDiretoryOnPath) { var reporter = new BufferedReporter(); var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools"); var pathValue = @"/usr/bin"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable("PATH")) .Returns(pathValue + ":" + toolsDiretoryOnPath); var environmentPath = new LinuxEnvironmentPath( toolsPath, reporter, provider.Object, FileSystemMockBuilder.Empty.File); environmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should().BeEmpty(); }
public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath() { var reporter = new BufferedReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( new BashPathUnderHomeDirectory("/myhome", "executable/path"), reporter, new FakeEnvironmentProvider( new Dictionary <string, string> { { "PATH", "" } }), FakeFile.Empty); linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist(); // similar to https://code.visualstudio.com/docs/setup/mac reporter.Lines.Should().Equal( string.Format( CommonLocalizableStrings.EnvironmentPathLinuxManualInstruction, "/myhome/executable/path", "/myhome/executable/path")); }
public void GivenPathNotSetAndProfileExistsItPrintsLogoutMessage() { var reporter = new BufferedReporter(); var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools"); var pathValue = @"/usr/bin"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable("PATH")) .Returns(pathValue); var environmentPath = new LinuxEnvironmentPath( toolsPath, reporter, provider.Object, new FileSystemMockBuilder() .AddFile(LinuxEnvironmentPath.DotnetCliToolsProfilePath, "") .Build() .File); environmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathLinuxNeedLogout); }
public void GivenPathNotSetItPrintsManualInstructions() { var reporter = new BufferedReporter(); var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools"); var pathValue = @"/usr/bin"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable("PATH")) .Returns(pathValue); var environmentPath = new LinuxEnvironmentPath( toolsPath, reporter, provider.Object, FileSystemMockBuilder.Empty.File); environmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should().Equal( string.Format( CommonLocalizableStrings.EnvironmentPathLinuxManualInstructions, toolsPath.Path)); }
public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath() { var fakeReporter = new FakeReporter(); var linuxEnvironmentPath = new LinuxEnvironmentPath( new BashPathUnderHomeDirectory("/myhome", "executable/path"), 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( $"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:/myhome/executable/path\"{Environment.NewLine}" + $"EOF"); }