Ejemplo n.º 1
0
        public Task <IQueryable <TodoListDto> > HandleAsync(GetTodoListsQuery query, CancellationToken cancellationToken)
        {
            var taskLists = mapper.ProjectTo <TodoListDto>(
                readRepository
                .FindAll <TodoListReadModel>());

            return(Task.FromResult(taskLists));
        }
Ejemplo n.º 2
0
        public Task <IQueryable <TodoListDto> > HandleAsync(GetTodoListsQuery query, CancellationToken cancellationToken)
        {
            IQueryable <TodoListDto> taskLists = readRepository
                                                 .FindAll <TodoListReadModel>()
                                                 .Include(x => x.Todos)
                                                 .ProjectTo <TodoListDto>();

            return(Task.FromResult(taskLists));
        }
Ejemplo n.º 3
0
        public async Task Handle_ReturnsCorrectVmAndListCount()
        {
            // Arrange
            var query   = new GetTodoListsQuery();
            var handler = new GetTodoListsQueryHandler(_context, _mapper);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.ShouldBeOfType <TodosVm>();
            result.Lists.Count.ShouldBe(1);
            result.Lists[0].Items.Count.ShouldBe(5);
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <GetTodoListsResult> > Handle(GetTodoListsQuery request, CancellationToken cancellationToken)
        {
            var results = await _context.TodoList
                          .OrderBy(x => x.Id)
                          .Take(10)
                          .Where(x => x.UserId == _currentUser.Id)
                          .Select(x => new GetTodoListsResult
            {
                Id    = x.Id,
                Title = x.Title
            })
                          .ToListAsync(cancellationToken);

            return(results);
        }
Ejemplo n.º 5
0
 public TodoListsController(
     GetTodoListsQuery getTodoListsQuery,
     GetTodoListByIdQuery getTodoListByIdQuery,
     GetTodoListItemsQuery getTodoListItemsQuery,
     CreateTodoListCommand createTodoListCommand,
     UpdateTodoListCommand updateTodoListCommand,
     RemoveTodoListCommand removeTodoListCommand
     )
 {
     this.getTodoListsQuery     = getTodoListsQuery;
     this.getTodoListByIdQuery  = getTodoListByIdQuery;
     this.getTodoListItemsQuery = getTodoListItemsQuery;
     this.createTodoListCommand = createTodoListCommand;
     this.updateTodoListCommand = updateTodoListCommand;
     this.removeTodoListCommand = removeTodoListCommand;
 }
Ejemplo n.º 6
0
        public async Task ShouldReturnAllListsAndAssociatedItems()
        {
            // Arrange
            await AddAsync(new TodoList
            {
                Title = "Shopping",
                Items =
                {
                    new TodoItem {
                        Title = "Fresh fruit", Done = true
                    },
                    new TodoItem {
                        Title = "Bread", Done = true
                    },
                    new TodoItem {
                        Title = "Milk", Done = true
                    },
                    new TodoItem {
                        Title = "Toilet paper"
                    },
                    new TodoItem {
                        Title = "Tuna"
                    },
                    new TodoItem {
                        Title = "Pasta"
                    }
                }
            });

            var query = new GetTodoListsQuery();

            // Act
            TodosVm result = await SendAsync(query);

            // Assert
            result.Should().NotBeNull();
            result.Lists.Should().HaveCount(1);
            result.Lists.First().Items.Should().HaveCount(6);
        }
 public async Task <IEnumerable <TodoList> > GetLists([FromQuery] GetTodoListsQuery query)
 {
     return(await _mediatorService.Send <GetTodoListsQuery, IEnumerable <TodoList> >(query));
 }
Ejemplo n.º 8
0
 public Task <List <TodoListViewModel> > Handle(GetTodoListsQuery request, CancellationToken cancellationToken)
 {
     return(_applicationDbContext.TodoLists.Select(q => new TodoListViewModel(q.Id, q.Title, q.TodoListItems.Count())).ToListAsync(cancellationToken));
 }
Ejemplo n.º 9
0
 public async Task <IEnumerable <GetTodoListsResult> > Get([FromQuery] GetTodoListsQuery query)
 {
     return(await _mediator.Send(query));
 }
Ejemplo n.º 10
0
 public async Task <IEnumerable <TodoList> > Handle(GetTodoListsQuery query)
 {
     return(await _todoListService.Get());
 }