コード例 #1
0
        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;
            }
        }
コード例 #2
0
ファイル: ApiTest.cs プロジェクト: StefanWentink/MyTelescope
        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;
            }
        }
コード例 #3
0
        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);
        }