public void CreateBuyNForXAmountSpecialArgsValidator_ContainsCorrectValidationRules()
        {
            _validator.ShouldHaveValidationErrorFor(x => x.ProductName, null as string);
            _validator.ShouldHaveValidationErrorFor(x => x.ProductName, "");
            _validator.ShouldHaveValidationErrorFor(x => x.ProductName, " ");
            _validator.ShouldHaveValidationErrorFor(x => x.ProductName, "milk");
            _validator.ShouldHaveValidationErrorFor(x => x.EndTime, (DateTime?)null);
            _validator.ShouldHaveValidationErrorFor(x => x.DiscountedItems, (int?)null);
            _validator.ShouldHaveValidationErrorFor(x => x.DiscountedItems, 0);
            _validator.ShouldHaveValidationErrorFor(x => x.PercentageOff, (decimal?)null);
            _validator.ShouldHaveValidationErrorFor(x => x.PercentageOff, 0);
            _validator.ShouldHaveValidationErrorFor(x => x.PercentageOff, 101);
            _validator.ShouldHaveValidationErrorFor(x => x.PreDiscountItems, (int?)null);
            _validator.ShouldHaveValidationErrorFor(x => x.PreDiscountItems, 0);

            var args = new CreateBuyNGetMAtXPercentOffSpecialArgs()
            {
                ProductName = "can of soup", EndTime = DateTime.Now
            };
            Action validate = () => _validator.ValidateAndThrow(args);

            validate.Should().Throw <ValidationException>("*Special start time is required*");

            args.StartTime = DateTime.Now;
            validate.Should().Throw <ValidationException>("*Special start time must be less than end time*");

            args.ProductName = "lean ground beef";
            args.EndTime     = DateTime.Now;
            validate.Should().Throw <ValidationException>("*Special can only be applied to a product with the Unit sell by type*");
        }
        public ProductDto CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(CreateBuyNGetMAtXPercentOffSpecialArgs args)
        {
            _createBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecialArgsValidator.ValidateAndThrow <CreateBuyNGetMAtXPercentOffSpecialArgs>(args);

            Func <Special> createSpecial = () => new BuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(args.StartTime.Value, args.EndTime.Value, args.PreDiscountItems.Value, args.DiscountedItems.Value, args.PercentageOff.Value, args.Limit);
            Func <Special, ISpecialDto> mapToSpecialDto = special => _mapper.Map <BuyNGetMAtXPercentOffSpecialDto>(special);

            return(CreateSpecial(args, createSpecial, mapToSpecialDto));
        }
示例#3
0
        public void CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial_WithInvalidProductName_ThrowsArgumentException(string productName, string message)
        {
            var args = new CreateBuyNGetMAtXPercentOffSpecialArgs {
                ProductName = productName
            };

            Action createSpecial = () => _productSpecialConfigurationService.CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(args);

            createSpecial.Should().Throw <ArgumentException>(message);
        }
示例#4
0
        public void CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial_CreatesSpecial()
        {
            var args = new CreateBuyNGetMAtXPercentOffSpecialArgs
            {
                DiscountedItems  = 1,
                EndTime          = _now.EndOfWeek(),
                Limit            = 6,
                PercentageOff    = 50m,
                PreDiscountItems = 2,
                ProductName      = "lean ground beef",
                StartTime        = _now.StartOfWeek()
            };

            var productDto = _productSpecialConfigurationService.CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(args);
            var specialDto = (BuyNGetMAtXPercentOffSpecialDto)productDto.Special;

            productDto.Name.Should().Be(args.ProductName);
            specialDto.DiscountedItems.Should().Be(args.DiscountedItems);
            specialDto.EndTime.Should().Be(args.EndTime.Value);
            specialDto.Limit.Should().Be(args.Limit);
            specialDto.PercentageOff.Should().Be(args.PercentageOff);
            specialDto.PreDiscountItems.Should().Be(args.PreDiscountItems);
            specialDto.StartTime.Should().Be(args.StartTime.Value);
        }
示例#5
0
 public ActionResult <ProductDto> CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(string productName, [FromBody] CreateBuyNGetMAtXPercentOffSpecialArgs args)
 {
     args.ProductName = productName;
     return(_productSpecialConfigurationService.CreateBuyNGetMOfEqualOrLesserValueAtXPercentOffSpecial(args));
 }