public IActionResult CompleteTodo(string id)
 {
     _todoService.Complete(id);
     return(Ok(new Response()
     {
         Message = "Task Marked as complete",
         Error = false
     }));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Complete(TodoReply item, CancellationToken cancellationToken)
        {
            CompleteRequest completeRequest = new()
            {
                Id = item.Id
            };

            await _todoService.Complete(completeRequest, cancellationToken);

            return(await Index(cancellationToken));
        }
    }
        public void TestTodoService_Complete_ShouldCompleteTodo()
        {
            // Arrange
            var expectedTodos = new TodoModel[] {
                new TodoModel {
                    Id = 1
                }
            };
            var mappedTodoDomainModel = new Mock <Todo>();
            // mock repository
            Mock <IRepository <TodoModel> > todoRepository = new Mock <IRepository <TodoModel> >();

            todoRepository.Setup(repo => repo.Find(It.IsAny <Expression <Func <TodoModel, bool> > >()))
            .Returns(expectedTodos.AsQueryable());
            todoRepository.Setup(repo => repo.Update(It.IsAny <TodoModel>()));
            // mock automapper
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(m => m.Map <Todo>(It.IsAny <TodoModel>()))
            .Returns(mappedTodoDomainModel.Object);
            mapperMock.Setup(m => m.Map <Todo, TodoModel>(It.IsAny <Todo>(), It.IsAny <TodoModel>()))
            .Returns(It.IsAny <TodoModel>());
            var cacheMock = new Mock <ICacheProvider>();

            var todoService = new TodoService(todoRepository.Object, mapperMock.Object, cacheMock.Object);

            // Act
            todoService.Complete(1);

            // Assert
            todoRepository.Verify(x => x.Find(It.IsAny <Expression <Func <TodoModel, bool> > >()), Times.Once);
            todoRepository.Verify(x => x.Update(It.IsAny <TodoModel>()), Times.Once);
            mapperMock.Verify(x => x.Map <Todo>(It.IsAny <TodoModel>()), Times.Once);
            mapperMock.Verify(x => x.Map <Todo, TodoModel>(It.IsAny <Todo>(), It.IsAny <TodoModel>()), Times.Once);
            mappedTodoDomainModel.Verify(x => x.Complete(), Times.Once);
        }