Пример #1
0
        public async Task CrudTest()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_uri);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response;

                // HTTP POST
                var id = Guid.NewGuid();
                var User = new USER
                {
                    GUID_RECORD = id,
                    KEY = "KEY" + id.ToString()
 
                };

                response = await client.PostAsJsonAsync(_controller, User);

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP POST fail");

                // HTTP GET
                response = await client.GetAsync(_controller + id.ToString());

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP GET fail");

                var result = await response.Content.ReadAsAsync<USER>();

                Assert.AreEqual(User.GUID_RECORD, result.GUID_RECORD);
                Assert.AreEqual(User.KEY, result.KEY);


                // HTTP PUT
                User.KEY = User.KEY + "Upd";

                response = await client.PutAsJsonAsync(_controller + id.ToString(), User);

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP PUT fail");

                // HTTP DELETE
                response = await client.DeleteAsync(_controller + id.ToString());

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP DELETE fail");
            }
        }
Пример #2
0
        public async Task PostTest()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_uri);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response;

                // HTTP POST
                var id = Guid.NewGuid();
                var User = new USER
                {
                    GUID_RECORD = id,
                    KEY = "KEY" + id.ToString()

                };

                response = await client.PostAsJsonAsync(_controller, User);

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP POST fail");
            }
        }