Exemplo n.º 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 Person = new PERSON
                {
                    GUID_RECORD = id,
                    FIRSTNAME = "AS " + id.ToString(),
                    LASTNAME = "SE " + id.ToString() ,
                    BIRTHDATE = DateTime.Now

                };

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

                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<PERSON>();

                Assert.AreEqual(Person.GUID_RECORD, result.GUID_RECORD);
                Assert.AreEqual(Person.FIRSTNAME, result.FIRSTNAME);
                Assert.AreEqual(Person.LASTNAME, result.LASTNAME);

                // HTTP PUT
                Person.FIRSTNAME = Person.FIRSTNAME + "GGGG";

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

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

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

                Assert.IsTrue(response.IsSuccessStatusCode, "HTTP DELETE fail");
            }
        }
Exemplo n.º 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 Person = new PERSON
                {
                    GUID_RECORD = id,
                    FIRSTNAME = "AS " + id.ToString(),
                    LASTNAME = "SE " + id.ToString(),
                    BIRTHDATE = DateTime.Now

                };

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

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