Exemple #1
0
        public async Task Get_FileContents_Exception_First()
        {
            var InputOwner         = "foo";
            var InputRepo          = "bar";
            var InputBranch        = "baz";
            var InputPath          = "qux.md";
            var ExpectedContentURL = $"https://api.github.com/repos/{InputOwner}/{InputRepo}/contents/{InputPath}?ref={InputBranch}";

            var fixture = new GitHubFixture();

            fixture.SetupGetFileContentsFirstFails(ExpectedContentURL);
            var respository = new GitHubRepository(fixture.GitHubContext);
            var ex          = await Assert.ThrowsAsync <RestAPICallException>(async() =>
                                                                              await respository.GetFileContents(InputOwner, InputRepo, InputBranch, InputPath)
                                                                              );

            Assert.Equal("InternalServerError", ex.StatusCode);
            Assert.Equal("Internal Server Error", ex.Message);
            Assert.Equal(ExpectedContentURL, ex.RequestMessage.RequestUri.ToString());
        }
Exemple #2
0
        public async Task Get_FileContents_Normal()
        {
            var InputOwner          = "foo";
            var InputRepo           = "bar";
            var InputBranch         = "baz";
            var InputPath           = "qux.md";
            var ExpectedContentURL  = $"https://api.github.com/repos/{InputOwner}/{InputRepo}/contents/{InputPath}?ref={InputBranch}";
            var ExpectedDownloadURL = $"https://raw.githubusercontent.com/foo/bar/baz/qux.md";
            var ExpectedContent     = "quux";
            // Task<string> GetFileContents(string owner, string repo, string branch, string path)
            // var response = await context.GetAsync($"{RestAPIBase}/{owner}/{repo}/contents/{path}?ref={branch}");
            // var response = await context.GetAsync(downloadUrl);
            var fixture = new GitHubFixture();

            fixture.SetupGetFileContents(ExpectedContentURL, ExpectedDownloadURL, ExpectedContent);
            var respository = new GitHubRepository(fixture.GitHubContext);
            var result      = await respository.GetFileContents(InputOwner, InputRepo, InputBranch, InputPath);

            Assert.Equal(ExpectedContent, result.Item2);
            Assert.Equal(ExpectedDownloadURL, result.Item1.download_url);
        }