Exemplo n.º 1
0
        public async Task WhenRequestOwnerControllerUsingPostWithOwnerOnBody_AndRequestOwnerControllerUsingGet_ThenVerifyIfOwnerWasAdded_ThenRequestOwnerControllerUsingPutWithUpdatedOwnerOnBody_AndRequestOwnerControllerUsingGet_ThenVerifyIfOwnerWasUpdated()
        {
            // Arrange
            var owner = OwnerHelper.CreateRandomOwner();

            // Act
            var post_response = await client.PostAsync($"{url}",
                                                       new StringContent(JsonConvert.SerializeObject(owner), Encoding.UTF8, "application/json"));

            Assert.AreEqual(post_response.StatusCode, System.Net.HttpStatusCode.OK);

            var get_response = await client.GetAsync($"{url}/{owner.Id}");

            Assert.AreEqual(get_response.StatusCode, System.Net.HttpStatusCode.OK);
            OwnerHelper.AssertOwner(owner, JsonConvert.DeserializeObject <Owner>(await get_response.Content.ReadAsStringAsync()));

            var updatedOwner = OwnerHelper.CreateRandomOwner();

            updatedOwner.Id = owner.Id;
            var put_response = await client.PutAsync($"{url}/{owner.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(updatedOwner), Encoding.UTF8, "application/json"));

            Assert.AreEqual(put_response.StatusCode, System.Net.HttpStatusCode.OK);

            get_response = await client.GetAsync($"{url}/{owner.Id}");

            Assert.AreEqual(get_response.StatusCode, System.Net.HttpStatusCode.OK);
            OwnerHelper.AssertOwner(updatedOwner, JsonConvert.DeserializeObject <Owner>(await get_response.Content.ReadAsStringAsync()));
        }
Exemplo n.º 2
0
        public async Task WhenRequestOwnerControllerUsingPost_ThenICheckIfOwnerWasAdded()
        {
            // Arrange
            var owner = OwnerHelper.CreateRandomOwner();

            client = new HttpClient();

            // Act
            var response = await client.PostAsync($"{url}",
                                                  new StringContent(JsonConvert.SerializeObject(owner), Encoding.UTF8, "application/json"));

            // Assert
            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
        }
Exemplo n.º 3
0
        public async Task WhenRequestOwnerControllerUsingPost_ThenVerifyIfOwnerWasCreatedUsingGetRequest_ThenISendDeleteRequestToOwnerController_ThenICantFindOwnerOnGet()
        {
            // Arrange
            var owner = OwnerHelper.CreateRandomOwner();

            client = new HttpClient();
            var insert_response = await client.PostAsync($"{url}",
                                                         new StringContent(JsonConvert.SerializeObject(owner), Encoding.UTF8, "application/json"));

            var get_response = await client.GetAsync($"{url}/{owner.Id}");

            // Act
            var delete_response = await client.DeleteAsync($"{url}/{owner.Id}");

            get_response = await client.GetAsync($"{url}/{owner.Id}");

            var test = get_response.Content.ReadAsStringAsync();

            // Assert
            Assert.AreEqual(get_response.StatusCode, System.Net.HttpStatusCode.NoContent);
        }