public async Task ShouldGetRoutesQuery() { // Arrange var listRoutesCommand = new ListRoutesCommand(); // Act var result = await _listRoutesQuery.Query(listRoutesCommand); // Assert Assert.IsNotNull(result); }
public async Task ShouldGetRoutesQueryHandler() { // Arrange var listRoutesCommand = new ListRoutesCommand(); // Act var result = await _listRoutesQueryHandler.Handle(listRoutesCommand); // Assert Assert.IsNotNull(result?.Object); }
public override async Task <List <Route> > Query(ListRoutesCommand command) { var query = DbContext.Routes .Include(o => o.AngularComponent) .Include(o => o.Category) .Include(o => o.InputForm) .Include(o => o.Product); if (command.RouteId.HasValue) { return(await query.Where(o => o.Id == command.RouteId).ToListAsync()); } else if (command.Url != null) { return(await query.Where(o => o.Url == command.Url).ToListAsync()); } else { return(await query.ToListAsync()); } }
public override async Task <ActionResult <List <RouteDto> > > Handle(ListRoutesCommand command) { var routes = await _listRoutesQuery.Query(command); if (routes == null) { return(Error()); } var routesDto = new List <RouteDto>(); var buildedCategoryNavigations = new List <Category>(); var categoriesForest = routes.Select(o => o.Category).Where(o => o != null).ConvertToForest(); foreach (var lastCategory in categoriesForest.LastNodes()) { buildedCategoryNavigations.AddRange(lastCategory.BuildCategoryNavigations()); } routesDto.AddRange(_mapper.Map <List <RouteDto> >(buildedCategoryNavigations)); routesDto.AddRange(_mapper.Map <List <RouteDto> >(routes.Select(o => o.Product))); routesDto = routesDto.ToList(); return(Ok(routesDto)); }