mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
Add support to get raw file content as byte[] (#2151)
This commit is contained in:
@@ -274,6 +274,45 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetRawContentMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task ReturnsRawContent()
|
||||
{
|
||||
var result = new byte[] { 1, 2, 3 };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var contentsClient = new ObservableRepositoryContentsClient(gitHubClient);
|
||||
IApiResponse<byte[]> response = new ApiResponse<byte[]>
|
||||
(
|
||||
new Response { ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()) },
|
||||
result
|
||||
);
|
||||
connection.GetRaw(Args.Uri, default).Returns(response);
|
||||
|
||||
var rawContent = await contentsClient.GetRawContent("fake", "repo", "path/to/file.txt");
|
||||
|
||||
connection.Received().GetRaw(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/path/to/file.txt"), null);
|
||||
Assert.Same(result, rawContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryContentsClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContent(null, "name", "path"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContent("owner", null, "path"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContent("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContent("", "name", "path"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContent("owner", "", "path"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContent("owner", "name", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetContentsByRefMethod
|
||||
{
|
||||
[Fact]
|
||||
@@ -396,6 +435,47 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetRawContentByRefMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task ReturnsRawContent()
|
||||
{
|
||||
var result = new byte[] { 1, 2, 3 };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var contentsClient = new ObservableRepositoryContentsClient(gitHubClient);
|
||||
IApiResponse<byte[]> response = new ApiResponse<byte[]>
|
||||
(
|
||||
new Response { ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()) },
|
||||
result
|
||||
);
|
||||
connection.GetRaw(Args.Uri, default).Returns(response);
|
||||
|
||||
var rawContent = await contentsClient.GetRawContentByRef("fake", "repo", "path/to/file.txt", "reference");
|
||||
|
||||
connection.Received().GetRaw(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/path/to/file.txt?ref=reference"), null);
|
||||
Assert.Same(result, rawContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryContentsClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContentByRef(null, "name", "path", "reference"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContentByRef("owner", null, "path", "reference"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContentByRef("owner", "name", null, "reference"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRawContentByRef("owner", "name", "path", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContentByRef("", "name", "path", "reference"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContentByRef("owner", "", "path", "reference"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContentByRef("owner", "name", "", "reference"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRawContentByRef("owner", "name", "path", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateFileMethod
|
||||
{
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user