mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
Create observable commits client
This commit is contained in:
22
Octokit.Reactive/Clients/IObservableCommitsClient.cs
Normal file
22
Octokit.Reactive/Clients/IObservableCommitsClient.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableCommitsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a commit for a given repository by sha reference
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/git/commits/#get-a-commit
|
||||
/// </remarks>
|
||||
/// <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 commit</param>
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
||||
Justification = "Method makes a network request")]
|
||||
IObservable<Commit> Get(string owner, string name, string reference);
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,6 @@
|
||||
public interface IObservableGitDatabaseClient
|
||||
{
|
||||
IObservableTagsClient Tag { get; set; }
|
||||
IObservableCommitsClient Commit { get; set; }
|
||||
}
|
||||
}
|
||||
25
Octokit.Reactive/Clients/ObservableCommitsClient.cs
Normal file
25
Octokit.Reactive/Clients/ObservableCommitsClient.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public class ObservableCommitsClient : IObservableCommitsClient
|
||||
{
|
||||
readonly ICommitsClient _client;
|
||||
|
||||
public ObservableCommitsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
_client = client.GitDatabase.Commit;
|
||||
}
|
||||
|
||||
public IObservable<Commit> Get(string owner, string name, string reference)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
return _client.Get(owner, name, reference).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
public ObservableGitDatabaseClient(IGitHubClient client)
|
||||
{
|
||||
Tag = new ObservableTagsClient(client);
|
||||
Commit = new ObservableCommitsClient(client);
|
||||
}
|
||||
|
||||
public IObservableTagsClient Tag { get; set; }
|
||||
public IObservableCommitsClient Commit { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\IObservableCommitsClient.cs" />
|
||||
<Compile Include="Clients\ObservableCommitsClient.cs" />
|
||||
<Compile Include="Clients\ObservableGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IObservableGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IObservableTagsClient.cs" />
|
||||
|
||||
@@ -14,11 +14,19 @@ public class GitDatabaseClientTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetChildsClients()
|
||||
public void SetTagsClient()
|
||||
{
|
||||
var apiConnection = Substitute.For<IApiConnection>();
|
||||
var gitDatabaseClient = new GitDatabaseClient(apiConnection);
|
||||
Assert.NotNull(gitDatabaseClient.Tag);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCommitsClient()
|
||||
{
|
||||
var apiConnection = Substitute.For<IApiConnection>();
|
||||
var gitDatabaseClient = new GitDatabaseClient(apiConnection);
|
||||
Assert.NotNull(gitDatabaseClient.Commit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,13 +77,13 @@ public class TagsClientTests
|
||||
[Fact]
|
||||
public void PerformsNewTagSerialization()
|
||||
{
|
||||
var tag = new NewTag()
|
||||
var tag = new NewTag
|
||||
{
|
||||
Message = "tag-message",
|
||||
Tag = "tag-name",
|
||||
Object = "tag-object",
|
||||
Type = TaggedType.Tree,
|
||||
Tagger = new Tagger
|
||||
Tagger = new UserAction
|
||||
{
|
||||
Name = "tagger-name",
|
||||
Email = "tagger-email",
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
<Compile Include="Helpers\StringExtensionsTests.cs" />
|
||||
<Compile Include="Clients\RepositoriesClientTests.cs" />
|
||||
<Compile Include="Reactive\AuthorizationExtensionsTests.cs" />
|
||||
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||
|
||||
37
Octokit.Tests/Reactive/ObservableCommitsClientTests.cs
Normal file
37
Octokit.Tests/Reactive/ObservableCommitsClientTests.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableCommitsClientTests
|
||||
{
|
||||
public class TheCtorMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgumentIsNotNulll()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ObservableCommitsClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", ""));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, ""));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", "name", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", "name", "reference"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", "reference"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "name", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,10 @@
|
||||
: base(apiConnection)
|
||||
{
|
||||
Tag = new TagsClient(apiConnection);
|
||||
Commit = new CommitsClient(apiConnection);
|
||||
}
|
||||
|
||||
public ITagsClient Tag { get; set; }
|
||||
public ICommitsClient Commit { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,6 @@
|
||||
public interface IGitDatabaseClient
|
||||
{
|
||||
ITagsClient Tag { get; set; }
|
||||
ICommitsClient Commit { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Octokit
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class Commit
|
||||
{
|
||||
@@ -6,12 +8,12 @@
|
||||
public string Url { get; set; }
|
||||
public string Message { get; set; }
|
||||
public UserAction Author { get; set; }
|
||||
public UserAction Commiter { get; set; }
|
||||
public CommitRelation Tree { get; set; }
|
||||
public CommitRelation[] Parents { get; set; }
|
||||
public UserAction Committer { get; set; }
|
||||
public GitReference Tree { get; set; }
|
||||
public IEnumerable<GitReference> Parents { get; set; }
|
||||
}
|
||||
|
||||
public class CommitRelation
|
||||
public class GitReference
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string Sha { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user