Beispiel #1
0
        public async Task AddToDoItem_NoNameTask()
        {
            using (var context = new ToDoListContext(ContextOptions))
            {
                // arrange
                var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper);

                var newToDo = new ToDoItemVm
                {
                    TaskName = ""
                };

                // act
                var result = await toDoListService.AddToDoItem(newToDo);

                // assert
                Assert.IsNull(result);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add a new item to the to-do list repository
        /// </summary>
        /// <param name="newToDoItemVm"></param>
        /// <exception cref="ArgumentNullException">If newToDoItemVm param is null</exception>
        /// <returns>The new To-do item with the populated key</returns>
        public async Task <ToDoItemVm> AddToDoItem(ToDoItemVm newToDoItemVm)
        {
            if (newToDoItemVm is null)
            {
                throw new ArgumentNullException(nameof(newToDoItemVm));
            }

            if (!(newToDoItemVm.Id == default))
            {
                return(null);
            }

            var newToDoItem = _mapper.Map <ToDoItem>(newToDoItemVm);

            if (string.IsNullOrWhiteSpace(newToDoItem.TaskName))
            {
                return(null);
            }

            var result = await _todoRepo.Add(newToDoItem);

            return(_mapper.Map <ToDoItemVm>(result));
        }
Beispiel #3
0
        public async Task AddToDoItem_Expected()
        {
            using (var context = new ToDoListContext(ContextOptions))
            {
                // arrange
                var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper);

                var newToDo = new ToDoItemVm
                {
                    TaskName = "Task 3"
                };

                // act
                var result = await toDoListService.AddToDoItem(newToDo);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual("Task 3", result.TaskName);

                var toDoCount = context.Set <ToDoItem>().Count();
                Assert.AreEqual(3, toDoCount);
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Create(ToDoItemVm newToDoItem)
        {
            var result = await _toDoListService.AddToDoItem(newToDoItem);

            return(Ok(result));
        }