public async void GetAsync_Response_Count_MoreThen_0() { //Arrange User user = new User() { ClientUserId = "123" }; Response <User> item = new Response <User>() { Count = 1, Data = new List <User>() { user } }; string json = JsonConvert.SerializeObject(item); HttpContent content = new StringContent(json); HttpResponseMessage response = new HttpResponseMessage { Content = content }; ContentFromHttpResponseGetter <Response <User> > getter = new ContentFromHttpResponseGetter <Response <User> >(response); //Act Response <User> data = await getter.GetAsync(); //Assert Assert.True(data.Count > 0); }
public virtual async Task <T> PutAsync(string token, T item) { GenerateAddress(token); Response = await Sender.PutAsync(Address, item); if (!Response.IsSuccessStatusCode) { throw new HttpRequestException("Request is not success. The code of error: " + Response.StatusCode); } IGetterFromHttpResponseMessage <T> getter = new ContentFromHttpResponseGetter <T>(Response); return(await getter.GetAsync()); }
public virtual async Task <Response <T> > GetAsync() { Response = await Sender.GetAsync(Address); if (!Response.IsSuccessStatusCode) { throw new HttpRequestException("Request is not success. The code of error: " + Response.StatusCode); } IGetterFromHttpResponseMessage <Response <T> > getter = new ContentFromHttpResponseGetter <Response <T> >(Response); Response <T> result = await getter.GetAsync(); if (result.Count > 10) { result = await GetAll(result); } return(result); }
public async void GetAsync_ClientUserId_123() { //Arrange User item = new User() { ClientUserId = "123" }; string json = JsonConvert.SerializeObject(item); HttpContent content = new StringContent(json); HttpResponseMessage response = new HttpResponseMessage { Content = content }; ContentFromHttpResponseGetter <User> getter = new ContentFromHttpResponseGetter <User>(response); //Act User data = await getter.GetAsync(); //Assert Assert.True(data.ClientUserId == "123"); }
private async Task <Response <T> > GetAll(Response <T> result) { for (int i = 10; i < result.Count; i += 10) { string address = string.Format("{0}?offset={1}", Address, i); Response = await Sender.GetAsync(address); IGetterFromHttpResponseMessage <Response <T> > getter = new ContentFromHttpResponseGetter <Response <T> >(Response); Response <T> get = await getter.GetAsync(); if (get?.Data == null) { continue; } foreach (T t in get.Data) { result.Data.Add(t); result.Limit++; } } return(result); }