コード例 #1
0
        public void When_getting_task_by_user_id_then_return_a_list_of_tasks()
        {
            var toDoItems = new List <ToDoItem> {
                new ToDoItem {
                    ToDoItemId = 1
                }, new ToDoItem {
                    ToDoItemId = 2
                }
            };

            _mockToDoItemRepository.Setup(x => x.GetToDoItemsByUser(It.IsAny <string>())).Returns(toDoItems);

            var result = _sut.GetToDoItemsByUser(It.IsAny <string>());

            Assert.Equal(toDoItems.Count, result.ToList().Count);
            Assert.Collection(result,
                              elem1 => { Assert.Equal(1, elem1.ToDoItemId); },
                              elem2 => { Assert.Equal(2, elem2.ToDoItemId); }
                              );

            _mockToDoItemRepository.Verify(x => x.GetToDoItemsByUser(It.IsAny <string>()), Times.Once);
        }
コード例 #2
0
        public ActionResult <List <ToDoItem> > GetToDoItemsByUser(string userId)
        {
            try
            {
                var toDoItems = _toDoItemBpc.GetToDoItemsByUser(userId);

                if (toDoItems.Count() == 0)
                {
                    return(NotFound($"No items found for user: {userId}"));
                }

                return(Ok(toDoItems));
            }
            catch (Exception e)
            {
                _logger.LogError($"Something went wrong when getting tasks by user. userId: {userId} - {e.Message}");
            }

            return(BadRequest());
        }