public async Task Token_is_refreshed_if_expired(string methodName, OAuthOptions options, Uri requestUri, string accessToken, long expiresIn, TestClock clock)
        {
            Clock.Set(clock);

            var method = new HttpMethod(methodName);

            var httpOptions = new List <HttpMessageOptions>();

            var refreshTokenOptions = new HttpMessageOptions
            {
                HttpMethod  = HttpMethod.Post,
                RequestUri  = new Uri(requestUri, "/oauth/v1/token"),
                HttpContent = new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    ["grant_type"]    = "refresh_token",
                    ["client_id"]     = options.ClientId,
                    ["client_secret"] = options.SecretKey,
                    ["redirect_uri"]  = options.RedirectUri.ToString(),
                    ["refresh_token"] = options.RefreshToken
                }),
                HttpResponseMessage = CreateNewResponse()
            };

            httpOptions.Add(refreshTokenOptions);


            var requestOption = new HttpMessageOptions
            {
                RequestUri          = requestUri,
                HttpMethod          = method,
                HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            };

            httpOptions.Add(requestOption);

            var client = CreateClient(options, httpOptions.ToArray());

            await MakeARequest();

            clock.AdvanceBy(TimeSpan.FromSeconds(expiresIn + 1));

            refreshTokenOptions.HttpResponseMessage = CreateNewResponse();

            await MakeARequest();

            Assert.That(refreshTokenOptions.NumberOfTimesCalled, Is.EqualTo(2));

            HttpResponseMessage CreateNewResponse()
            {
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = JsonContent.FromObject(new
                    {
                        access_token = accessToken,
                        expires_in = expiresIn
                    })
                });
            }

            async Task MakeARequest()
            {
                var request = new HttpRequestMessage(method, requestUri);
                await client.SendAsync(request);
            }
        }