public void SupportsODataInLinq()
        {
            var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress };

            var persons = client.CreateQuery<Person>().Where(p => p.FirstName == "John").OrderBy(p => p.Id).Skip(1).Take(1).ToList();

            Assert.IsNotNull(persons);
            Assert.IsTrue(persons.Count == 1);
            Assert.IsTrue(persons[0].Id == 2);
        }
        public void CanGetJsonEnumerable()
        {
            var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress };
            client.DefaultRequestHeaders.Add("Accept", AcceptType.Json);

            var response = client.GetAsync("persons").Result;

            var persons = response.Content.ReadAsAsync<IEnumerable<Person>>().Result.ToList();

            Assert.IsTrue(persons.Count == 5);
        }
Пример #3
0
        public void CanGetStringContent()
        {
            var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress };
            var response = client.GetAsync("persons").Result;

            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);

            var content = response.Content.ReadAsStringAsync().Result;

            Assert.IsNotNull(content);
            Assert.IsTrue(content.Length > 0);
        }
        public void CanGetXmlContent()
        {
            var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress };
            client.DefaultRequestHeaders.Add("Accept", AcceptType.Xml);

            var response = client.GetAsync("persons/1").Result;

            var person = response.Content.ReadAsAsync<Person>().Result;

            Assert.IsTrue(person.Id == 1);
            Assert.IsTrue(person.FirstName == "John");
            Assert.IsTrue(person.LastName == "Smith");
        }
Пример #5
0
        public void CancelationTest()
        {
            TimeoutManager.TimeoutInMilliseconds = 0;

            var client = new HttpClient() { BaseAddress = BaseApiUriAddress };
            var response = client.GetAsync("persons");

            Thread.Sleep(2000);

            try
            {
                Assert.IsNotNull(response.Result);
            }
            catch (AggregateException exception)
            {
                Assert.AreEqual(exception.InnerExceptions.Count, 1);
                var requestException = exception.InnerException.InnerException as WebException;
                Assert.IsNotNull(requestException);
                Assert.AreEqual(requestException.Status, WebExceptionStatus.RequestCanceled);
            }

            TimeoutManager.TimeoutInMilliseconds = 100 * 1000;
        }