예제 #1
0
        public async Task <List <TourDto> > Handle(GetToursQuery request, CancellationToken cancellationToken)
        {
            var pipeline = _pipelineBuilder
                           .WithNode(new AgencyPipelineNode(request.Agencies))
                           .WithNode(new CategoryPipelineNode(request.Categories))
                           .WithNode(new NamePipelineNode(request.Name))
                           .WithNode(new PriceRangePipelineNode(request.MinPrice, request.MaxPrice))
                           .WithNode(new TimeOfTheYearPipelineNode(request.TimeOfTheYear))
                           .WithNode(new DestinationPointPipelineNode(request.DestinationPointId))
                           .Execute();

            var filter     = pipeline.Execute();
            var sortOption = _sortOptionFactory.Create <Tour>(request.SortOption);

            var tours = await _toursRepository.FindAllAsync(
                filter,
                sortOption.Expression,
                sortOption.Direction,
                GetSkipValue(request.PageNumber, request.PageSize),
                request.PageSize);

            var toursDto = _mapper.Map <List <Tour>, List <TourDto> >(tours);

            return(toursDto);
        }
예제 #2
0
        private IEnumerable <GameRoot> Sort(IEnumerable <GameRoot> games, string sortCriteria)
        {
            var sortOption       = _sortOptionFactory.Create(sortCriteria);
            var propertyAccessor = sortOption.SortPropertyAccessor.Compile();
            var sortedGames      = sortOption.SortDirection == SortDirection.Ascending
                ? games.OrderBy(propertyAccessor)
                : games.OrderByDescending(propertyAccessor);

            return(sortedGames.ToList());
        }
예제 #3
0
        public void Setup()
        {
            _unitOfWork        = A.Fake <IUnitOfWork>();
            _gameDecorator     = A.Fake <IGameDecorator>();
            _mapper            = A.Fake <IMapper>();
            _visitRepository   = A.Fake <IAsyncRepository <Visit> >();
            _sortOptionFactory = A.Fake <ISortOptionFactory <GameRoot> >();
            _sortOption        = A.Fake <ISortOption <GameRoot> >();
            _publisherService  = A.Fake <IPublisherService>();

            A.CallTo(() => _sortOption.SortDirection).Returns(SortDirection.Descending);
            A.CallTo(() => _sortOption.SortPropertyAccessor).Returns(root => root.Details.Price);
            A.CallTo(() => _sortOptionFactory.Create(A <string> ._)).Returns(_sortOption);
            A.CallTo(() => _unitOfWork.GetRepository <IAsyncRepository <Visit> >()).Returns(_visitRepository);

            _gameServices =
                new GameService(_unitOfWork, _gameDecorator, _sortOptionFactory, _mapper, _publisherService);
        }