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
This commit is contained in:
Joen Sindholt
2017-04-03 14:34:43 +02:00
committed by Ryan Gribble
parent dba2b7bdc2
commit 596e51d5b3
3 changed files with 28 additions and 5 deletions
@@ -227,6 +227,30 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync<ArgumentException>(() => client.Add("owner", "test", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.Add(1, ""));
}
[Fact]
public async Task SurfacesAuthorizationException()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepoCollaboratorsClient(connection);
connection.Put(Arg.Any<Uri>()).Returns(x => { throw new AuthorizationException(); });
await Assert.ThrowsAsync<AuthorizationException>(() => client.Add("owner", "test", "user1"));
await Assert.ThrowsAsync<AuthorizationException>(() => client.Add(1, "user1"));
}
[Fact]
public async Task SurfacesAuthorizationExceptionWhenSpecifyingCollaboratorRequest()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepoCollaboratorsClient(connection);
connection.Connection.Put<object>(Arg.Any<Uri>(), Arg.Any<object>()).ThrowsAsync(new AuthorizationException());
await Assert.ThrowsAsync<AuthorizationException>(() => client.Add("owner", "test", "user1", new CollaboratorRequest(Permission.Pull)));
await Assert.ThrowsAsync<AuthorizationException>(() => client.Add(1, "user1", new CollaboratorRequest(Permission.Pull)));
}
}
public class TheInviteMethod
+3 -3
View File
@@ -175,11 +175,11 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(user, "user");
try
{
{
var response = await Connection.Put<object>(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<object>(ApiUrls.RepoCollaborator(repositoryId, user), permission).ConfigureAwait(false);
return response.HttpResponse.IsTrue();
}
catch
catch (NotFoundException)
{
return false;
}
+1 -2
View File
@@ -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
name: OctokitPackages