Exemplo n.º 1
0
        public async Task ShouldCreateNew()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.PostAsync(
                "tasks/new",
                Serialize(new
            {
                name = "Buy an avocado",
                priority = 1,
                status = "Completed"
            }));

            var result = await response.Content.ReadAsStringAsync();

            // Assert

            Assert.True(response.IsSuccessStatusCode);
            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
Exemplo n.º 2
0
        public async Task ShouldReturn400WhenDeleteInvalid()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.DeleteAsync($"tasks/delete/{tasks[1].Id}");

            // Assert

            Assert.Equal(400, (int)response.StatusCode);
        }
Exemplo n.º 3
0
        public async Task ShouldDelete()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.DeleteAsync($"tasks/delete/{tasks[0].Id}");

            // Assert

            Assert.True(response.IsSuccessStatusCode);
        }
Exemplo n.º 4
0
        public async Task ShouldGetAll()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.GetAsync("tasks/all");

            var result = await DeserializeAsync <IEnumerable <TodoTaskDto> >(response.Content);

            // Assert

            Assert.True(response.IsSuccessStatusCode);
            Assert.Collection(result,
                              model => AssertEqualToEntity(model, tasks[0]),
                              model => AssertEqualToEntity(model, tasks[1]));
        }
Exemplo n.º 5
0
        public async Task ShouldReturn400WhenNewTaskInvalid()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.PostAsync(
                "tasks/new",
                Serialize(new
            {
                name = "Buy an avocado",
                priority = 0,
                status = "Completed"
            }));

            // Assert

            Assert.Equal(400, (int)response.StatusCode);
        }
Exemplo n.º 6
0
        public async Task ShouldUpdate()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.PutAsync(
                $"tasks/update",
                Serialize(new
            {
                id = tasks[0].Id,
                name = "Buy an avocado",
                priority = 1,
                status = "Completed"
            }));

            // Assert

            Assert.True(response.IsSuccessStatusCode);
        }
Exemplo n.º 7
0
        public async Task ShouldReturn400WhenUpdateInvalid()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.PutAsync(
                $"tasks/update",
                Serialize(new
            {
                id = tasks[0].Id,
                name = tasks[1].Name,
                priority = 1,
                status = "Completed"
            }));

            // Assert

            Assert.Equal(400, (int)response.StatusCode);
        }
Exemplo n.º 8
0
        public async Task ShouldReturn400WhenUpdateMissingTask()
        {
            // Arrange

            using var server = new WebAppFixture(TodoTaskControllerTests.tasks);
            using var client = server.CreateClient();

            // Act

            var response = await client.PutAsync(
                $"tasks/update",
                Serialize(new
            {
                id = Guid.NewGuid().ToString(),
                name = "Buy an avocado",
                priority = 1,
                status = "Completed"
            }));

            // Assert

            Assert.Equal(400, (int)response.StatusCode);
        }