Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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]));
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }