public void GivenSecurityExceptionItPrintsWarning() { var reporter = new BufferedReporter(); var toolsPath = @"C:\Tools"; var pathValue = @"C:\Other"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable( "PATH", It.Is <EnvironmentVariableTarget>(t => t == EnvironmentVariableTarget.Process || t == EnvironmentVariableTarget.User || t == EnvironmentVariableTarget.Machine))) .Returns(pathValue); provider .Setup(p => p.SetEnvironmentVariable("PATH", pathValue + ";" + toolsPath, EnvironmentVariableTarget.User)) .Throws(new System.Security.SecurityException()); var environmentPath = new WindowsEnvironmentPath(toolsPath, reporter, provider.Object); environmentPath.AddPackageExecutablePathToUserPath(); reporter.Lines.Should().Equal( string.Format( CommonLocalizableStrings.FailedToSetToolsPathEnvironmentVariable, toolsPath).Yellow()); }
public void GivenPathNotSetInProcessItPrintsReopenNotice() { var reporter = new BufferedReporter(); var toolsPath = @"C:\Tools"; var pathValue = @"C:\Other"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process)) .Returns(pathValue); provider .Setup(p => p.GetEnvironmentVariable( "PATH", It.Is <EnvironmentVariableTarget>(t => t == EnvironmentVariableTarget.User || t == EnvironmentVariableTarget.Machine))) .Returns(pathValue + ";" + toolsPath); var environmentPath = new WindowsEnvironmentPath(toolsPath, reporter, provider.Object); environmentPath.PrintAddPathInstructionIfPathDoesNotExist(); reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathWindowsNeedReopen); }
public WindowsEnvironmentPathTests() { _reporter = new BufferedReporter(); _mockPathInternal = new MockPathInternal(); var mockEnvironmentProvider = new MockEnvironmentProvider(_mockPathInternal); var mockEnvironmentPathEditor = new MockEnvironmentPathEditor(_mockPathInternal); _windowsEnvironmentPath = new WindowsEnvironmentPath( _toolsPath, CliFolderPathCalculator.WindowsNonExpandedToolsShimPath, mockEnvironmentProvider, mockEnvironmentPathEditor, _reporter ); }
public WindowsEnvironmentPathTests() { _reporter = new BufferedReporter(); _mockPathInternal = new MockPathInternal(); var mockEnvironmentProvider = new MockEnvironmentProvider(_mockPathInternal); var mockEnvironmentPathEditor = new MockEnvironmentPathEditor(_mockPathInternal); _windowsEnvironmentPath = new WindowsEnvironmentPath( _toolsPath, @"%USERPROFILE%\.dotnet\tools", mockEnvironmentProvider, mockEnvironmentPathEditor, _reporter ); }
public void GivenPathSetItDoesNotAddPathToEnvironment() { var reporter = new BufferedReporter(); var toolsPath = @"C:\Tools"; var pathValue = @"C:\Other"; var provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict); provider .Setup(p => p.GetEnvironmentVariable( "PATH", It.Is <EnvironmentVariableTarget>(t => t == EnvironmentVariableTarget.Process || t == EnvironmentVariableTarget.User || t == EnvironmentVariableTarget.Machine))) .Returns(pathValue + ";" + toolsPath); var environmentPath = new WindowsEnvironmentPath(toolsPath, reporter, provider.Object); environmentPath.AddPackageExecutablePathToUserPath(); reporter.Lines.Should().BeEmpty(); }