GetAccessTokenAsync() private method

private GetAccessTokenAsync ( ) : TimeSpan>>.Task
return TimeSpan>>.Task
        public async Task GetAccessTokenAsync_Test()
        {
            using (var mockHandler = new HttpMessageHandlerMock())
                using (var http = new HttpClient(mockHandler))
                {
                    var translateApi = new MicrosoftTranslatorApi(http);

                    mockHandler.Enqueue(x =>
                    {
                        Assert.Equal(HttpMethod.Post, x.Method);
                        Assert.Equal(MicrosoftTranslatorApi.IssueTokenEndpoint, x.RequestUri);

                        var keyHeader = x.Headers.First(y => y.Key == "Ocp-Apim-Subscription-Key");
                        Assert.Equal(ApplicationSettings.TranslatorSubscriptionKey, keyHeader.Value.Single());

                        return(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new StringContent(@"ACCESS_TOKEN"),
                        });
                    });

                    var result = await translateApi.GetAccessTokenAsync()
                                 .ConfigureAwait(false);

                    var expectedToken = (@"ACCESS_TOKEN", TimeSpan.FromMinutes(10));
                    Assert.Equal(expectedToken, result);

                    Assert.Equal(0, mockHandler.QueueCount);
                }
        }
        public async Task GetAccessTokenAsync_Test()
        {
            using (var mockHandler = new HttpMessageHandlerMock())
                using (var http = new HttpClient(mockHandler))
                {
                    var translateApi = new MicrosoftTranslatorApi(http);

                    mockHandler.Enqueue(async x =>
                    {
                        Assert.Equal(HttpMethod.Post, x.Method);
                        Assert.Equal(MicrosoftTranslatorApi.OAuthEndpoint, x.RequestUri);

                        var body = await x.Content.ReadAsStringAsync()
                                   .ConfigureAwait(false);
                        var query = HttpUtility.ParseQueryString(body);

                        Assert.Equal("client_credentials", query["grant_type"]);
                        Assert.Equal(ApplicationSettings.AzureClientId, query["client_id"]);
                        Assert.Equal(ApplicationSettings.AzureClientSecret, query["client_secret"]);
                        Assert.Equal("http://api.microsofttranslator.com", query["scope"]);

                        return(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new StringContent(@"
{
  ""access_token"": ""12345acbde"",
  ""token_type"": ""bearer"",
  ""expires_in"": 3600
}"),
                        });
                    });

                    var result = await translateApi.GetAccessTokenAsync()
                                 .ConfigureAwait(false);

                    var expectedToken = (@"12345acbde", TimeSpan.FromSeconds(3600));
                    Assert.Equal(expectedToken, result);

                    Assert.Equal(0, mockHandler.QueueCount);
                }
        }
        public async Task GetAccessTokenAsync_Test()
        {
            using (var mockHandler = new HttpMessageHandlerMock())
            using (var http = new HttpClient(mockHandler))
            {
                var translateApi = new MicrosoftTranslatorApi(http);

                mockHandler.Enqueue(async x =>
                {
                    Assert.Equal(HttpMethod.Post, x.Method);
                    Assert.Equal(MicrosoftTranslatorApi.OAuthEndpoint, x.RequestUri);

                    var body = await x.Content.ReadAsStringAsync()
                        .ConfigureAwait(false);
                    var query = HttpUtility.ParseQueryString(body);

                    Assert.Equal("client_credentials", query["grant_type"]);
                    Assert.Equal(ApplicationSettings.AzureClientId, query["client_id"]);
                    Assert.Equal(ApplicationSettings.AzureClientSecret, query["client_secret"]);
                    Assert.Equal("http://api.microsofttranslator.com", query["scope"]);

                    return new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(@"
{
  ""access_token"": ""12345acbde"",
  ""token_type"": ""bearer"",
  ""expires_in"": 3600
}"),
                    };
                });

                var result = await translateApi.GetAccessTokenAsync()
                    .ConfigureAwait(false);

                var expectedToken = Tuple.Create(@"12345acbde", TimeSpan.FromSeconds(3600));
                Assert.Equal(expectedToken, result);

                Assert.Equal(0, mockHandler.QueueCount);
            }
        }