Ejemplo n.º 1
0
        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.GroupSalePrice, (decimal?)null);
            _validator.ShouldHaveValidationErrorFor(x => x.GroupSalePrice, 0);

            var args = new CreateBuyNForXAmountSpecialArgs()
            {
                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 CreateBuyNForXAmountSpecial(CreateBuyNForXAmountSpecialArgs args)
        {
            _createBuyNForXAmountSpecialArgsValidator.ValidateAndThrow <CreateBuyNForXAmountSpecialArgs>(args);

            Func <Special> createSpecial = () => new BuyNForXAmountSpecial(args.StartTime.Value, args.EndTime.Value, args.DiscountedItems.Value, args.GroupSalePrice.Value, args.Limit);
            Func <Special, ISpecialDto> mapToSpecialDto = special => _mapper.Map <BuyNForXAmountSpecialDto>(special);

            return(CreateSpecial(args, createSpecial, mapToSpecialDto));
        }
Ejemplo n.º 3
0
        public void CreateBuyNForXAmountSpecial_WithInvalidProductName_ThrowsArgumentException(string productName, string message)
        {
            var args = new CreateBuyNForXAmountSpecialArgs {
                ProductName = productName
            };

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

            createSpecial.Should().Throw <ArgumentException>(message);
        }
Ejemplo n.º 4
0
        public void CreateBuyNForXAmountSpecial_CreatesSpecial()
        {
            var args = new CreateBuyNForXAmountSpecialArgs
            {
                DiscountedItems = 3,
                EndTime         = _now.EndOfWeek(),
                GroupSalePrice  = 2m,
                Limit           = 6,
                ProductName     = "can of soup",
                StartTime       = _now.StartOfWeek()
            };

            var productDto = _productSpecialConfigurationService.CreateBuyNForXAmountSpecial(args);
            var specialDto = (BuyNForXAmountSpecialDto)productDto.Special;

            productDto.Name.Should().Be(args.ProductName);
            specialDto.DiscountedItems.Should().Be(args.DiscountedItems);
            specialDto.EndTime.Should().Be(args.EndTime.Value);
            specialDto.GroupSalePrice.Should().Be(args.GroupSalePrice);
            specialDto.Limit.Should().Be(args.Limit);
            specialDto.StartTime.Should().Be(args.StartTime.Value);
        }
Ejemplo n.º 5
0
 public ActionResult <ProductDto> CreateBuyNForXAmountSpecial(string productName, [FromBody] CreateBuyNForXAmountSpecialArgs args)
 {
     args.ProductName = productName;
     return(_productSpecialConfigurationService.CreateBuyNForXAmountSpecial(args));
 }