Beispiel #1
0
        public async Task GetTodoItemAsync_WithInvalidIdAndExistingElement_ShouldThrowException(long id)
        {
            // Arrange
            var expectedTodoItem = CreateFakeTodoItem();
            var options          = GetInMemoryOptions();
            var mapper           = GetMapper();

            ClearDataBase(options);

            using (var context = new ApplicationDbContext(options))
            {
                await context.TodoItems.AddAsync(expectedTodoItem);

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context, mapper);

                // Act / Assert
                await Assert.ThrowsAsync <ArgumentException>("id", () => service.GetTodoItemAsync(id));
            }

            ClearDataBase(options);
        }
Beispiel #2
0
        public async Task GetTodoItemAsync_WithValidId_ShouldReturnDTO()
        {
            // Arrange
            var expectedTodoItem = CreateFakeTodoItem();
            var options          = GetInMemoryOptions();
            var mapper           = GetMapper();

            ClearDataBase(options);

            using (var context = new ApplicationDbContext(options))
            {
                await context.TodoItems.AddAsync(expectedTodoItem);

                await context.SaveChangesAsync();
            }

            // Act
            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context, mapper);
                var todoItem = await service.GetTodoItemAsync(expectedTodoItem.Id);

                // Assert
                Assert.NotNull(todoItem);
                Assert.Equal(expectedTodoItem.Name, todoItem.Name);
                Assert.Equal(expectedTodoItem.Description, todoItem.Description);
                Assert.Equal(expectedTodoItem.IsComplete, todoItem.IsComplete);
                Assert.Equal(expectedTodoItem.DueAt, todoItem.DueAt);
                Assert.Equal(expectedTodoItem.Order, todoItem.Order);
            }

            ClearDataBase(options);
        }
        public async Task <ActionResult> DeleteAsync(string id, string category)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TodoItem item = await TodoItemService.GetTodoItemAsync(id, category);

            if (item == null)
            {
                return(HttpNotFound());
            }

            return(View(item));
        }
Beispiel #4
0
        public async Task GetTodoItemAsync_WithInvalidIdAndEmptyList_ShouldThrowException(long id)
        {
            // Arrange
            var options = GetInMemoryOptions();
            var mapper  = GetMapper();

            ClearDataBase(options);

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context, mapper);

                // Act / Assert
                await Assert.ThrowsAsync <ArgumentException>("id", () => service.GetTodoItemAsync(id));
            }

            ClearDataBase(options);
        }
        public async Task <ActionResult> DetailsAsync(string id, string category)
        {
            TodoItem item = await TodoItemService.GetTodoItemAsync(id, category);

            return(View(item));
        }