Beispiel #1
0
        public async Task Get_Should_Delete_All_Person()
        {
            // Arrange
            var request     = new HttpRequestMessage(new HttpMethod("GET"), "/api/Person");
            var accessToken = FakeJwtManager.GenerateJwtToken();

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            // ACT
            var response = await _client.SendAsync(request);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            List <Person> lista;

            using (Stream stream = await response.Content.ReadAsStreamAsync())
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    string responseContent = streamReader.ReadToEnd();

                    lista = responseContent.ToObjects <Person>();
                }

            int n = 0;

            foreach (var person in lista)
            {
                n += 1;
                var requestDel = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/Person/{person.Id}");
                requestDel.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // ACT
                var responseDel = await _client.SendAsync(requestDel);

                responseDel.EnsureSuccessStatusCode();
                Assert.Equal(HttpStatusCode.NoContent, responseDel.StatusCode);

                var request2 = new HttpRequestMessage(new HttpMethod("GET"), "/api/Person");
                request2.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                response = await _client.SendAsync(request2);

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                using (Stream stream = await response.Content.ReadAsStreamAsync())
                    using (StreamReader streamReader = new StreamReader(stream))
                    {
                        string responseContent = streamReader.ReadToEnd();

                        var result = responseContent.ToObjects <Person>();
                        result.Should().HaveCount(lista.Count - n);
                    }
            }
        }
Beispiel #2
0
        public async Task Get_Should_Retrieve_All_Person(string method)
        {
            // Arrange
            var request     = new HttpRequestMessage(new HttpMethod(method), "/api/Person");
            var accessToken = FakeJwtManager.GenerateJwtToken();

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            // ACT
            var response = await _client.SendAsync(request);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            using (Stream stream = await response.Content.ReadAsStreamAsync())
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    string responseContent = streamReader.ReadToEnd();

                    var lista = responseContent.ToObjects <Person>();
                    lista.Should().HaveCount(100);
                }
        }