public void PutTest()
        {
            Todo mockTodo    = new Todo(0, "an updated item", 2, false);
            Todo updatedTodo = tc.Put(mockTodo.todoItemId, mockTodo);

            Assert.AreEqual(mockTodo, updatedTodo);
        }
Beispiel #2
0
        public async Task Put_Is_Ok()
        {
            // Arrange
            var mockTodoService = new Mock <ITodoService>();
            var mockTodoMapper  = new Mock <ITodoModelDtoMapper>();

            mockTodoService.Setup(s => s.UpdateTodo(It.IsAny <Guid>(), It.IsAny <TodoDto>()))
            .ReturnsAsync(new TodoDto());
            mockTodoMapper.Setup(s => s.Map(It.IsAny <TodoRequestModel>()))
            .Returns(new TodoDto());
            mockTodoMapper.Setup(s => s.Map(It.IsAny <TodoDto>()))
            .Returns(new TodoResponseModel());

            var controller = new TodosController(mockTodoService.Object, mockTodoMapper.Object);

            // Act
            var result = await controller.Put(It.IsAny <Guid>(), It.IsAny <TodoRequestModel>());

            // Assert
            result.Result.Should().BeOfType <OkObjectResult>();
            var resultObject = result.GetObjectResult();

            resultObject.Should().BeOfType <TodoResponseModel>();
            resultObject.Should().NotBeNull();
            mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoRequestModel>()), Times.Once);
            mockTodoService.Verify(c => c.UpdateTodo(It.IsAny <Guid>(), It.IsAny <TodoDto>()), Times.Once);;
            mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoDto>()), Times.Once);
        }
Beispiel #3
0
 public void canAddTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var list = c.Get();
         var newid = list.Last().ID + 1;
         var newitem = new Todos { ID = newid, Description = $"New item {newid}", IsComplete = false };
         c.Put(newid, newitem);
         int newcount = c.Get().Count();
         Assert.AreEqual(newid, newcount);
     }
 }
Beispiel #4
0
        public void Put()
        {
            // Arrange
            setupContext();
            TodosController controller = new TodosController(mockContext.Object);

            // Act
            controller.Put(1);

            // Assert
            mockSet.Verify(m => m.Find(It.Is <int>(i => i == 1)), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
            Assert.AreEqual(mockData.First().Completed, true);
        }
        public void PutWithCommentStoresAndSetsDates()
        {
            //Given
            var now = DateTime.Now;
            var todoCommentWithChange = new TodoComment {
                Id = 1, Text = "A Comment", UpdatedOn = now
            };
            var todoCommentWithoutChange = new TodoComment {
                Id = 2, Text = "Unchanged", UpdatedOn = now
            };
            var todo = new Todo {
                Id = 5, TodoComments = new List <TodoComment> {
                    todoCommentWithChange, todoCommentWithoutChange
                }
            };
            var todosRepository = new TestTodosRepository();
            var todosController = new TodosController(todosRepository);

            //When
            todosRepository.Add(todo);
            todoCommentWithChange.Text = "Changed comment"; // Change the comment

            var rc = todosController.Put(todo);

            //Then
            Assert.True(1 == rc.Count(), "Count is wrong");
            Assert.True(5 == rc.First().Id, "Todo Id is wrong");

            var cChanged = rc.First().TodoComments.First();

            Assert.True(1 == cChanged.Id, "TodoComment.Id is wrong");
            Assert.True(now < cChanged.UpdatedOn, "UpdatedOn should have been set");

            var cUnchanged = rc.First().TodoComments.Skip(1).First();

            Assert.True(2 == cUnchanged.Id, "Second TodoComment.Id is wrong");
            Assert.True(now == cUnchanged.UpdatedOn, "UpdatedOn should not have been set");
        }
        public void PutStores()
        {
            //Given
            var createDate      = DateTime.Now.ToUniversalTime().Subtract(TimeSpan.FromDays(1.0));
            var todosRepository = new TestTodosRepository {
                Todos = new Dictionary <int, Todo> {
                    { 5, new Todo {
                          Id = 5, Task = "ZZZZ", CreateDate = createDate
                      } }
                }
            };
            var todosController = new TodosController(todosRepository);
            var todo            = todosController.Get(5).First();

            todo.Task = "Task";
            //When
            var rc = todosController.Put(todo);

            //Then
            Assert.True(1 == rc.Count(), "Count is wrong");
            Assert.True(todo.Id == rc.First().Id, "Id is wrong");
            Assert.True(createDate == todo.CreateDate, "CreateDate should not have changed");
            Assert.True("Task" == rc.First().Task, "Task is not correct - was the Put todo stored?");
        }