GetTokenByCodeAsync() public méthode

After the user authorizes, the pin is returned as a code to your application via the redirect URL you specified during registration, in the form of a regular query string parameter.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public GetTokenByCodeAsync ( string code ) : Task
code string The code from the query string.
Résultat Task
        public async Task GetTokenByCodeAsync_ThrowsImgurException()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenResponseError)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse);

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler));
            await endpoint.GetTokenByCodeAsync("12345");
        }
        public async Task GetTokenByCodeAsync_WithClientSecretNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123");
            var endpoint = new OAuth2Endpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.GetTokenByCodeAsync("1234").ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException) exception;
            Assert.Equal(argNullException.ParamName, "ClientSecret");
        }
        public async Task GetTokenByCodeAsync_ThrowsImgurException()
        {
            var mockUrl = "https://api.imgur.com/oauth2/token";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent(MockOAuth2EndpointResponses.OAuth2TokenResponseError)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.GetTokenByCodeAsync("12345").ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ImgurException>(exception);
        }
        public async Task GetTokenByCodeAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/oauth2/token";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockOAuth2EndpointResponses.GetTokenByCode)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var token = await endpoint.GetTokenByCodeAsync("12345").ConfigureAwait(false);

            Assert.Equal("CodeResponse", token.AccessToken);
            Assert.Equal("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken);
            Assert.Equal("bearer", token.TokenType);
            Assert.Equal(2419200, token.ExpiresIn);
            Assert.Equal("Bob", token.AccountUsername);
            Assert.Equal("45344", token.AccountId);
        }
        public async Task GetTokenByCodeAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenCodeResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse);

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler));
            var token = await endpoint.GetTokenByCodeAsync("12345");

            Assert.AreEqual("CodeResponse", token.AccessToken);
            Assert.AreEqual("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken);
            Assert.AreEqual("bearer", token.TokenType);
            Assert.AreEqual(2419200, token.ExpiresIn);
            Assert.AreEqual("Bob", token.AccountUsername);
            Assert.AreEqual("45344", token.AccountId);
        }
 public async Task GetTokenByCodeAsync_SetCodeInvalid_ThrowsImgurException()
 {
     var authentication = new ImgurClient(ClientId, ClientSecret);
     var endpoint = new OAuth2Endpoint(authentication);
     await endpoint.GetTokenByCodeAsync("abc");
 }
 public async Task GetTokenByCodeAsync_WithCodeNull_ThrowsArgumentNullException()
 {
     var client = new ImgurClient("123", "1234");
     var endpoint = new OAuth2Endpoint(client);
     await endpoint.GetTokenByCodeAsync(null);
 }