public async Task <List <TModel> > ReadAsync(FilterModel filter) { var name = ModelHelper.GetName(typeof(TModel).Name); var requestModel = new MyTelescopeRequestModel(name, Exchanger.ReadAction, filter); try { var content = await Exchanger.GetString(requestModel).ConfigureAwait(false); return(JsonConvert.DeserializeObject <List <TModel> >(content)); } catch (Exception exception) { LogHelper.LogError(exception); throw; } }
private string ExecuteExchangerRequest(string modelName) { var filter = GetFilter(); var exchanger = new MyTelescopeDataExchanger(); var requestModel = new MyTelescopeRequestModel(modelName, exchanger.ReadAction, filter); try { var contentTask = exchanger.GetString(requestModel); var contentResult = contentTask.Result; Assert.True(contentResult.Contains("["), "Invalid result"); return(contentResult); } catch (Exception exception) { Assert.True(string.IsNullOrEmpty(exception.Message), exception.Message); throw; } }
public void DataExchangerGetStringTest() { var expected = "Content"; var httpContent = new StringContent(expected, Encoding.UTF8, "application/text"); var dataExchanger = new Mock <MyTelescopeDataExchanger>(); dataExchanger.Setup(x => x.RequestContent(It.IsAny <IRequestModel>())).Returns( Task.Run(() => new HttpResponseMessage(HttpStatusCode.OK) { Content = httpContent })); var filter = new FilterModel( new SortModel(new SortItemModel("Id", true), 2, 5), new FilterItemModel("Code", ColumnType.StringColumn, FilterType.Equal, "iets")); var requestModel = new MyTelescopeRequestModel("{0}/{1}/{2}", "Actie", filter); var actual = dataExchanger.Object.GetString(requestModel).Result; Assert.Equal(expected, actual); }