public void ErrorDuringBootstrapperRetrievalThrowsAnException()
        {
            // arrange
            var fixture          = new CakePaketRestoreAliasFixture();
            var directory        = new DirectoryPath(Guid.NewGuid().ToString());
            var bootstrapperPath = new FilePath(Path.Combine(directory.FullPath, PaketBootstrapper));

            const string fakeUrl  = "http://localhost:9955";
            var          httpMock = HttpMockRepository.At(fakeUrl);

            CakePaketRestoreAlias.GithubUrlPath = fakeUrl;

            fixture.FileSysteMock.Setup(t => t.GetFile(bootstrapperPath).Exists).Returns(false);
            httpMock.Stub(x => x.Get(BootStrapperUrl))
            .AddHeader("X-RateLimit-Limit", "2")
            .AddHeader("X-RateLimit-Remaining", "1")
            .WithStatus(HttpStatusCode.BadRequest);

            var act = new Action(() => fixture.GetCakeContext.RetrievePaketBootstrapper(directory));

            // act
            // assert
            act.ShouldThrow <CakeException>("Failed to retrieve link for latest Paket Bootstrapper");

            DirectoryHelper.DeleteDirectory(directory.FullPath);
        }
        public void FailedPaketExecutableRetrievalShouldThrowAnException()
        {
            // arrange
            var fixture = new CakePaketRestoreAliasFixture(1);

            var act = new Action(() => fixture.GetCakeContext.RetrievePaketExecutable(fixture.GetDirectoryPath));

            // act
            // assert
            act.ShouldThrow <CakeException>("Error occured during Paket boostrapper execution");
        }
        public void FailedPaketUpdateShouldThrowAnException()
        {
            // arrange
            var fixture = new CakePaketRestoreAliasFixture(1);

            var act = new Action(() => fixture.GetCakeContext.PaketUpdate(fixture.GetDirectoryPath));

            // act
            // assert
            act.ShouldThrow <CakeException>("Error occured during Paket restore");
        }
        public void SuccessfulPaketUpdateShouldNotThrowAnException()
        {
            // arrange
            var passedArguments = string.Empty;
            var fixture         = new CakePaketRestoreAliasFixture();

            fixture.ProcessRunnerMock.Setup(t => t.Start(It.IsAny <FilePath>(), It.IsAny <ProcessSettings>())).Callback(
                (FilePath p, ProcessSettings t) => { passedArguments = t.Arguments.Render(); });

            var act = new Action(() => fixture.GetCakeContext.PaketUpdate(fixture.GetDirectoryPath));

            // act
            // assert
            act.ShouldNotThrow <CakeException>("Error occured during Paket restore");
            passedArguments.Should().NotBeNullOrEmpty();
            passedArguments.Should().Be("update");
        }
        public void PaketUpdateWithBootloaderAndPaketExecutableRetrieval()
        {
            // arrange
            var fixture             = new CakePaketRestoreAliasFixture();
            var updateSettingsDummy = new PaketUpdateSettings
            {
                RetrieveBootstrapper    = true,
                RetrievePaketExecutable = true
            };

            const string fakeUrl            = "http://localhost:9955";
            var          directory          = new DirectoryPath(Guid.NewGuid().ToString());
            var          bootstrapperPath   = new FilePath(Path.Combine(directory.FullPath, PaketBootstrapper));
            var          transferModelDummy = new GitHubLatestReleaseTransferModel
            {
                GitHubAssetsTransferModel = new[]
                {
                    new GitHubAssetsTransferModel
                    {
                        BrowserUrl = $"{fakeUrl}/{PaketBootstrapper}",
                        Name       = PaketBootstrapper
                    }
                }
            };

            var httpMock = HttpMockRepository.At(fakeUrl);

            CakePaketRestoreAlias.GithubUrlPath = fakeUrl;

            fixture.FileSysteMock.Setup(t => t.GetFile(bootstrapperPath).Exists).Returns(false);
            httpMock.Stub(x => x.Get(BootStrapperUrl))
            .Return("application/json")
            .Return(JsonConvert.SerializeObject(transferModelDummy))
            .OK();
            httpMock.Stub(x => x.Get($"/{PaketBootstrapper}"))
            .ReturnFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "TestFile.txt"))
            .OK();
            var act = new Action(() => fixture.GetCakeContext.PaketUpdate(fixture.GetDirectoryPath, updateSettingsDummy));

            // act
            // assert
            act.ShouldNotThrow <CakeException>("Error occured during Paket update");
            fixture.GetCakeLog.Messages.Should().Contain(x => x.Format == "Completed retrieval of the Paket Bootstrapper");
            DirectoryHelper.DeleteDirectory(directory.FullPath);
        }
        public void SuccessfullyRetrievePaketBootStrapper()
        {
            // arrange
            var          fixture            = new CakePaketRestoreAliasFixture();
            const string fakeUrl            = "http://localhost:9955";
            var          directory          = new DirectoryPath(Guid.NewGuid().ToString());
            var          bootstrapperPath   = new FilePath(Path.Combine(directory.FullPath, PaketBootstrapper));
            var          transferModelDummy = new GitHubLatestReleaseTransferModel
            {
                GitHubAssetsTransferModel = new[]
                {
                    new GitHubAssetsTransferModel
                    {
                        BrowserUrl = $"{fakeUrl}/{PaketBootstrapper}",
                        Name       = PaketBootstrapper
                    }
                }
            };

            var httpMock = HttpMockRepository.At(fakeUrl);

            CakePaketRestoreAlias.GithubUrlPath = fakeUrl;

            fixture.FileSysteMock.Setup(t => t.GetFile(bootstrapperPath).Exists).Returns(false);
            httpMock.Stub(x => x.Get(BootStrapperUrl))
            .Return("application/json")
            .Return(JsonConvert.SerializeObject(transferModelDummy))
            .OK();
            httpMock.Stub(x => x.Get($"/{PaketBootstrapper}"))
            .ReturnFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "TestFile.txt"))
            .OK();

            // act
            fixture.GetCakeContext.RetrievePaketBootstrapper(directory);

            // assert
            fixture.GetCakeLog.Messages.Last().Format.Should().Be("Completed retrieval of the Paket Bootstrapper");

            DirectoryHelper.DeleteDirectory(directory.FullPath);
        }
        public void ErrorDuringBootstrapperDownloadShouldThrowException()
        {
            // arrange
            var          fixture            = new CakePaketRestoreAliasFixture();
            const string fakeUrl            = "http://localhost:9955";
            var          directory          = new DirectoryPath(Guid.NewGuid().ToString());
            var          bootstrapperPath   = new FilePath(Path.Combine(directory.FullPath, PaketBootstrapper));
            var          transferModelDummy = new GitHubLatestReleaseTransferModel
            {
                GitHubAssetsTransferModel = new[]
                {
                    new GitHubAssetsTransferModel
                    {
                        BrowserUrl = $"{fakeUrl}/{PaketBootstrapper}",
                        Name       = PaketBootstrapper
                    }
                }
            };

            var httpMock = HttpMockRepository.At(fakeUrl);

            CakePaketRestoreAlias.GithubUrlPath = fakeUrl;

            fixture.FileSysteMock.Setup(t => t.GetFile(bootstrapperPath).Exists).Returns(false);
            httpMock.Stub(x => x.Get(BootStrapperUrl))
            .AddHeader("X-RateLimit-Limit", "2")
            .AddHeader("X-RateLimit-Remaining", "1")
            .Return("application/json")
            .Return(JsonConvert.SerializeObject(transferModelDummy))
            .OK();

            var act = new Action(() => fixture.GetCakeContext.RetrievePaketBootstrapper(directory));

            // act
            // assert
            act.ShouldThrow <CakeException>("An error occured while trying to retrieve the Paket Bootstrapper");

            DirectoryHelper.DeleteDirectory(directory.FullPath);
        }
        public void RetrieveBootstrapperDoesNothingIfBootstrapperAlreadyExists()
        {
            // arrange
            var directory        = new DirectoryPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString()));
            var bootstrapperPath = new FilePath(Path.Combine(directory.FullPath, PaketBootstrapper));
            var fixture          = new CakePaketRestoreAliasFixture();

            Directory.CreateDirectory(directory.FullPath);
            File.Create(Path.Combine(directory.FullPath, PaketBootstrapper)).Close();

            fixture.FileSysteMock.Setup(t => t.GetFile(bootstrapperPath).Exists).Returns(true);

            // act
            fixture.GetCakeContext.RetrievePaketBootstrapper(directory);

            // assert
            fixture.GetCakeLog.Messages.Last()
            .Format.Should()
            .Be("Paket Bootstrapper already exists - skipping download");

            DirectoryHelper.DeleteDirectory(directory.FullPath);
        }