Example #1
0
        public void GivenIdWhenIdIsNotFoundThenNotFoundResultIsRetured()
        {
            long id = 5;

            var actual = sut.Update(id, null);

            Assert.IsType <NotFoundResult>(actual);
        }
Example #2
0
        public void Update_InvalidObjectPassed_ReturnsBadRequest()
        {
            var nameMissingItem = new TodoVO()
            {
                Id = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"), TaskName = "Dentist"
            };

            _controller.ModelState.AddModelError("Category", "Required");
            var badResponse = _controller.Update(nameMissingItem).Result;

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Example #3
0
        public void Update_ReturnsUpdatedTodo_GivenCorrectInputs()
        {
            // Arrange
            const int    testTodoId = 123;
            const string testName   = "Updated";
            var          oldTodo    = new Todo
            {
                Name = "Todo"
            };
            var updateTodo = new Todo
            {
                Name = testName
            };
            var mockRepo = new Mock <ITodoRepository>();

            mockRepo.Setup(repo => repo.Find(testTodoId))
            .Returns(oldTodo);
            var controller = new TodoController(mockRepo.Object);

            // Act
            var result = controller.Update(testTodoId, updateTodo);

            // Assert
            var okResult   = Assert.IsType <CreatedAtRouteResult>(result);
            var returnTodo = Assert.IsType <Todo>(okResult.Value);

            Assert.Equal(testName, returnTodo.Name);
        }
Example #4
0
        public void Test_Update_FailCase_MismatchId()
        {
            var lastItem   = (TodoItem)_context.TodoItems.LastOrDefault();
            var controller = new TodoController(_context);
            var result     = controller.Update(lastItem.Id - 1, lastItem);

            Assert.IsType <BadRequestResult>(result);
        }
Example #5
0
        public void Test_Update_SuccessCase()
        {
            var lastItem   = (TodoItem)_context.TodoItems.LastOrDefault();
            var controller = new TodoController(_context);

            lastItem.Name = "Updated item";
            var result = controller.Update(lastItem.Id, lastItem);

            Assert.IsType <NoContentResult>(result);
        }
Example #6
0
        public void Test_Update_FailCase_NonExistingItem()
        {
            var lastItem = (TodoItem)_context.TodoItems.LastOrDefault();
            var fakeItem = new TodoItem {
                Id = lastItem.Id + 1
            };
            var controller = new TodoController(_context);
            var result     = controller.Update(lastItem.Id + 1, fakeItem);

            Assert.IsType <NotFoundResult>(result);
        }
Example #7
0
        public void Update_ReturnsBadRequest_GivenNullModel()
        {
            // Arrange & Act
            const int testTodoId = 123;
            var       mockRepo   = new Mock <ITodoRepository>();
            var       controller = new TodoController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Act
            var result = controller.Update(testTodoId, payload: null);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public async Task TodoUpdate_WithValidModel_Return_OkResult()
        {
            //Arrange
            var toDoDto = new ToDoDTO
            {
                Title       = "FAKE",
                Description = "FAKE",
                IsComplete  = false,
                Time        = DateTime.Now.AddHours(2)
            };

            //Act
            var result = await _controller.Update(toDoDto);

            //Assert
            Assert.IsType <OkResult>(result);
        }
Example #9
0
        public void Update_ReturnsHttpNotFound_ForInvalidId()
        {
            // Arrange
            const int testTodoId = 123;
            var       mockRepo   = new Mock <ITodoRepository>();

            mockRepo.Setup(repo => repo.Find(testTodoId))
            .Returns((Todo)null);
            var controller = new TodoController(mockRepo.Object);

            // Act
            var result = controller.Update(testTodoId, new Todo {
                Name = "OK"
            });

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public void Update_Returns_NotFound_If_Todo_NotFound()
        {
            var options = CreateDbContextOptions();

            using (var todoApiDbContext = new TodoApiDbContext(options))
            {
                var mockLogger     = new Mock <ILogger <TodoController> >();
                var todoController = new TodoController(mockLogger.Object, todoApiDbContext);

                var todo = todoController.Update(15, new TodoItem()
                {
                    Id          = 15,
                    Description = "Write Blog Post"
                });

                Assert.IsType <NotFoundResult>(todo);
            }
        }
Example #11
0
        public void CanUpdateTodo()
        {
            const string expectedName = "go to work";

            var store = new Store();

            store.Add(new Todo("go to the gym"));
            var addedTodo = store.Add(new Todo("go to school")) as Todo;

            var controller = new TodoController(store);

            addedTodo.Name = expectedName;
            var updateResult = controller.Update(new TodoViewModel(addedTodo));
            var updatedTodo  = (updateResult.Data as TodoViewModel).Id;

            updatedTodo.Should().NotBeNull();

            store.Get <Todo>(1, 10).Should().HaveCount(2);
            store.Get <Todo>(1, 10).Should().ContainSingle(x => x.Name.Equals(expectedName));
        }
Example #12
0
        public void CanUpdateTodoItem()
        {
            DbContextOptions <TodoDbContext> options = new
                                                       DbContextOptionsBuilder <TodoDbContext>()
                                                       .UseInMemoryDatabase("Test3Database").Options;

            using (TodoDbContext context = new TodoDbContext(options))
            {
                // Arrange
                TodoItem datItem1 = new TodoItem();
                datItem1.ID         = 1;
                datItem1.Name       = "walk the dog";
                datItem1.IsComplete = false;
                datItem1.DatListID  = 1;

                // note: ID must be the same in order to update
                TodoItem datItem2 = new TodoItem();
                datItem2.ID         = 1;
                datItem2.Name       = "pet the dog";
                datItem2.IsComplete = true;
                datItem2.DatListID  = 2;

                TodoController ic = new TodoController(context);

                // Act
                var created1 = ic.Create(datItem1);

                var result1 = ic.Update(datItem1.ID, datItem2);
                var result2 = ic.GetById(datItem1.ID);

                // Assert
                Assert.Equal(datItem2.Name, result2.Result.Value.Name);
                Assert.Equal(datItem2.IsComplete, result2.Result.Value.IsComplete);
                Assert.Equal(datItem2.DatListID, result2.Result.Value.DatListID);
            }
        }
        public async Task Update_Update_An_Existing_Todo()
        {
            var options = CreateDbContextOptions();

            using (var todoApiDbContext = new TodoApiDbContext(options))
            {
                var mockLogger       = new Mock <ILogger <TodoController> >();
                var todoController   = new TodoController(mockLogger.Object, todoApiDbContext);
                var todoCreateResult = await todoController.Create(new TodoItem()
                {
                    Description = "Update this description"
                });

                var todoTemp = todoCreateResult as CreatedAtRouteResult;
                var id       = (todoTemp.Value as TodoItem).Id;
                var todo     = todoController.Update(id, new TodoItem()
                {
                    Id          = id,
                    Description = "Write Blog Post"
                });

                Assert.IsType <NoContentResult>(todo);
            }
        }