public async Task Create_ThrowsExeption_ItemOfWipStatusWithPriority1AlreadyExists()
        {
            var item = new TodoItemVO {
                Id = 22, Priority = 1, Status = Status.Wip
            };

            _todoItemProvider.Setup(provider => provider.WipStatusWithPriority1Exists()).Returns(Task.FromResult(true));

            await Assert.ThrowsAsync <ArgumentException>(() => _todoItemService.Create(item));
        }
Beispiel #2
0
        public void CanCreateTask()
        {
            //arrange
            string taskName = "new Test Task";

            var settingsMock = new Mock <IMashAppConfig>();

            settingsMock.Setup(x => x.MiminumTaskNameLength).Returns(3);
            settingsMock.Setup(x => x.MaximumTaskNameLength).Returns(50);

            var repoMock = new Mock <ITodoItemRepository>();


            var statsMock = new Mock <IStatisticsRepository>();


            var service = new TodoItemService(repoMock.Object, statsMock.Object, settingsMock.Object);

            //act
            var createdGuid = service.Create(taskName).Result;

            //assert
            repoMock.Verify(x =>
                            x.Create(It.Is <TodoItem>(y =>
                                                      y.Name == taskName &&
                                                      y.Status == TodoStatus.Open &&
                                                      y.Id == createdGuid)),
                            Times.Once);
            statsMock.Verify(x => x.RaiseCreatedCount(), Times.Once);
        }
        private async void AddNewTask(object sender)
        {
            try
            {
                IsSending = true;
                var guid = await _service.Create(NewTaskName);

                if (guid != Guid.Empty)
                {
                    NewTaskName = string.Empty;
                }
                await RefreshTodos();
            }
            catch (ArgumentException ex)
            {
                _notifier.ShowInformation(ex.Message);
            }
            catch (TodoMashException ex)
            {
                _notifier.ShowError(ex.Message);
            }
            finally
            {
                IsSending = false;
            }
        }
        public ActionResult <TodoItem> PostTaskById(TodoItem todoItem)
        {
            int listId = int.Parse(this.Request.Query["listId"]);

            TodoItem createdItem = todoItemService.Create(todoItem, listId);

            return(createdItem);
        }
Beispiel #5
0
        // POST: api/TodoItem
        public IHttpActionResult Post([FromBody] TodoItemCreateViewModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            TodoItemGetViewModel model = _service.Create(value);

            return(CreatedAtRoute("DefaultApi", new { model.Id }, model));
        }
        public async Task <IActionResult> PostTodoItem([FromBody] TodoItem todoItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdId = await _context.Create(todoItem.Name);

            return(CreatedAtAction("GetTodoItem", new { id = createdId }, todoItem));
        }
Beispiel #7
0
        public async Task <ActionResult> Create(TodoItemDTO todoItemDTO)
        {
            if (ModelState.IsValid)
            {
                todoItemDTO = await todoItemService.Create(todoItemDTO);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(todoItemDTO));
        }
Beispiel #8
0
        public void ThrowsTaskNameIsNull()
        {
            string taskName = null;

            var settingsMock = new Mock <IMashAppConfig>();

            settingsMock.Setup(x => x.MiminumTaskNameLength).Returns(3);
            settingsMock.Setup(x => x.MaximumTaskNameLength).Returns(50);
            var repoMock  = new Mock <ITodoItemRepository>();
            var statsMock = new Mock <IStatisticsRepository>();
            var service   = new TodoItemService(repoMock.Object, statsMock.Object, settingsMock.Object);

            //act
            Assert.That(() => service.Create(taskName).Wait(),
                        Throws.Exception
                        .TypeOf <AggregateException>()
                        .With.Property("InnerException").TypeOf <ArgumentException>());
        }
Beispiel #9
0
        public async Task Create_Should_CallRepository()
        {
            // Arrange
            var item = new TodoItem();

            _repositoryMock
            .Setup(x => x.Create(item))
            .Returns(Task.CompletedTask);
            _unitOfWorkMock
            .Setup(x => x.Save())
            .ReturnsAsync(true);

            // Act
            var actual = await _service.Create(item);

            // Assert
            Assert.True(actual);
            _repositoryMock.Verify(x => x.Create(item), Times.Once());
            _unitOfWorkMock.Verify(x => x.Save(), Times.Once());
        }
        public ActionResult <TodoItem> PostTodoItem(int listId, TodoItem model)
        {
            TodoItem todoItem = service.Create(listId, model);

            return(Created($"api/todoItem/{todoItem.Id}", todoItem));
        }
Beispiel #11
0
        public ActionResult <TodoItem> Create(TodoItem todoItem)
        {
            _todoItemService.Create(todoItem);

            return(CreatedAtRoute("GetTodoItem", new { id = todoItem.Id.ToString() }, todoItem));
        }
Beispiel #12
0
        public ActionResult <TodoItem> PostTaskById(int listId, TodoItem todoItem)
        {
            TodoItem createdItem = todoItemService.Create(todoItem, listId);

            return(Created($"api/todolist/{listId}/tasks/{createdItem.Id}", createdItem));
        }