Allow base64 content for create/update file (#1488)

* Allow base64 direct content for create/update file

* Add overload to avoid breaking change
This commit is contained in:
Jérémie Bertrand
2016-11-21 13:24:53 +01:00
committed by Ryan Gribble
parent 97dee1e6d8
commit 88e5342562
4 changed files with 476 additions and 15 deletions
@@ -437,7 +437,7 @@ namespace Octokit.Tests.Reactive
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}
@@ -454,7 +454,66 @@ namespace Octokit.Tests.Reactive
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}
[Fact]
public void RequestsCorrectUrlWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
string expectedUri = "repos/org/repo/contents/path/to/file";
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
[Fact]
public void RequestsCorrectUrlWithRepositoryIdWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
string expectedUri = "repositories/1/contents/path/to/file";
client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
[Fact]
public void PassesRequestObjectWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}
[Fact]
public void PassesRequestObjectWithRepositoryIdWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}
@@ -606,7 +665,7 @@ namespace Octokit.Tests.Reactive
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
@@ -624,7 +683,69 @@ namespace Octokit.Tests.Reactive
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
[Fact]
public void RequestsCorrectUrlWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
string expectedUri = "repos/org/repo/contents/path/to/file";
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
[Fact]
public void RequestsCorrectUrlWithRepositoryIdWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
string expectedUri = "repositories/1/contents/path/to/file";
client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
[Fact]
public void PassesRequestObjectWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
[Fact]
public void PassesRequestObjectWithRepositoriesIdWithExplicitBase64()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);
client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));
gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}