Пример #1
0
        public async Task <ControllerTestResponse <T> > Post <T>(T obj)
        {
            if (authPromise != null)
            {
                await authPromise.Task;
            }

            var jsonString = JsonSerializer.Serialize <T>(obj, jsonOptions);

            HttpContent httpContent = new StringContent(jsonString);

            HttpResponseMessage response = await HttpClient.PostAsync(BaseUri + BasePath, httpContent);

            var ctResponse = new ControllerTestResponse <T>()
            {
                Status = response.StatusCode
            };

            if (response.IsSuccessStatusCode)
            {
                var responseContentString = await response.Content.ReadAsStringAsync();

                ctResponse.Body = JsonSerializer.Deserialize <T>(responseContentString, jsonOptions);
            }

            return(ctResponse);
        }
Пример #2
0
        public async Task <ControllerTestResponse <T> > Delete <T>(int id, string postFix = "")
        {
            if (authPromise != null)
            {
                await authPromise.Task;
            }

            HttpResponseMessage response = await HttpClient.DeleteAsync(BaseUri + BasePath + "/" + id + postFix);

            var ctResponse = new ControllerTestResponse <T>()
            {
                Status = response.StatusCode
            };

            if (response.IsSuccessStatusCode && response.StatusCode != System.Net.HttpStatusCode.NoContent)
            {
                var responseContentString = await response.Content.ReadAsStringAsync();

                ctResponse.Body = JsonSerializer.Deserialize <T>(responseContentString, jsonOptions);
            }

            return(ctResponse);
        }
Пример #3
0
        public async Task <ControllerTestResponse <T> > GetList <T>(string urlPostfix = "")
        {
            if (authPromise != null)
            {
                await authPromise.Task;
            }

            HttpResponseMessage response = await HttpClient.GetAsync(BaseUri + BasePath + urlPostfix);

            var ctResponse = new ControllerTestResponse <T>()
            {
                Status = response.StatusCode
            };

            if (response.IsSuccessStatusCode)
            {
                var responseContentString = await response.Content.ReadAsStringAsync();

                ctResponse.Body = JsonSerializer.Deserialize <T>(responseContentString, jsonOptions);
            }

            return(ctResponse);
        }