public async Task GetProductsSuccess() { var response = await _httpClient.GetAsync <ProductList>(_endpoints.Products); Assert.AreEqual(response.HttpStatusCode, HttpStatusCode.OK); Assert.IsTrue(response.Success); Assert.IsNotNull(response.Model); }
protected T GetFromAPI <T>(string apiMethodwithParameter, out bool error) where T : class { error = false; WebApiResult <T> result = null; try { ApiHttpClient <T> httpClient = new ApiHttpClient <T>(ServiceUrl, false); SetToken(httpClient); result = httpClient.GetAsync(apiMethodwithParameter).Result; if (!result.HasError) { return(result.Data); } else { error = true; Error(apiMethodwithParameter, result.ErrorMessages); } } catch (Exception ex) { _logger.Error(ex.ToString()); } return(null); }
private static async Task <JObject> GetOffice365Detail(Token token) { ApiHttpClient <JObject> client = new ApiHttpClient <JObject>(Settings.GraphApiDiscoveryPath, false); client.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.token_type, token.access_token); var result = await client.GetAsync(""); return(result.Data); }
public async Task <MajorIndex> GetMajorIndex(MajorIndexType IndexType) { using (ApiHttpClient client = new ApiHttpClient()) { string uri = "majors-indexes/" + GetUriSfx(IndexType) + "?apikey=" + APIKey; MajorIndex majorIndex = await client.GetAsync <MajorIndex>(uri); majorIndex.Type = IndexType; Debug.Write("\r\n************************************"); Debug.Write("\r\nURI: " + uri); Debug.Write("\r\nIndexName: " + majorIndex.IndexName); Debug.Write("\r\nIndexPrice: " + majorIndex.Price); Debug.Write("\r\nIndexChange: " + majorIndex.Changes); Debug.Write("\r\nIndexType: " + majorIndex.Type.ToString()); Debug.Write("\r\n************************************"); return(majorIndex); } }
public async Task <double> GetPrice(string symbol) { using (ApiHttpClient client = new ApiHttpClient()) { string uri = "stock/real-time-price/" + symbol + "?apikey=" + APIKey; StockPriceResult SPR = await client.GetAsync <StockPriceResult>(uri); if (SPR.Price == 0) { throw new InvalidSymbolX(symbol); } Debug.Write("\r\n===================================="); Debug.Write("\r\nURI: " + uri); Debug.Write("\r\nIndexSymbol: " + SPR.Symbol); Debug.Write("\r\nIndexPrice: " + SPR.Price); Debug.Write("\r\n===================================="); return(SPR.Price); } }
public async void TokenTest(String token, String state) { _Client.Token = token; var infs = await _Client.InvokeAsync <IDictionary <String, Object> >("api/info", new { state }); Assert.NotNull(infs); Assert.Equal(token, infs["token"]); _Client.Token = null; // 另一个客户端,共用令牌,应该可以拿到上一次状态数据 var client2 = new ApiHttpClient("http://127.0.0.1:12347") { Log = XTrace.Log, Token = token, }; infs = await client2.GetAsync <IDictionary <String, Object> >("api/info"); Assert.NotNull(infs); Assert.Equal(state, infs["LastState"]); }
public async void TokenTest(String token, String state) { var client = new ApiHttpClient(_Address) { Token = token }; var ac = client as IApiClient; var infs = await ac.InvokeAsync <IDictionary <String, Object> >("api/info", new { state }); Assert.NotNull(infs); Assert.Equal(token, infs["token"]); // 另一个客户端,共用令牌,应该可以拿到上一次状态数据 var client2 = new ApiHttpClient(_Address) { Token = token }; infs = await client2.GetAsync <IDictionary <String, Object> >("api/info"); Assert.NotNull(infs); Assert.Equal(state, infs["LastState"]); }