コード例 #1
0
 private void Seed()
 {
     _todoService.Add(new Todo()
     {
         Text = "abc"
     });
     _todoService.Add(new Todo()
     {
         Text = "abcA"
     });
 }
コード例 #2
0
        public void WhenChangeStatus_GivenTheIdIsNotFound_ThenFalseIsReturned()
        {
            // Arrange
            var invalidId = 333;

            // Act
            _todoService.Add(new DataModel.TodoItem {
                Id = 1, Description = "New"
            });
            var result = _todoService.ChangeStatus(invalidId, true);

            // Assert
            Assert.IsFalse(result, "false must be returned");
        }
コード例 #3
0
        public async Task WhenATodoItemIsAdded_ThenItemsCountIsIncreasedByOne()
        {
            // Arrange

            // Act
            var todoListBeforeAdding = await _todoService.GetAllTodoItemsAsync();

            _todoService.Add(new DataModel.TodoItem {
                Description = "New"
            });
            var todoListAfterAdding = await _todoService.GetAllTodoItemsAsync();

            // Assert
            Assert.IsTrue(todoListAfterAdding.Length == todoListBeforeAdding.Length + 1, "A new item must be added");
        }
コード例 #4
0
ファイル: TodoTest.cs プロジェクト: rcamara32/ToDo
        public void Add_New_Todo()
        {
            var teste   = new TodoService(mockTodoRepository.Object);
            var retorno = teste.Add(newTodo);

            Assert.IsTrue(retorno);
        }
コード例 #5
0
        public async Task <IActionResult> CreateTodo(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] Todo req,
            ILogger log)
        {
            var result = await _todoService.Add(req);

            return(new OkObjectResult(result));
        }
コード例 #6
0
        public void Add_NewItem_ReturnsResultObject()
        {
            // Arrange
            A.CallTo(() => _repository.AddItem(A <TodoItem> ._)).Returns(true);

            // Act
            var result = _todoService.Add(_todoItem.Title, _todoItem.Description);

            // Assert
            result.IsSuccess.Should().BeTrue();
            result.NewItem.Should().NotBeNull();
            result.NewItem.Title.Should().Be(_todoItem.Title);
            result.NewItem.Description.Should().Be(_todoItem.Description);
            result.NewItem.CreatedTimeStamp.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMilliseconds(100));
            result.NewItem.Id.Should().NotBeEmpty();
            result.NewItem.IsCompleted.Should().BeFalse();
        }
コード例 #7
0
        public void WhenATodoItemIsAdded_GivenItemIsNull_ThenReturnFalse()
        {
            // Arrange

            // Act
            var result = _todoService.Add(null);

            // Assert
            Assert.IsFalse(result, "Add must return false");
        }
コード例 #8
0
        public ActionResult Create(Todo model)
        {
            model.ID         = Guid.NewGuid();
            model.RegisterId = ((User)Session["login"]).ID;
            model.IsComplete = false;
            db.Add(model);

            return(RedirectToAction("Index"));
        }
コード例 #9
0
            public void ReturnsListOfItems()
            {
                _service.Add(new TodoItem()
                {
                    Name = "Task A"
                });
                _service.Add(new TodoItem()
                {
                    Name = "Task B"
                });

                var todoItems = _service.GetItems();

                Assert.Equal(3, todoItems.Count);
                Assert.Equal("Item1", todoItems.ElementAt(0).Name);
                Assert.Equal("Task A", todoItems.ElementAt(1).Name);
                Assert.Equal("Task B", todoItems.ElementAt(2).Name);
            }
コード例 #10
0
            public void SavesTodoItemByString()
            {
                TodoItem todoItem;

                using (var context = new TodoContext(_dbContextOptions))
                {
                    var service = new TodoService(context);
                    todoItem = service.Add("item1");
                }
                Assert.Equal("item1", todoItem.Name);
            }
コード例 #11
0
            public void ReturnsItemIfPresent()
            {
                var todoItem = _service.Add(new TodoItem()
                {
                    Name = "item0"
                });

                var result = _service.GetById(todoItem.Id);

                Assert.NotNull(result);
                Assert.Equal("item0", result.Name);
            }
コード例 #12
0
            public void RemovesItem()
            {
                var todoItem = _service.Add(new TodoItem()
                {
                    Name = "item0"
                });

                _service.Delete(todoItem.Id);

                var result = _service.GetById(todoItem.Id);

                Assert.Null(result);
            }
コード例 #13
0
        public async Task <IHttpActionResult> Post(TodoItemModel item)
        {
            item.Created = DateTime.Now;

            BllTodoItem result = await service.Add(item.ToBll());

            if (result == null)
            {
                return(BadRequest(ModelState));
            }

            return(CreatedAtRoute("DefaultApi", new { id = item.Id }, result.ToViewModel()));
        }
コード例 #14
0
            public void SavesTodoItemObject()
            {
                TodoItem todoItem;

                using (var context = new TodoContext(_dbContextOptions))
                {
                    var service = new TodoService(context);
                    todoItem = service.Add(new TodoItem()
                    {
                        Name = "item2"
                    });
                }
                Assert.Equal("item2", todoItem.Name);
            }
コード例 #15
0
            public void SetsNewValue()
            {
                var todoItem = _service.Add(new TodoItem()
                {
                    Name = "item0"
                });

                todoItem.Name = "item1";

                var result = _service.Update(todoItem);

                Assert.Equal(todoItem.Id, result.Id);
                Assert.Equal("item1", result.Name);
            }
コード例 #16
0
        public ApiResponse Post([FromBody] Todo value)
        {
            var response = new ApiResponse();

            try
            {
                response.Data = _todoService.Add(value);
            }
            catch (Exception ex)
            {
                response.HasError     = true;
                response.ErrorMessage = ex.Message;
            }
            response.ResponseDate = DateTime.Now;
            return(response);
        }
コード例 #17
0
        public async Task <IActionResult> AddTodo(TodoAddViewModel todo) //[FromBody]
        {
            if (todo != null)
            {
                // NOTE: Used AutoMapper for Object-to-Object mapping instead of old school viewModel
                var mappedViewModel = new Todo {
                    WorkTodo    = todo.WorkTodo,
                    IsCompleted = todo.IsCompleted
                };
                //var mappedViewModel = _mapper.Map<Todo>(todo);
                int result = await _todoService.Add(mappedViewModel).ConfigureAwait(false);

                return(Ok(result));
            }

            return(BadRequest());
        }
コード例 #18
0
 public IActionResult Add([FromBody] Todo todo)
 {
     return(Json(TodoService.Add(todo.text)));
 }
コード例 #19
0
 public bool Add(string value)
 {
     return(todoService.Add(value));
 }
コード例 #20
0
 public async Task NewTodo()
 {
     TodoService.Url    = Url;
     TodoService.Client = Http.CreateClient();
     Response           = await TodoService.Add(Request);
 }
コード例 #21
0
        public IHttpActionResult Put(string description)
        {
            var target = _service.Add(description);

            return(Ok(target));
        }