private static HttpRequestMessage CreateAuthHttpRequest(AppTokenRequest req) => new HttpRequestMessage(HttpMethod.Post, AuthRequestUri) { Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "client_id", req.Key }, { "client_secret", req.Secret }, { "grant_type", req.GrantType } }) };
public async Task <RestResponse <TRes> > PostAuthAsync <TRes>( Uri uri, AppTokenRequest content) where TRes : IDwollaResponse => await SendAsync <TRes>(new HttpRequestMessage(HttpMethod.Post, uri) { Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "client_id", content.Key }, { "client_secret", content.Secret }, { "grant_type", content.GrantType } }) });
public async void CreatePostAuthRequestAndPassToClient() { var response = CreateRestResponse(HttpMethod.Post, Response); var req = new AppTokenRequest { Key = "key", Secret = "secret" }; var request = CreateAuthHttpRequest(req); _restClient.Setup(x => x.SendAsync <TestResponse>(It.IsAny <HttpRequestMessage>())) .Callback <HttpRequestMessage>(y => AppTokenCallback(request, y)).ReturnsAsync(response); var actual = await _client.PostAuthAsync <TestResponse>(AuthRequestUri, req); Assert.Equal(response, actual); }
public async void CreatePostAuthRequestAndPassToClient() { var response = CreateRestResponse(HttpMethod.Post, Response); var req = new AppTokenRequest { Key = "key", Secret = "secret" }; var request = CreateAuthHttpRequest(req); messageHandler.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Callback <HttpRequestMessage, CancellationToken>((y, _) => AppTokenCallback(request, y)) .ReturnsAsync(response.Response) .Verifiable(); var actual = await _client.PostAuthAsync <TestResponse>(AuthRequestUri, req); Assert.Equal(response.Response, actual.Response); }
public async Task <RestResponse <TRes> > PostAuthAsync <TRes>( string uri, AppTokenRequest content) where TRes : IDwollaResponse { var formContentDict = new Dictionary <string, string> { { "grant_type", content.GrantType } }; if (!string.IsNullOrEmpty(content.Key) && !string.IsNullOrEmpty(content.Secret)) { formContentDict.Add("client_id", content.Key); formContentDict.Add("client_secret", content.Secret); } var request = new HttpRequestMessage(HttpMethod.Post, uri) { Content = new FormUrlEncodedContent(formContentDict) }; // Not adding this accept will result in a 401. For some reason. request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return(await SendAsync <TRes>(request).ConfigureAwait(false)); }