mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Move error handling to Connection
The adapter shouldn't be responsible for translating errors into the proper exception.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Http;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
@@ -116,6 +119,26 @@ namespace Octokit.Tests.Http
|
||||
Assert.NotNull(resp.ApiInfo);
|
||||
Assert.Equal("user", resp.ApiInfo.AcceptedOauthScopes.First());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.Forbidden)]
|
||||
[InlineData(HttpStatusCode.Unauthorized)]
|
||||
public async Task ThrowsAuthenticationExceptionExceptionForAppropriateStatusCodes(HttpStatusCode statusCode)
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse<string> response = new ApiResponse<string> { StatusCode = statusCode};
|
||||
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(ExampleUri,
|
||||
Substitute.For<ICredentialStore>(),
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<AuthenticationException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("/endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("You must be authenticated to call this method. Either supply a login/password or an " +
|
||||
"oauth token.", exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetHtmlMethod
|
||||
|
||||
Reference in New Issue
Block a user