From 596e51d5b31783418b4b7601b88ff9531cb2a611 Mon Sep 17 00:00:00 2001 From: Joen Sindholt Date: Mon, 3 Apr 2017 14:34:43 +0200 Subject: [PATCH] Surface exceptions in RepoCollaboratorsClient.Add method (#1576) * Surface exceptions in RepoCollaboratorsClient.Add method * Reintroducing try...catch but for NotFoundException * Remove old/test dotnet core builds from appveyor --- .../Clients/RepoCollaboratorsClientTests.cs | 24 +++++++++++++++++++ Octokit/Clients/RepoCollaboratorsClient.cs | 6 ++--- appveyor.yml | 3 +-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 3fb20b53..c5925362 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -227,6 +227,30 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.Add("owner", "test", "")); await Assert.ThrowsAsync(() => client.Add(1, "")); } + + [Fact] + public async Task SurfacesAuthorizationException() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + connection.Put(Arg.Any()).Returns(x => { throw new AuthorizationException(); }); + + await Assert.ThrowsAsync(() => client.Add("owner", "test", "user1")); + await Assert.ThrowsAsync(() => client.Add(1, "user1")); + } + + [Fact] + public async Task SurfacesAuthorizationExceptionWhenSpecifyingCollaboratorRequest() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + connection.Connection.Put(Arg.Any(), Arg.Any()).ThrowsAsync(new AuthorizationException()); + + await Assert.ThrowsAsync(() => client.Add("owner", "test", "user1", new CollaboratorRequest(Permission.Pull))); + await Assert.ThrowsAsync(() => client.Add(1, "user1", new CollaboratorRequest(Permission.Pull))); + } } public class TheInviteMethod diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 4eda7655..ca59630f 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -175,11 +175,11 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); try - { + { var response = await Connection.Put(ApiUrls.RepoCollaborator(owner, name, user), permission).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } - catch + catch (NotFoundException) { return false; } @@ -220,7 +220,7 @@ namespace Octokit var response = await Connection.Put(ApiUrls.RepoCollaborator(repositoryId, user), permission).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } - catch + catch (NotFoundException) { return false; } diff --git a/appveyor.yml b/appveyor.yml index 6c4ffa07..904bc132 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,8 +5,7 @@ build_script: - cmd: build.cmd UnitTests - cmd: build.cmd ConventionTests - cmd: build.cmd CreatePackages - - cmd: build.cmd UnitTestsDotNetCore test: off artifacts: - path: 'packaging\octokit*.nupkg' - name: OctokitPackages \ No newline at end of file + name: OctokitPackages