Merge pull request #1363 from dampir/add-repo-id-tags-client

Add repositoryId overloads to methods on I(Observable)TagsClient
This commit is contained in:
Brendan Forster
2016-07-12 11:13:54 -07:00
committed by GitHub
9 changed files with 371 additions and 12 deletions
@@ -3,6 +3,12 @@ using System.Diagnostics.CodeAnalysis;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Git Tags API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/git/tags/">Git Tags API documentation</a> for more information.
/// </remarks>
public interface IObservableTagsClient
{
/// <summary>
@@ -14,11 +20,22 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
Justification = "Method makes a network request")]
IObservable<GitTag> Get(string owner, string name, string reference);
/// <summary>
/// Gets a tag for a given repository by sha reference
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#get-a-tag
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
IObservable<GitTag> Get(int repositoryId, string reference);
/// <summary>
/// Create a tag for a given repository
/// </summary>
@@ -28,7 +45,16 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="tag">The tag to create</param>
/// <returns></returns>
IObservable<GitTag> Create(string owner, string name, NewTag tag);
/// <summary>
/// Create a tag for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#create-a-tag-object
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="tag">The tag to create</param>
IObservable<GitTag> Create(int repositoryId, NewTag tag);
}
}
}
@@ -3,6 +3,12 @@ using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Git Tags API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/git/tags/">Git Tags API documentation</a> for more information.
/// </remarks>
public class ObservableTagsClient : IObservableTagsClient
{
readonly ITagsClient _client;
@@ -23,7 +29,6 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
/// <returns></returns>
public IObservable<GitTag> Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -33,6 +38,21 @@ namespace Octokit.Reactive
return _client.Get(owner, name, reference).ToObservable();
}
/// <summary>
/// Gets a tag for a given repository by sha reference
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#get-a-tag
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
public IObservable<GitTag> Get(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _client.Get(repositoryId, reference).ToObservable();
}
/// <summary>
/// Create a tag for a given repository
/// </summary>
@@ -42,7 +62,6 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="tag">The tag to create</param>
/// <returns></returns>
public IObservable<GitTag> Create(string owner, string name, NewTag tag)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -51,5 +70,20 @@ namespace Octokit.Reactive
return _client.Create(owner, name, tag).ToObservable();
}
/// <summary>
/// Create a tag for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#create-a-tag-object
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="tag">The tag to create</param>
public IObservable<GitTag> Create(int repositoryId, NewTag tag)
{
Ensure.ArgumentNotNull(tag, "tag");
return _client.Create(repositoryId, tag).ToObservable();
}
}
}
@@ -0,0 +1,112 @@
using System.Threading.Tasks;
using Octokit.Tests.Integration.Helpers;
using Xunit;
namespace Octokit.Tests.Integration.Clients
{
public class TagsClientTests
{
public class TheCreateMethod
{
readonly RepositoryContext context;
readonly ITagsClient fixture;
readonly string sha;
public TheCreateMethod()
{
var github = Helper.GetAuthenticatedClient();
fixture = github.Git.Tag;
context = github.CreateRepositoryContext("public-repo").Result;
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = github.Git.Blob.Create(context.RepositoryOwner, context.RepositoryName, blob).Result;
sha = blobResult.Sha;
}
[IntegrationTest]
public async Task CreatesTagForRepository()
{
var newTag = new NewTag { Message = "Hello", Type = TaggedType.Blob, Object = sha, Tag = "tag" };
var tag = await fixture.Create(context.Repository.Id, newTag);
Assert.Equal(tag.Object.Type, TaggedType.Blob);
Assert.Equal(tag.Message, "Hello");
Assert.Equal(tag.Object.Sha, sha);
}
[IntegrationTest]
public async Task CreatesTagForRepositoryWithRepositoryId()
{
var newTag = new NewTag { Message = "Hello", Type = TaggedType.Tree, Object = sha, Tag = "tag" };
var tag = await fixture.Create(context.Repository.Id, newTag);
Assert.Equal(tag.Object.Type, TaggedType.Blob);
Assert.Equal(tag.Message, "Hello");
Assert.Equal(tag.Object.Sha, sha);
}
}
public class TheGetMethod
{
readonly RepositoryContext context;
readonly ITagsClient fixture;
readonly string sha;
public TheGetMethod()
{
var github = Helper.GetAuthenticatedClient();
fixture = github.Git.Tag;
context = github.CreateRepositoryContext("public-repo").Result;
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = github.Git.Blob.Create(context.RepositoryOwner, context.RepositoryName, blob).Result;
sha = blobResult.Sha;
}
[IntegrationTest]
public async Task CreatesTagForRepository()
{
var newTag = new NewTag { Message = "Hello", Type = TaggedType.Blob, Object = sha, Tag = "tag" };
var tag = await fixture.Create(context.RepositoryOwner, context.RepositoryName, newTag);
var gitTag = await fixture.Get(context.RepositoryOwner, context.RepositoryName, tag.Sha);
Assert.NotNull(gitTag);
Assert.Equal(gitTag.Object.Type, TaggedType.Blob);
Assert.Equal(gitTag.Message, "Hello");
Assert.Equal(gitTag.Object.Sha, sha);
}
[IntegrationTest]
public async Task CreatesTagForRepositoryWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
var newTag = new NewTag { Message = "Hello", Type = TaggedType.Blob, Object = sha, Tag = "tag" };
var tag = await github.Git.Tag.Create(context.Repository.Id, newTag);
var gitTag = await github.Git.Tag.Get(context.Repository.Id, tag.Sha);
Assert.NotNull(gitTag);
Assert.Equal(gitTag.Object.Type, TaggedType.Blob);
Assert.Equal(gitTag.Message, "Hello");
Assert.Equal(gitTag.Object.Sha, sha);
}
}
}
}
@@ -113,6 +113,7 @@
<Compile Include="Clients\SearchClientTests.cs" />
<Compile Include="Clients\StarredClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.cs" />
<Compile Include="Clients\TagsClientTests.cs" />
<Compile Include="Clients\TreeClientTests.cs" />
<Compile Include="Clients\UserAdministrationClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
+33 -2
View File
@@ -10,16 +10,27 @@ public class TagsClientTests
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
client.Get("owner", "repo", "reference");
await client.Get("owner", "repo", "reference");
connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"));
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
await client.Get(1, "reference");
connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/tags/reference"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -28,9 +39,14 @@ public class TagsClientTests
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "reference"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "reference"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "reference"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "reference"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get(1, ""));
}
}
@@ -48,6 +64,18 @@ public class TagsClientTests
Arg.Is<NewTag>(nt => nt.Type == TaggedType.Tree));
}
[Fact]
public void PostsToTheCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
client.Create(1, new NewTag { Type = TaggedType.Tree });
connection.Received().Post<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/tags"),
Arg.Is<NewTag>(nt => nt.Type == TaggedType.Tree));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -56,6 +84,9 @@ public class TagsClientTests
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewTag()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewTag()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewTag()));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewTag()));
}
+1
View File
@@ -250,6 +250,7 @@
<Compile Include="Reactive\ObservableRespositoryCommitsClientTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTagsClientTests.cs" />
<Compile Include="Reactive\ObservableTeamsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
<Compile Include="Reactive\ObservableFollowersTest.cs" />
@@ -0,0 +1,106 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class TagsClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
client.Get("owner", "repo", "reference");
gitHubClient.Received().Git.Tag.Get("owner", "repo", "reference");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
client.Get(1, "reference");
gitHubClient.Received().Git.Tag.Get(1, "reference");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableTagsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", "reference"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, "reference"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Get(1, null));
Assert.Throws<ArgumentException>(() => client.Get("", "name", "reference"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "", "reference"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "name", ""));
Assert.Throws<ArgumentException>(() => client.Get(1, ""));
}
}
public class TheCreateMethod
{
[Fact]
public void PostsToTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
var newTag = new NewTag { Type = TaggedType.Tree };
client.Create("owner", "repo", newTag);
gitHubClient.Received().Git.Tag.Create("owner", "repo", newTag);
}
[Fact]
public void PostsToTheCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
var newTag = new NewTag { Type = TaggedType.Tree };
client.Create(1, newTag);
gitHubClient.Received().Git.Tag.Create(1, newTag);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableTagsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewTag()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewTag()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewTag()));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewTag()));
}
}
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableTagsClient(null));
}
}
}
}
+22 -2
View File
@@ -20,11 +20,22 @@ namespace Octokit
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
Task<GitTag> Get(string owner, string name, string reference);
/// <summary>
/// Gets a tag for a given repository by sha reference
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#get-a-tag
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
Task<GitTag> Get(int repositoryId, string reference);
/// <summary>
/// Create a tag for a given repository
/// </summary>
@@ -34,7 +45,16 @@ namespace Octokit
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="tag">The tag to create</param>
/// <returns></returns>
Task<GitTag> Create(string owner, string name, NewTag tag);
/// <summary>
/// Create a tag for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#create-a-tag-object
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="tag">The tag to create</param>
Task<GitTag> Create(int repositoryId, NewTag tag);
}
}
+30 -2
View File
@@ -28,7 +28,6 @@ namespace Octokit
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
/// <returns></returns>
public Task<GitTag> Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -38,6 +37,21 @@ namespace Octokit
return ApiConnection.Get<GitTag>(ApiUrls.Tag(owner, name, reference));
}
/// <summary>
/// Gets a tag for a given repository by sha reference
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#get-a-tag
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">Tha sha reference of the tag</param>
public Task<GitTag> Get(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get<GitTag>(ApiUrls.Tag(repositoryId, reference));
}
/// <summary>
/// Create a tag for a given repository
/// </summary>
@@ -47,7 +61,6 @@ namespace Octokit
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="tag">The tag to create</param>
/// <returns></returns>
public Task<GitTag> Create(string owner, string name, NewTag tag)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -56,5 +69,20 @@ namespace Octokit
return ApiConnection.Post<GitTag>(ApiUrls.CreateTag(owner, name), tag);
}
/// <summary>
/// Create a tag for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/tags/#create-a-tag-object
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="tag">The tag to create</param>
public Task<GitTag> Create(int repositoryId, NewTag tag)
{
Ensure.ArgumentNotNull(tag, "tag");
return ApiConnection.Post<GitTag>(ApiUrls.CreateTag(repositoryId), tag);
}
}
}