Esempio n. 1
0
        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/paths.d");

            provider
            .Setup(p => p.GetEnvironmentVariable("PATH"))
            .Returns(pathValue);

            var environmentPath = new OSXEnvironmentPath(
                toolsPath,
                reporter,
                provider.Object,
                fileSystem.File);

            environmentPath.AddPackageExecutablePathToUserPath();

            reporter.Lines.Should().BeEmpty();

            fileSystem
            .File
            .ReadAllText(OSXEnvironmentPath.DotnetCliToolsPathsDPath)
            .Should()
            .Be(toolsPath.PathWithTilde);
        }
Esempio n. 2
0
        public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath()
        {
            var fakeReporter       = new FakeReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                @"~/executable/path",
                @"/Users/name/executable/path",
                fakeReporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", "" }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            // similar to https://code.visualstudio.com/docs/setup/mac
            fakeReporter.Message.Should().Be(
                $"Cannot find the tools executable path. Please ensure /Users/name/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:/Users/name/executable/path\"{Environment.NewLine}" +
                $"EOF");
        }
Esempio n. 3
0
        public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists(string existingPath)
        {
            var fakeReporter       = new FakeReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                new BashPathUnderHomeDirectory("/myhome", "executable/path"),
                fakeReporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", existingPath }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            fakeReporter.Message.Should().BeEmpty();
        }
Esempio n. 4
0
        public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists(string existingPath)
        {
            var fakeReporter       = new FakeReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                @"~/executable/path",
                @"/Users/name/executable/path",
                fakeReporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", existingPath }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            fakeReporter.Message.Should().BeEmpty();
        }
Esempio n. 5
0
        public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout()
        {
            var reporter           = new BufferedReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                new BashPathUnderHomeDirectory("/myhome", "executable/path"),
                reporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", @"" }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.AddPackageExecutablePathToUserPath();

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathOSXNeedReopen);
        }
Esempio n. 6
0
        public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout()
        {
            var fakeReporter       = new FakeReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                new BashPathUnderHomeDirectory("/myhome", "executable/path"),
                fakeReporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", @"" }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.AddPackageExecutablePathToUserPath();

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            fakeReporter.Message.Should().Be(
                "Since you just installed the .NET Core SDK, you will need to reopen terminal before running the tool you installed.");
        }
Esempio n. 7
0
        public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath()
        {
            var reporter           = new BufferedReporter();
            var osxEnvironmentPath = new OSXEnvironmentPath(
                new BashPathUnderHomeDirectory("/myhome", "executable/path"),
                reporter,
                new FakeEnvironmentProvider(
                    new Dictionary <string, string>
            {
                { "PATH", "" }
            }),
                FakeFile.Empty);

            osxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            // similar to https://code.visualstudio.com/docs/setup/mac
            reporter.Lines.Should().Equal(
                string.Format(
                    CommonLocalizableStrings.EnvironmentPathOSXManualInstruction,
                    "/myhome/executable/path", "/myhome/executable/path"));
        }
Esempio n. 8
0
        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 OSXEnvironmentPath(
                toolsPath,
                reporter,
                provider.Object,
                FileSystemMockBuilder.Empty.File);

            environmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            reporter.Lines.Should().BeEmpty();
        }
Esempio n. 9
0
        public void GivenPathNotSetAndProfileExistsItPrintsReopenMessage()
        {
            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 OSXEnvironmentPath(
                toolsPath,
                reporter,
                provider.Object,
                new FileSystemMockBuilder()
                .AddFile(OSXEnvironmentPath.DotnetCliToolsPathsDPath, "")
                .Build()
                .File);

            environmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathOSXNeedReopen);
        }
Esempio n. 10
0
        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 OSXEnvironmentPath(
                toolsPath,
                reporter,
                provider.Object,
                FileSystemMockBuilder.Empty.File);

            environmentPath.PrintAddPathInstructionIfPathDoesNotExist();

            reporter.Lines.Should().Equal(
                string.Format(
                    CommonLocalizableStrings.EnvironmentPathOSXManualInstructions,
                    toolsPath.Path));
        }