Exemple #1
0
        public async void GetPrestations_Return_Ok()
        {
            #region Arrange
            var dbContext = DbContextMocker.GetElegantGlamourDbContext(nameof(GetPrestations_Return_Ok));
            var config    = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper = new Mapper(config);

            var mockUnitOfWork        = new UnitOfWork(dbContext);
            var mockPrestationService = new PrestationService(mockUnitOfWork);

            var mockLogger = Mock.Of <ILogger <PrestationsController> >();

            var controller = new PrestationsController(mockPrestationService, mapper, mockLogger);
            #endregion

            #region Act
            var specParams = new PrestationSpecParams();
            var response   = await controller.GetPrestations(specParams);

            dbContext.Dispose();
            #endregion

            #region Assert
            Assert.IsAssignableFrom <IEnumerable <GetPrestationDto> >(response);
            #endregion
        }
Exemple #2
0
        public PrestationsWithCategoriesSpecification(PrestationSpecParams prestationSpecParams)
            : base(x =>
                   (string.IsNullOrEmpty(prestationSpecParams.Search) || x.Title.ToLower().Contains(prestationSpecParams.Search)) &&
                   (!prestationSpecParams.CategoryId.HasValue || x.PrestationCategoryId == prestationSpecParams.CategoryId)
                   )
        {
            AddInclude(x => x.PrestationCategory);
            AddOrderBy(x => x.Title);
            if (!string.IsNullOrEmpty(prestationSpecParams.Sort))
            {
                switch (prestationSpecParams.Sort)
                {
                case "priceAsc":
                    AddOrderBy(p => p.Price);
                    break;

                case "priceDesc":
                    AddOrderByDescending(p => p.Price);
                    break;

                default:
                    AddOrderBy(p => p.Title);
                    break;
                }
            }
        }
Exemple #3
0
        public async Task <IEnumerable <GetPrestationDto> > GetPrestations([FromQuery] PrestationSpecParams spec)
        {
            try
            {
                IEnumerable <Prestation> prestations = await this._prestationService.GetAllPrestations(spec);

                IEnumerable <GetPrestationDto> prestationsDtos = this._mapper.Map <IEnumerable <Prestation>, IEnumerable <GetPrestationDto> >(prestations);

                return(prestationsDtos);
            }
            catch (Exception ex)
            {
                _logger.LogError("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public async Task <IEnumerable <Prestation> > GetAllPrestations(PrestationSpecParams specParam)
        {
            var spec = new PrestationsWithCategoriesSpecification(specParam);

            return(await _unitOfWork.Prestations.ListAsync(spec));
        }