public async Task ShouldThrowReloadlyOAuthException() { var httpTest = new HttpTest(new Uri(ServiceUrls.AirtimeAuth)) .ExpectMethod(HttpMethod.Post) .ExpectHeader(HeaderNames.Accept, MediaTypeNames.Application.Json) .ExpectUriPath("oauth/token") .ExpectRequestBodyField("grant_type", GrantType.ClientCredentials) .ExpectRequestBodyField("client_id", CLIENT_ID) .ExpectRequestBodyField("client_secret", CLIENT_SECRET) .ResponseBodyFromFile("auth/error_access_denied.json") .StatusCode(HttpStatusCode.Unauthorized); var oAuth2Operation = new OAuth2Operation( httpTest.HttpClient, AuthenticationApi.BaseUri, CLIENT_ID, CLIENT_SECRET, ReloadlyService.AirtimeSandbox); try { var tokenRequest = await oAuth2Operation.GetAccessTokenAsync(); } catch (ReloadlyOAuthException ex) { Assert.AreEqual(401, ex.HttpStatusCode); throw; } catch { Assert.Fail("A generic exception was thrown."); } Assert.Fail("An exception was not thrown."); }
public async Task ShouldCreateOAuth2ClientCredentialsTokenRequest() { var httpTest = new HttpTest(new Uri(ServiceUrls.AirtimeAuth)) .ExpectMethod(HttpMethod.Post) .ExpectHeader(HeaderNames.Accept, MediaTypeNames.Application.Json) .ExpectRequestBodyField("client_id", CLIENT_ID) .ExpectRequestBodyField("client_secret", CLIENT_SECRET) .ExpectUriPath("oauth/token") .ExpectRequestBodyField("grant_type", GrantType.ClientCredentials) .ResponseBodyFromFile("auth/success_token_response.json"); var expected = httpTest.ResponseBody <OAuthTokenResponse>(); var oAuth2Operation = new OAuth2Operation( httpTest.HttpClient, AuthenticationApi.BaseUri, CLIENT_ID, CLIENT_SECRET, ReloadlyService.AirtimeSandbox); var actual = await oAuth2Operation.GetAccessTokenAsync(); Verify(expected, actual); }