public async void Can_Add_Todo()
        {
            // Arrange
            var testTodo = new Todo.Data.Entities.Todo
            {
                Id          = Guid.NewGuid(),
                Description = "test todo",
                IsCompleted = false,
            };

            // Act
            using (var context = new TodoContext(_contextOptions))
            {
                var repository = new TodoRepository(context);
                var todo       = await repository.AddAsync(testTodo);
            }

            // Assert
            using (var context = new TodoContext(_contextOptions))
            {
                var todo = await context.Todos.FindAsync(testTodo.Id);

                Assert.Equal(testTodo.Id, todo.Id);
                Assert.Equal(testTodo.Description, todo.Description);
                Assert.Equal(testTodo.IsCompleted, todo.IsCompleted);
            }
        }
Exemple #2
0
        public async Task GetExistingItem()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_GetExistingItem").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var repository = new TodoRepository(context);
                var item       = new TodoItem
                {
                    Name = "Fake Item"
                };

                await repository.AddAsync(item);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var repository = new TodoRepository(context);
                var item       = await repository.GetAsync(1);

                Assert.Equal(1, item.Id);
                Assert.Equal("Fake Item", item.Name);
            }
        }
        public async Task <IActionResult> Create(CreateTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                // add todo and bing it to signed in user
                var signedInUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var user           = await userManager.FindByIdAsync(signedInUserId);

                var todo = await viewModelService.CreateTodoFromModelAsync(model, user);

                await todoRepository.AddAsync(todo);
                await SendUserDateOnTodosUpdateAsync();

                return(RedirectToAction("index", "todos"));
            }

            return(View());
        }
Exemple #4
0
 public async Task <Todo> Post([FromBody] Todo item)
 {
     return(await _todoService.AddAsync(item));
 }