예제 #1
0
        public async Task ReplaceTodoItem_Should_ReturnUnprocessableEntity()
        {
            // Arrange
            var model = new Models.TodoItemToUpdate
            {
                Description = "Test updated"
            };

            _controller.ModelState.AddModelError(nameof(Models.TodoItemToUpdate.Title), "Title is required");

            // Act
            var result = await _controller.ReplaceTodoItem(Guid.NewGuid(), model);

            // Assert
            Assert.IsType <UnprocessableEntityObjectResult>(result);
        }
예제 #2
0
        public async Task ReplaceTodoItem_Should_ReturnNotFound()
        {
            // Arrange
            var guid  = Guid.NewGuid();
            var model = new Models.TodoItemToUpdate
            {
                Title = "Test updated"
            };

            _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync((TodoItem)null);

            // Act
            var result = await _controller.ReplaceTodoItem(guid, model);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
예제 #3
0
        public async Task ReplaceTodoItem_Should_ThrowException_WhenSaveFails()
        {
            // Arrange
            var guid   = Guid.NewGuid();
            var entity = new TodoItem
            {
                Id    = guid,
                Title = "Test"
            };
            var model = new Models.TodoItemToUpdate
            {
                Title = "Test updated"
            };

            _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync(entity);
            _serviceMock.Setup(x => x.Update(It.IsAny <TodoItem>())).ReturnsAsync(false);

            // Act && Assert
            await Assert.ThrowsAsync <ApiException>(() => _controller.ReplaceTodoItem(guid, model));
        }
예제 #4
0
        public async Task ReplaceTodoItem_Should_ReturnNoContent()
        {
            // Arrange
            var guid   = Guid.NewGuid();
            var entity = new TodoItem
            {
                Id    = guid,
                Title = "Test"
            };
            var model = new Models.TodoItemToUpdate
            {
                Title = "Test updated"
            };

            _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync(entity);
            _serviceMock.Setup(x => x.Update(It.IsAny <TodoItem>())).ReturnsAsync(true);

            // Act
            var result = await _controller.ReplaceTodoItem(guid, model);

            // Assert
            Assert.IsType <NoContentResult>(result);
            Assert.Equal(model.Title, entity.Title);
        }