public async Task <IEnumerable <MenuItemDto> > GetAllMenuItemsWithFilters(FilterDto filters)
        {
            ISpecification <MenuItem> specification;

            var mealType  = filters.MealType;
            var allergens = filters.Allergens;

            if (!(mealType == MealType.Unknown) && allergens != null && allergens.Any())
            {
                var mealTypeSpec         = new MenuItemForMealTypeSpecification(mealType);
                var excludeAllergensSpec = new MenuItemForAllergensSpecification(allergens).Not();

                specification = mealTypeSpec.And(excludeAllergensSpec);
            }
            else if (allergens != null && allergens.Any())
            {
                specification = new MenuItemForAllergensSpecification(allergens).Not();
            }
            else
            {
                specification = new MenuItemForMealTypeSpecification(mealType);
            }

            var menuItems = await _menuItemRepository.All(specification);

            var menuItemDtos = _mapper.Map <IEnumerable <MenuItemDto> >(menuItems);

            return(menuItemDtos);
        }
Esempio n. 2
0
        public void IsSatisfiedBy_AppendsToBuilderAndAddsParameters()
        {
            var spec = new MenuItemForMealTypeSpecification(MealType);

            var builder    = new StringBuilder();
            var parameters = new Dictionary <string, object>();

            spec.IsSatisfiedBy(builder, parameters);

            builder.ToString().Should().Be("[MealType] = @mealType");
            parameters["mealType"].Should().Be(MealType.ToString());
        }
Esempio n. 3
0
        public void IsSatisfiedBy_ReturnsFalse()
        {
            var spec = new MenuItemForMealTypeSpecification(MealType);

            var menuItem = new MenuItem
            {
                MealType = MealType.Starter,
            };

            var result = spec.IsSatisfiedBy(menuItem);

            result.Should().BeFalse();
        }