Example #1
0
        public async void GetPrestationCategories_Return_Ok()
        {
            #region Arrange
            var dbContext = DbContextMocker.GetElegantGlamourDbContext(nameof(GetPrestationCategories_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 <PrestationCategoriesController> >();

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

            #region Act
            PrestationCategorySpecParams spec = new PrestationCategorySpecParams();
            var response = await controller.GetPrestationCategories(spec);

            dbContext.Dispose();
            #endregion

            #region Assert
            Assert.IsAssignableFrom <IEnumerable <GetPrestationCategoryDto> >(response);
            #endregion
        }
        public PrestationsCategorySpecification(PrestationCategorySpecParams spec)
            : base(x =>
                   (!spec.Id.HasValue || x.Id == (spec.Id)) &&
                   (string.IsNullOrEmpty(spec.Name) || x.Name == spec.Name)
                   )
        {
            AddOrderBy(x => x.Name);
            if (!string.IsNullOrEmpty(spec.Sort))
            {
                switch (spec.Sort)
                {
                case "nameAsc":
                    AddOrderBy(p => p.Name);
                    break;

                case "nameDesc":
                    AddOrderByDescending(p => p.Name);
                    break;

                default:
                    AddOrderBy(p => p.Name);
                    break;
                }
            }
        }
        public async Task <IReadOnlyList <PrestationCategory> > GettAllPrestationCategories(PrestationCategorySpecParams specParams)
        {
            var spec = new PrestationsCategorySpecification(specParams);

            return(await _unitOfWork.Prestations.GetPrestationCategoriesAsync(spec));
        }
        public async Task <IEnumerable <GetPrestationCategoryDto> > GetPrestationCategories([FromQuery] PrestationCategorySpecParams spec)
        {
            try
            {
                IEnumerable <PrestationCategory> categories = await this._prestationService.GettAllPrestationCategories(spec);

                IEnumerable <GetPrestationCategoryDto> categoriesDto = this._mapper.Map <IEnumerable <PrestationCategory>, IEnumerable <GetPrestationCategoryDto> >(categories);

                return(categoriesDto);
            }
            catch (Exception ex)
            {
                _logger.LogError("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }