public async Task <IActionResult> Get() { var query = new GetTodosQuery(); var result = await _mediator.Send(query); return(Ok(result)); }
public async Task ShouldIncludePriorityLevels() { var query = new GetTodosQuery(); var result = await SendAsync(query); result.PriorityLevels.Should().NotBeEmpty(); }
public async Task ShouldGetAllListsAndItems() { var query = new GetTodosQuery(); var result = await SendAsync(query); result.Lists.Should().HaveCount(0); }
public async System.Threading.Tasks.Task ShouldReturnTaskStates() { var query = new GetTodosQuery(); var result = await SendAsync(query); result.TaskStates.Should().NotBeEmpty(); }
public async Task <IActionResult> GetAll([FromQuery] GetTodosQuery query) { var todoListPreview = await mediator.Send(query); Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(todoListPreview.PaginationMetadata)); return(Ok(todoListPreview.TodoPreviewDtos)); }
public async Task ShouldReturnPriorityLevels() { var query = new GetTodosQuery() { Take = 20 }; var result = await SendAsync(query); result.PriorityLevels.Should().NotBeEmpty(); }
public async void ShouldReturnPriorityLevels() { // Arrange var query = new GetTodosQuery(); // Act var result = await _fixture.SendAsync(query); // Assert result.PriorityLevels.ShouldNotBeEmpty(); }
public Task <IQueryable <GetTodosQuery.Todo> > Handle(GetTodosQuery request, CancellationToken cancellationToken) { var session = _sessionFactory.GetCurrentSession(); var queryable = session.Query <Todo>().Select(x => new GetTodosQuery.Todo { Id = x.Id, Task = x.Task, IsCompleted = x.IsCompleted }); return(Task.FromResult(queryable)); }
public async Task <ActionResult <TodosVm> > Get(int userId) { var currentUserId = int.Parse(User.Identity.Name); var query = new GetTodosQuery(); query.CurrentUserId = userId; if (currentUserId != query.CurrentUserId && !User.IsInRole(Role.Admin)) { return(Forbid()); } return(await Mediator.Send(query)); }
public async Task Handle_ReturnsCorrectVmAndListCount() { var query = new GetTodosQuery(); var handler = new GetTodosQuery.GetTodosQueryHandler(_context, _mapper); var result = await handler.Handle(query, CancellationToken.None); result.ShouldBeOfType <TodosVm>(); result.Lists.Count.ShouldBe(1); var list = result.Lists.First(); list.Items.Count.ShouldBe(5); }
public async Task Handle_ReturnsCorrectVmAndListCount() { //arrange var query = new GetTodosQuery(); var mockedDbContext = new Mock <IApplicationDbContext>(); var todoListEntities = new List <TodoList> { new TodoList { Colour = "Blue", Items = new List <TodoItem> { new TodoItem { Title = "Dynamics" }, new TodoItem { Title = "Case" }, new TodoItem { Title = "Management" }, new TodoItem { Title = "Accelerator" }, new TodoItem { Title = "HSD" } } } }; var mockDbSet = todoListEntities.AsQueryable().BuildMockDbSet(); mockedDbContext.Setup(db => db.TodoLists).Returns(mockDbSet.Object); //act var handler = new GetTodosQuery.GetTodosQueryHandler(mockedDbContext.Object, _mapper); var result = await handler.Handle(query, CancellationToken.None); //assert result.ShouldBeOfType <TodosVm>(); result.Lists.Count.ShouldBe(1); var list = result.Lists.First(); list.Items.Count.ShouldBe(5); }
//[Fact] public async void ShouldReturnAllListsAndItems() { var createdId = await _fixture.AddAsync(new TodoList { Title = "Shopping 30/10/2020", Items = { new TodoItem { Title = "Apples" }, new TodoItem { Title = "Milk" }, new TodoItem { Title = "Bread" }, new TodoItem { Title = "Toilet paper" }, new TodoItem { Title = "Pasta" }, new TodoItem { Title = "Tissues" }, new TodoItem { Title = "Tuna" } } }); var confirmCreation = await _fixture.FindAsync <TodoList>(createdId); confirmCreation.ShouldNotBeNull(); var query = new GetTodosQuery(); var result = await _fixture.SendAsync(query); var createdList = result.Lists.Single(x => x.Title == "Shopping 30/10/2020"); createdList.ShouldNotBeNull(); createdList.Items.Count.ShouldBe(7); }
public async Task <ApiResponse <TodosVm> > Handle(GetTodosQuery request, CancellationToken cancellationToken) { var result = new TodosVm { PriorityLevels = Enum.GetValues(typeof(PriorityLevel)) .Cast <PriorityLevel>() .Select(p => new PriorityLevelDto { Value = (int)p, Name = p.ToString() }) .ToList(), Lists = await _context.TodoLists .ProjectTo <TodoListDto>(_mapper.ConfigurationProvider) .OrderBy(t => t.Title) .ToListAsync(cancellationToken) }; return(result.ToApiResponse()); }
public async Task ShouldReturnAllListsAndItems() { await AddAsync(new TodoList { Title = "Shopping", Items = { new TodoItem { Title = "Apples", Done = true }, new TodoItem { Title = "Milk", Done = true }, new TodoItem { Title = "Bread", Done = true }, new TodoItem { Title = "Toilet paper" }, new TodoItem { Title = "Pasta" }, new TodoItem { Title = "Tissues" }, new TodoItem { Title = "Tuna" } } }); var query = new GetTodosQuery() { Take = 20 }; var result = await SendAsync(query); result.Lists.Should().HaveCount(1); result.Lists.First().Items.Should().HaveCount(7); }
public async System.Threading.Tasks.Task ShouldReturnAllEmployeesAndTasks() { await AddAsync(new Employee { Name = "John Smith", Tasks = { new Domain.Entities.Task { Title = "Requirements", State = TaskState.Closed, Priority = PriorityLevel.Critical }, new Domain.Entities.Task { Title = "UI/UX Design", State = TaskState.Resolved, Priority = PriorityLevel.Low }, new Domain.Entities.Task { Title = "Making Prototypes", State = TaskState.New, Priority = PriorityLevel.Medium }, new Domain.Entities.Task { Title = "Milestone 1", State = TaskState.Active, Priority = PriorityLevel.Critical }, new Domain.Entities.Task { Title = "Unit Testing", State = TaskState.New, Priority = PriorityLevel.Low }, new Domain.Entities.Task { Title = "Quality Assurance", State = TaskState.New, Priority = PriorityLevel.Low }, new Domain.Entities.Task { Title = "Demo", State = TaskState.New, Priority = PriorityLevel.Low }, new Domain.Entities.Task { Title = "Milestone 2", State = TaskState.New, Priority = PriorityLevel.Low } } }); var query = new GetTodosQuery(); var result = await SendAsync(query); result.Employees.Should().HaveCount(1); result.Employees.First().Tasks.Should().HaveCount(8); }
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 GetTodosQuery(); // 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 ShouldReturnAllListsAndItems() { await AddAsync(new TodoList { Title = "Shopping", Items = { new TodoItem { Title = "Turbocharger", Done = true }, new TodoItem { Title = "Intercooler", Done = true }, new TodoItem { Title = "Custom Wastegate", Done = true }, new TodoItem { Title = "T25 Flange" }, new TodoItem { Title = "Downpipes" }, new TodoItem { Title = "ECU remap" }, new TodoItem { Title = "Turbo Pressure gauge" } } }); var query = new GetTodosQuery(); var result = await SendAsync(query); result.Lists.Should().HaveCount(1); result.Lists.First().Items.Should().HaveCount(7); }
public async Task <IEnumerable <GetTodosResult> > Get([FromQuery] GetTodosQuery query) { return(await _mediator.Send(query)); }
public async Task <List <GetTodoResponse> > Handle(GetTodosQuery request, CancellationToken cancellationToken) { var todos = await _todoService.GetTodos(); return(_mapper.MapTodoTaskDtoToGetTodoResponse(todos.ToList())); }
public async Task <ActionResult <List <TodoDto> > > GetTodos([FromQuery] GetTodosQuery query) { return(await Mediator.Send(query)); }
public Task <IQueryable <TodoReadModel> > HandleAsync(GetTodosQuery query, CancellationToken cancellationToken) { return(Task.FromResult( readRepository.FindAll <TodoReadModel>())); }