From 5dfe1968da206b85eef37fea588edd78bd819a57 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Wed, 16 Mar 2016 21:59:33 +0000 Subject: [PATCH 01/15] Get the SHA-1 of a commit reference Updated RepositoryCommitsClients and unit/integration tests --- .../Clients/RepositoryCommitsClientTests.cs | 8 +++++ .../Clients/RepositoriesClientTests.cs | 30 +++++++++++++++++++ Octokit/Clients/IRepositoryCommitsClient.cs | 9 ++++++ Octokit/Clients/RepositoryCommitsClient.cs | 16 ++++++++++ 4 files changed, 63 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 9546491755..7724e443e8 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -87,6 +87,14 @@ public async Task CanGetCommitWithRenamedFiles() .Where(file => file.Status == "renamed") .All(file => string.IsNullOrEmpty(file.PreviousFileName) == false)); } + + [IntegrationTest] + public async Task CanGetSha1() + { + var sha1 = await _fixture.Sha1("octokit", "octokit.net", "master"); + + Assert.NotNull(sha1); + } } public class TestsWithNewRepository : IDisposable diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index e74cc97b83..e1130eac19 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -790,5 +790,35 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.EditBranch("owner", "repo", "", update)); } } + + public class TheSha1Method + { + [Fact] + public async Task EnsureNonNullArguments() + { + var client = new RepositoryCommitsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Sha1(null, "name", "reference")); + await Assert.ThrowsAsync(() => client.Sha1("", "name", "reference")); + + await Assert.ThrowsAsync(() => client.Sha1("owner", null, "reference")); + await Assert.ThrowsAsync(() => client.Sha1("owner", "", "reference")); + + await Assert.ThrowsAsync(() => client.Sha1("owner", "name", null)); + await Assert.ThrowsAsync(() => client.Sha1("owner", "name", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryCommitsClient(connection); + + client.Sha1("owner", "name", "reference"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repos/owner/name/commits/reference"), null, AcceptHeaders.CommitReferenceSha1Preview); + } + } } } diff --git a/Octokit/Clients/IRepositoryCommitsClient.cs b/Octokit/Clients/IRepositoryCommitsClient.cs index f2b09f2b49..27b846cb59 100644 --- a/Octokit/Clients/IRepositoryCommitsClient.cs +++ b/Octokit/Clients/IRepositoryCommitsClient.cs @@ -50,5 +50,14 @@ public interface IRepositoryCommitsClient /// Used to filter list of commits returned /// Task> GetAll(string owner, string name, CommitRequest request); + + /// + /// Get the SHA-1 of a commit reference + /// + /// The owner of the repository + /// The name of the repository + /// The repository reference + /// + Task Sha1(string owner, string name, string reference); } } diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs index 0e8ad1b26f..c328cfb6d3 100644 --- a/Octokit/Clients/RepositoryCommitsClient.cs +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -79,5 +79,21 @@ public Task> GetAll(string owner, string name, Commi return _apiConnection.GetAll(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary()); } + + /// + /// Get the SHA-1 of a commit reference + /// + /// The owner of the repository + /// The name of the repository + /// The repository reference + /// + public Task Sha1(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _apiConnection.Get(ApiUrls.RepositoryCommit(owner, name, reference), null, AcceptHeaders.CommitReferenceSha1Preview); + } } } \ No newline at end of file From 5270b3783e47ef73be9d4bbeb00f9d84b483dd4f Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Wed, 16 Mar 2016 22:01:45 +0000 Subject: [PATCH 02/15] Get the SHA-1 of a commit reference Added implementation for Reactive framework --- .../IObservableRepositoryCommitsClients.cs | 9 +++++++++ .../ObservableRepositoryCommitsClients.cs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs index 927b34c03e..aee952781b 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs @@ -43,5 +43,14 @@ public interface IObservableRepositoryCommitsClient /// Used to filter list of commits returned /// IObservable GetAll(string owner, string name, CommitRequest request); + + /// + /// Get the SHA-1 of a commit reference + /// + /// The owner of the repository + /// The name of the repository + /// The repository reference + /// + IObservable Sha1(string owner, string name, string reference); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs index 7982485e39..9aa5d2a6dd 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs @@ -73,5 +73,21 @@ public IObservable GetAll(string owner, string name, CommitRequest return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary()); } + + /// + /// Get the SHA-1 of a commit reference + /// + /// The owner of the repository + /// The name of the repository + /// The repository reference + /// + public IObservable Sha1(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _commit.Sha1(owner, name, reference).ToObservable(); + } } } From faa19af7485c01ff4d5517de8619e5c72768aed3 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Wed, 16 Mar 2016 22:05:50 +0000 Subject: [PATCH 03/15] added sha preview header --- Octokit/Helpers/AcceptHeaders.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index d94e7e1502..21c0047eb5 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -13,5 +13,7 @@ public static class AcceptHeaders public const string ProtectedBranchesApiPreview = "application/vnd.github.loki-preview+json"; public const string StarCreationTimestamps = "application/vnd.github.v3.star+json"; + + public const string CommitReferenceSha1Preview = "application/vnd.github.chitauri-preview+sha"; } } From d9fd0b7e2ccbf9c65df1e3d2f123404ca805eacf Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Wed, 16 Mar 2016 23:30:41 +0000 Subject: [PATCH 04/15] Added verb to Sha1 method --- .../Clients/IObservableRepositoryCommitsClients.cs | 2 +- .../Clients/ObservableRepositoryCommitsClients.cs | 4 ++-- .../Clients/RepositoryCommitsClientTests.cs | 2 +- Octokit.Tests/Clients/RepositoriesClientTests.cs | 14 +++++++------- Octokit/Clients/IRepositoryCommitsClient.cs | 2 +- Octokit/Clients/RepositoryCommitsClient.cs | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs index aee952781b..29d4d55ead 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs @@ -51,6 +51,6 @@ public interface IObservableRepositoryCommitsClient /// The name of the repository /// The repository reference /// - IObservable Sha1(string owner, string name, string reference); + IObservable GetSha1(string owner, string name, string reference); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs index 9aa5d2a6dd..629142d7dc 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs @@ -81,13 +81,13 @@ public IObservable GetAll(string owner, string name, CommitRequest /// The name of the repository /// The repository reference /// - public IObservable Sha1(string owner, string name, string reference) + public IObservable GetSha1(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - return _commit.Sha1(owner, name, reference).ToObservable(); + return _commit.GetSha1(owner, name, reference).ToObservable(); } } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 7724e443e8..1acbaa8c2b 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -91,7 +91,7 @@ public async Task CanGetCommitWithRenamedFiles() [IntegrationTest] public async Task CanGetSha1() { - var sha1 = await _fixture.Sha1("octokit", "octokit.net", "master"); + var sha1 = await _fixture.GetSha1("octokit", "octokit.net", "master"); Assert.NotNull(sha1); } diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index e1130eac19..52e325c729 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -798,14 +798,14 @@ public async Task EnsureNonNullArguments() { var client = new RepositoryCommitsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Sha1(null, "name", "reference")); - await Assert.ThrowsAsync(() => client.Sha1("", "name", "reference")); + await Assert.ThrowsAsync(() => client.GetSha1(null, "name", "reference")); + await Assert.ThrowsAsync(() => client.GetSha1("", "name", "reference")); - await Assert.ThrowsAsync(() => client.Sha1("owner", null, "reference")); - await Assert.ThrowsAsync(() => client.Sha1("owner", "", "reference")); + await Assert.ThrowsAsync(() => client.GetSha1("owner", null, "reference")); + await Assert.ThrowsAsync(() => client.GetSha1("owner", "", "reference")); - await Assert.ThrowsAsync(() => client.Sha1("owner", "name", null)); - await Assert.ThrowsAsync(() => client.Sha1("owner", "name", "")); + await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "")); } [Fact] @@ -814,7 +814,7 @@ public void GetsCorrectUrl() var connection = Substitute.For(); var client = new RepositoryCommitsClient(connection); - client.Sha1("owner", "name", "reference"); + client.GetSha1("owner", "name", "reference"); connection.Received() .Get(Arg.Is(u => u.ToString() == "repos/owner/name/commits/reference"), null, AcceptHeaders.CommitReferenceSha1Preview); diff --git a/Octokit/Clients/IRepositoryCommitsClient.cs b/Octokit/Clients/IRepositoryCommitsClient.cs index 27b846cb59..bd48619266 100644 --- a/Octokit/Clients/IRepositoryCommitsClient.cs +++ b/Octokit/Clients/IRepositoryCommitsClient.cs @@ -58,6 +58,6 @@ public interface IRepositoryCommitsClient /// The name of the repository /// The repository reference /// - Task Sha1(string owner, string name, string reference); + Task GetSha1(string owner, string name, string reference); } } diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs index c328cfb6d3..e5fa961346 100644 --- a/Octokit/Clients/RepositoryCommitsClient.cs +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -87,7 +87,7 @@ public Task> GetAll(string owner, string name, Commi /// The name of the repository /// The repository reference /// - public Task Sha1(string owner, string name, string reference) + public Task GetSha1(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); From 64cea23bb78026dce03479a7046b6c803d93e6f3 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 07:43:12 +0000 Subject: [PATCH 05/15] Added integration test to verify a new repository - Create repository - Call GetSha1 - Call it a second time - Verify the two responses are equal --- .../Clients/RepositoryCommitsClientTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 1acbaa8c2b..349b83c88a 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -166,6 +166,17 @@ public async Task CanCompareUsingSha() Assert.Equal(0, result.BehindBy); } + [IntegrationTest] + public async Task GetShaFromRepository() + { + await CreateTheWorld(); + + var firstSha1 = await _fixture.GetSha1(Helper.UserName, _context.RepositoryName, "master"); + var secondSha1 = await _fixture.GetSha1(Helper.UserName, _context.RepositoryName, "master"); + + Assert.Equal(firstSha1, secondSha1); + } + async Task CreateTheWorld() { var master = await _github.Git.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/master"); From 705b93913ec9845c65844bc8379110fe90d654aa Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 07:48:33 +0000 Subject: [PATCH 06/15] Fixed wording & split out unit tests - One unit test for NonNullArguments - Another unit test for NonEMptyArguments --- Octokit.Tests/Clients/RepositoriesClientTests.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 52e325c729..417c3a5691 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -794,18 +794,24 @@ public async Task EnsuresNonNullArguments() public class TheSha1Method { [Fact] - public async Task EnsureNonNullArguments() + public async void EnsuresNonNullArguments() { var client = new RepositoryCommitsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.GetSha1(null, "name", "reference")); await Assert.ThrowsAsync(() => client.GetSha1("", "name", "reference")); - - await Assert.ThrowsAsync(() => client.GetSha1("owner", null, "reference")); await Assert.ThrowsAsync(() => client.GetSha1("owner", "", "reference")); + await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "")); + + } + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var client = new RepositoryCommitsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetSha1(null, "name", "reference")); + await Assert.ThrowsAsync(() => client.GetSha1("owner", null, "reference")); await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", null)); - await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "")); } [Fact] From 0fa9966fa77350b1939ff80648c4a278f5e0f30c Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 07:52:19 +0000 Subject: [PATCH 07/15] Changed integration test name --- .../Clients/RepositoryCommitsClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 349b83c88a..bac6865b86 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -167,7 +167,7 @@ public async Task CanCompareUsingSha() } [IntegrationTest] - public async Task GetShaFromRepository() + public async Task GetSha1FromRepository() { await CreateTheWorld(); From 6d1634c843df9e2853e12b32d6b3b888b500d173 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 08:35:39 +0000 Subject: [PATCH 08/15] Updated test to compare sha1 from reference with the GetSha1 method - CreateTheWorld now returns a Task - This reference is compared with client.GetSha1 --- .../Clients/RepositoryCommitsClientTests.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index bac6865b86..74c4e43e53 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -169,15 +169,14 @@ public async Task CanCompareUsingSha() [IntegrationTest] public async Task GetSha1FromRepository() { - await CreateTheWorld(); + var reference = await CreateTheWorld(); - var firstSha1 = await _fixture.GetSha1(Helper.UserName, _context.RepositoryName, "master"); - var secondSha1 = await _fixture.GetSha1(Helper.UserName, _context.RepositoryName, "master"); + var sha1 = await _fixture.GetSha1(Helper.UserName, _context.RepositoryName, "master"); - Assert.Equal(firstSha1, secondSha1); + Assert.Equal(reference.Object.Sha, sha1); } - async Task CreateTheWorld() + async Task CreateTheWorld() { var master = await _github.Git.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/master"); @@ -193,7 +192,7 @@ async Task CreateTheWorld() var newFeature = await CreateCommit("this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha); // create branch - await _github.Git.Reference.Create(Helper.UserName, _context.RepositoryName, new NewReference("refs/heads/my-branch", newFeature.Sha)); + return await _github.Git.Reference.Create(Helper.UserName, _context.RepositoryName, new NewReference("refs/heads/my-branch", newFeature.Sha)); } async Task CreateTree(IDictionary treeContents) From ebf2792c25df19c59724c1d9061d1cbd1d02e8b0 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 08:47:06 +0000 Subject: [PATCH 09/15] Remove async from void --- Octokit.Tests/Clients/RepositoriesClientTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 417c3a5691..583db0728c 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -794,14 +794,13 @@ public async Task EnsuresNonNullArguments() public class TheSha1Method { [Fact] - public async void EnsuresNonNullArguments() + public void EnsuresNonNullArguments() { var client = new RepositoryCommitsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.GetSha1("", "name", "reference")); - await Assert.ThrowsAsync(() => client.GetSha1("owner", "", "reference")); - await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "")); - + Assert.ThrowsAsync(() => client.GetSha1("", "name", "reference")); + Assert.ThrowsAsync(() => client.GetSha1("owner", "", "reference")); + Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "")); } [Fact] From 5be778b0f01b21a424b1e622d2e5cefe4596c476 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Thu, 17 Mar 2016 08:53:12 +0000 Subject: [PATCH 10/15] Modified the test class name to reflect the method under test --- Octokit.Tests/Clients/RepositoriesClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 583db0728c..dab4474d7b 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -791,7 +791,7 @@ public async Task EnsuresNonNullArguments() } } - public class TheSha1Method + public class TheGetSha1Method { [Fact] public void EnsuresNonNullArguments() From 04ec997cfa57a138c50bd7d173303e235dd4af44 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Mon, 21 Mar 2016 19:13:15 +0000 Subject: [PATCH 11/15] Created ObservableRepositoryCommitsClientTests Added tests for GetSha1 --- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableRepositoryCommitsClientTests.cs | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 5c6484c309..9f226d4e3a 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -212,6 +212,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs new file mode 100644 index 0000000000..a99938b4d8 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -0,0 +1,50 @@ +using System; +using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepositoryCommitsClientTests + { + public class TheGetSha1Method + { + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableRepositoryCommitsClient(Substitute.For()); + + Assert.ThrowsAsync(() => client.GetSha1("", "name", "reference").ToTask()); + Assert.ThrowsAsync(() => client.GetSha1("owner", "", "reference").ToTask()); + Assert.ThrowsAsync(() => client.GetSha1("owner", "name", "").ToTask()); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var client = new ObservableRepositoryCommitsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetSha1(null, "name", "reference").ToTask()); + await Assert.ThrowsAsync(() => client.GetSha1("owner", null, "reference").ToTask()); + await Assert.ThrowsAsync(() => client.GetSha1("owner", "name", null).ToTask()); + } + + [Fact] + public void GetsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryCommitsClient(gitHubClient); + + client.GetSha1("owner", "name", "reference"); + + gitHubClient + .Received() + .Repository + .Commit + .GetSha1("owner", "name", "reference"); + } + } + } +} From c34d904f1ab50972a7fe8d02dd762144033c5155 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Mon, 21 Mar 2016 19:23:18 +0000 Subject: [PATCH 12/15] Created ObservableRepositoryCommitsClientTests Added integration test for GetSha1 for observableclient --- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableRepositoryCommitsClientTests.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a5c12a316..d5581fe808 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -147,6 +147,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs new file mode 100644 index 0000000000..8906a3c095 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -0,0 +1,29 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableRepositoryCommitsClientTests + { + readonly IObservableRepositoryCommitsClient _fixture; + + public ObservableRepositoryCommitsClientTests() + { + var github = Helper.GetAuthenticatedClient(); + + _fixture = new ObservableRepositoryCommitsClient(github); + } + + [IntegrationTest] + public async Task CanGetSha1() + { + var observable = _fixture.GetSha1("octokit", "octokit.net", "master"); + + var sha1 = await observable; + + Assert.NotNull(sha1); + } + } +} From e57dfa33e2a8e645d0aa37851fa0c125564943d1 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Mon, 21 Mar 2016 19:27:13 +0000 Subject: [PATCH 13/15] Added constructor test Check the ctor for a null IGitHubClient --- .../Reactive/ObservableRepositoryCommitsClientTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs index a99938b4d8..44154d1b6b 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -9,6 +9,15 @@ namespace Octokit.Tests.Reactive { public class ObservableRepositoryCommitsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new ObservableRepositoryCommitsClient(null)); + } + } + public class TheGetSha1Method { [Fact] From dc8ef18c25d1652b999968edd9b2581303b0091a Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Tue, 22 Mar 2016 09:00:51 +0000 Subject: [PATCH 14/15] Removing integration test --- .../Octokit.Tests.Integration.csproj | 1 - .../ObservableRepositoryCommitsClientTests.cs | 29 ------------------- 2 files changed, 30 deletions(-) delete mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index d5581fe808..0a5c12a316 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -147,7 +147,6 @@ - diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs deleted file mode 100644 index 8906a3c095..0000000000 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Reactive.Linq; -using System.Threading.Tasks; -using Octokit.Reactive; -using Xunit; - -namespace Octokit.Tests.Integration.Reactive -{ - public class ObservableRepositoryCommitsClientTests - { - readonly IObservableRepositoryCommitsClient _fixture; - - public ObservableRepositoryCommitsClientTests() - { - var github = Helper.GetAuthenticatedClient(); - - _fixture = new ObservableRepositoryCommitsClient(github); - } - - [IntegrationTest] - public async Task CanGetSha1() - { - var observable = _fixture.GetSha1("octokit", "octokit.net", "master"); - - var sha1 = await observable; - - Assert.NotNull(sha1); - } - } -} From dd63d1bffad336b82f145c1a7b2ae1ff41596177 Mon Sep 17 00:00:00 2001 From: Roger Tinsley Date: Tue, 22 Mar 2016 09:02:45 +0000 Subject: [PATCH 15/15] Correcting method names NoNull needs to test null strings and NonEmpty tests empty strings --- .../Reactive/ObservableRepositoryCommitsClientTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs index 44154d1b6b..bcd91f377e 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -21,7 +21,7 @@ public void EnsuresArgument() public class TheGetSha1Method { [Fact] - public void EnsuresNonNullArguments() + public void EnsuresNonEmptyArguments() { var client = new ObservableRepositoryCommitsClient(Substitute.For()); @@ -31,7 +31,7 @@ public void EnsuresNonNullArguments() } [Fact] - public async Task EnsuresNonEmptyArguments() + public async Task EnsuresNonNullArguments() { var client = new ObservableRepositoryCommitsClient(Substitute.For());