Beispiel #1
0
        protected NuGetFixture()
        {
            Environment = FakeEnvironment.CreateUnixEnvironment();

            Process = Substitute.For <IProcess>();
            Process.GetExitCode().Returns(0);
            ProcessRunner = Substitute.For <IProcessRunner>();
            ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process);

            Globber = Substitute.For <IGlobber>();
            Globber.Match("./tools/**/nuget.exe").Returns(new[] { (FilePath)"/Working/tools/NuGet.exe" });
            Globber.Match("./tools/**/NuGet.exe").Returns(new[] { (FilePath)"/Working/tools/NuGet.exe" });

            NuGetToolResolver = Substitute.For <INuGetToolResolver>();

            Log        = Substitute.For <ICakeLog>();
            FileSystem = new FakeFileSystem(Environment);

            // By default, there is a default tool.
            NuGetToolResolver.ResolvePath().Returns("/Working/tools/NuGet.exe");
            FileSystem.CreateFile("/Working/tools/NuGet.exe");

            // Set standard output.
            Process.GetStandardOutput().Returns(new string[0]);
        }
Beispiel #2
0
        public void GivenDefaultToolDoNotExist()
        {
            var toolPath = new FilePath("/Working/tools/NuGet.exe");

            FileSystem.EnsureFileDoNotExist(toolPath);
            NuGetToolResolver.ResolvePath().Returns("/NonWorking/tools/NuGet.exe");
        }
Beispiel #3
0
            public void Should_Resolve_In_Correct_Order()
            {
                // Given
                var environment = Substitute.For <ICakeEnvironment>();

                environment.WorkingDirectory.Returns("/Working");
                environment.IsUnix().Returns(false);
                environment.GetEnvironmentVariable("NUGET_EXE").Returns(c => null);
                environment.GetEnvironmentVariable("path").Returns(c => null);
                var fileSystem = new FakeFileSystem(environment);
                var globber    = Substitute.For <IGlobber>();

                globber.GetFiles("./tools/**/NuGet.exe").Returns(new FilePath[] { });
                var resolver = new NuGetToolResolver(fileSystem, environment, globber);

                // When
                Record.Exception(() => resolver.ResolvePath());

                // Then
                Received.InOrder(() =>
                {
                    // 1. Look in the tools directory.
                    globber.GetFiles("./tools/**/NuGet.exe");
                    // 2. Look for the environment variable NUGET_EXE.
                    environment.GetEnvironmentVariable("NUGET_EXE");
                    // 3. Panic and look in the path variable.
                    environment.GetEnvironmentVariable("path");
                });
            }
Beispiel #4
0
            public void Should_Be_Able_To_Resolve_Path_From_The_Tools_Directory()
            {
                // Given
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var fileSystem  = new FakeFileSystem(environment);
                var globber     = Substitute.For <IGlobber>();

                globber.Match("./tools/**/NuGet.exe").Returns(p => new FilePath[] { "/root/tools/nuget.exe" });
                fileSystem.CreateFile("/root/tools/nuget.exe");
                var resolver = new NuGetToolResolver(fileSystem, environment, globber);

                // When
                var result = resolver.ResolvePath();

                // Then
                Assert.Equal("/root/tools/nuget.exe", result.FullPath);
            }
Beispiel #5
0
            public void Should_Be_Able_To_Resolve_Path_Via_NuGet_Environment_Variable()
            {
                // Given
                var globber     = Substitute.For <IGlobber>();
                var environment = Substitute.For <ICakeEnvironment>();

                environment.WorkingDirectory.Returns("/Working");
                environment.IsUnix().Returns(false);
                environment.GetEnvironmentVariable("NUGET_EXE").Returns("/programs/nuget.exe");
                var fileSystem = new FakeFileSystem(environment);

                fileSystem.CreateFile("/programs/nuget.exe");
                var resolver = new NuGetToolResolver(fileSystem, environment, globber);

                // When
                var result = resolver.ResolvePath();

                // Then
                Assert.Equal("/programs/nuget.exe", result.FullPath);
            }
Beispiel #6
0
            public void Should_Throw_If_NuGet_Exe_Could_Not_Be_Found()
            {
                // Given
                var environment = Substitute.For <ICakeEnvironment>();

                environment.WorkingDirectory.Returns("/Working");
                environment.IsUnix().Returns(false);
                environment.GetEnvironmentVariable("NUGET_EXE").Returns(c => null);
                environment.GetEnvironmentVariable("path").Returns(c => null);
                var fileSystem = new FakeFileSystem(environment);
                var globber    = Substitute.For <IGlobber>();

                globber.GetFiles("./tools/**/NuGet.exe").Returns(new FilePath[] { });
                var resolver = new NuGetToolResolver(fileSystem, environment, globber);

                // When
                var result = Record.Exception(() => resolver.ResolvePath());

                // Assert
                Assert.IsCakeException(result, "Could not locate nuget.exe.");
            }
Beispiel #7
0
        public FilePath Resolve()
        {
            var resolver = new NuGetToolResolver(FileSystem, Environment, Tools);

            return(resolver.ResolvePath());
        }