public async Task Sends_to_self_rel_when_authenticated(string nextUri) { _httpClientWrapper .Send("web-address", Arg.Any <HttpMethod>(), Arg.Any <HttpContent>(), Arg.Any <IDictionary <string, string> >()) .Returns(AuthorizedResponse(nextUri)); var result = await _sut.SendAsync(_resourceBuilder.Build()); Assert.That(result.Links, Is.Not.Null); Assert.That(result.Links.Single().Uri, Is.EqualTo(nextUri)); }
private async Task <object> HttpVerb(object[] args) { args.ParseHttpVerbArgs(); var httpMethodString = GetLastCall(); var uri = Extensions.GetUri(ToString(), args); var requestHeaders = args.GetRequestHeaders(); var httpMethod = (HttpMethod)typeof(HttpMethod).GetProperty(httpMethodString).GetValue(null); var httpContent = Extensions.ParseContent(httpMethodString, args); var httpResponseMessage = await _httpClientWrapper.Send(httpMethod, uri, requestHeaders, httpContent); return(new RestClientResponseObject(httpResponseMessage)); }
private async Task <object> HttpVerb(object[] args) { args.ValidateHttpVerbArgs(); var httpMethodString = GetLastCall(); var uri = Extensions.GetUri(httpMethodString, ToString(), args); var requestHeaders = args.GetRequestHeaders(); var httpContent = Extensions.ParseContent(httpMethodString, args); var httpResponseMessage = await _httpClientWrapper.Send(new HttpMethod(httpMethodString.ToUpperInvariant()), uri, requestHeaders, httpContent); return(new RestClientResponseObject(httpResponseMessage)); }
public async Task <Resource> SendAsync(Resource resource) { var headers = new Dictionary <string, string> { ["Content-type"] = _apiMediaType }; var selfLink = resource.GetUriForRel("/rels/self"); var httpMethodFromDataTemplate = new HttpMethod(resource.DataTemplate.Methods[0]); var jsonDataTemplate = new StringContent(JsonConvert.SerializeObject(resource.DataTemplate)); return(await CallApi <Resource>( headers, () => _httpClientWrapper.Send(selfLink, httpMethodFromDataTemplate, jsonDataTemplate, headers))); }
public async Task RenewToken(IDictionary <string, string> headers, string tokenUri = null) { if (string.IsNullOrEmpty(tokenUri)) { AddBearerToken(headers); } else { var response = await _httpClientWrapper.Send(tokenUri, HttpMethod.Post, _tokenRequestBody, _tokenHeaders); var token = await ConvertJsonBody.From(response).To <TokenResponse>(); AddBearerToken(headers, token.AccessToken); } }
public void SetUp() { _httpClient = Substitute.For <IHttpClientWrapper>(); _httpClient.Send( Arg.Any <string>(), Arg.Any <HttpMethod>(), Arg.Any <HttpContent>(), Arg.Any <IDictionary <string, string> >()) .Returns(TokenResponseFromApi("token-from-api")); var configuration = Substitute.For <IConfiguration>(); configuration.GetValue <string>("ApiSecretKey").Returns("test-auth-token"); _token = new Token(_httpClient, configuration); _headers = new Dictionary <string, string>(); }
public void SetUp() { _httpClientWrapper = Substitute.For <IHttpClientWrapper>(); _authenticate = Substitute.For <IAuthenticate>(); _resourceBuilder = new ResourceBuilder(); _resourceBuilder .WithDataTemplate() .WithLink("/rels/a /rels/self /rels/b", "web-address") .Build(); var configuration = Substitute.For <IConfiguration>(); configuration.GetValue <string>("ApiMediaType").Returns("test-media-value"); _sut = new ApiClient(_httpClientWrapper, _authenticate, configuration); _httpClientWrapper .Send( Arg.Any <string>(), Arg.Any <HttpMethod>(), Arg.Any <HttpContent>(), Arg.Any <IDictionary <string, string> >()) .Returns(NotFoundResponse); }