public ActionResult <string> UpdateSpecial([FromBody] SpecialRequest specialRequest)
        {
            string result = string.Empty;

            if (specialRequest.Type == SpecialType.Price)
            {
                var priceSpecial = new PriceSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                    specialRequest.IsActive, specialRequest.Price);
                result = _specialsDataAccessor.Update(priceSpecial);
            }
            else if (specialRequest.Type == SpecialType.Limit)
            {
                var limitSpecial = new LimitSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                    specialRequest.IsActive, specialRequest.DiscountQty, specialRequest.DiscountAmount, specialRequest.Limit);
                result = _specialsDataAccessor.Update(limitSpecial);
            }
            else if (specialRequest.Type == SpecialType.Restriction)
            {
                var restrictionSpecial = new RestrictionSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                                specialRequest.IsActive, specialRequest.DiscountQty, specialRequest.DiscountAmount,
                                                                specialRequest.RestrictionType);

                result = _specialsDataAccessor.Update(restrictionSpecial);
            }

            return(result);
        }
 public void Setup()
 {
     validPriceSpecial = new PriceSpecial("Can of soup", 2, true, 5);
     zeroPriceSpecial  = new PriceSpecial("Can of soup", 2, true, 0);
     lessThanTwoQuantityPriceSpecial = new PriceSpecial("Can of soup", 1, true, 5);
     validLimitSpecial                        = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 6);
     limitSpecialWithoutLimit                 = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 0);
     limitSpecialWithoutDiscountAmount        = new LimitSpecial("Can of beans", 2, true, 1, 0, 4);
     limitSpecialWithoutDiscountQuantity      = new LimitSpecial("Can of beans", 2, true, 0, 0.5f, 4);
     limitSpecialWithLimitLessThanPurchaseQty = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 1);
     limitSpecialWithLimitNotAMultipleOfPurchaseQtyPlusDiscountQty = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 5);
     validRestrictionSpecial = new RestrictionSpecial("Bananas", 2, true, 1, 0.5f, RestrictionType.Lesser);
     restrictionSpecialWithZeroDiscountAmount   = new RestrictionSpecial("Bananas", 2, true, 1, 0, RestrictionType.Lesser);
     restrictionSpecialWithZeroDiscountQuantity = new RestrictionSpecial("Bananas", 2, true, 0, 0.5f, RestrictionType.Lesser);
 }
Exemplo n.º 3
0
        public void Setup()
        {
            validPriceSpecial = new PriceSpecial("Can of soup", 2, true, 5);
            validLimitSpecial = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 6);
            zeroPriceSpecial  = new PriceSpecial("Can of soup", 2, true, 0);
            lessThanTwoQuantityPriceSpecial          = new PriceSpecial("Can of soup", 1, true, 5);
            limitSpecialWithoutLimit                 = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 0);
            limitSpecialWithoutDiscountAmount        = new LimitSpecial("Can of beans", 2, true, 1, 0, 4);
            limitSpecialWithoutDiscountQuantity      = new LimitSpecial("Can of beans", 2, true, 0, 0.5f, 4);
            limitSpecialWithLimitLessThanPurchaseQty = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 1);
            limitSpecialWithLimitNotAMultipleOfPurchaseQtyPlusDiscountQty = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 5);
            validRestrictionSpecial = new RestrictionSpecial("Bananas", 2, true, 1, 0.5f, RestrictionType.Lesser);
            restrictionSpecialWithZeroDiscountAmount = new RestrictionSpecial("Bananas", 2, true, 1, 0, RestrictionType.Lesser);
            restrictionSpecialWithZeroDiscountQty    = new RestrictionSpecial("Bananas", 2, true, 0, 0.5f, RestrictionType.Lesser);
            nonExistentPriceSpecial   = new PriceSpecial("Milk", 2, true, 5);
            successValidationResponse = new ValidationResponse
            {
                IsValid = true,
                Message = "Success."
            };

            zeroPriceValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Price must be bigger than 0."
            };

            purchaseQuantityLessThanTwoValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Purchase quantity must be bigger than 1."
            };

            zeroLimitValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Limit must be bigger than 0."
            };

            zeroDiscountAmountValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Discount amount must be bigger than zero."
            };

            limitLessThanPurchaseQuantityValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Limit must be bigger than purchase quantity."
            };

            limitNotAMultipleOfPurchaseQtyPlusDiscountQtyValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Limit must be a multiple of purchase quantity plus discount quantity."
            };

            zeroDiscountQuantityValidationResponse = new ValidationResponse
            {
                IsValid = false,
                Message = "Error: Discount quantity must be bigger than zero."
            };

            specialsList = new List <ISpecial>();
            specialsList.Add(validPriceSpecial);
            specialsList.Add(validLimitSpecial);
        }
Exemplo n.º 4
0
        public void Setup()
        {
            validPriceSpecial        = new PriceSpecial("Can of soup", 2, true, 5);
            validPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 2,
                IsActive    = true,
                Price       = 5,
                Type        = SpecialType.Price
            };

            zeroPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 2,
                IsActive    = true,
                Price       = 0,
                Type        = SpecialType.Price
            };

            lessThanTwoQuantityPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 1,
                IsActive    = true,
                Price       = 5,
                Type        = SpecialType.Price
            };

            validLimitSpecial = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 6);

            validLimitSpecialRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 6,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutLimitRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 0,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutDiscountAmountRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0,
                Limit          = 4,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutDiscountQuantityRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 0,
                DiscountAmount = 0.5f,
                Limit          = 4,
                Type           = SpecialType.Limit
            };

            limitSpecialWithLimitLessThanPurchaseQtyRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 1,
                Type           = SpecialType.Limit
            };

            limitSpecialWithLimitNotAMultipleOfPurchaseQtyPlusDiscountQtyRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 5,
                Type           = SpecialType.Limit
            };

            validRestrictionSpecial = new RestrictionSpecial("Bananas", 2, true, 1, 0.5f, RestrictionType.Lesser);

            validRestrictionSpecialRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 1,
                DiscountAmount  = 0.5f,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            restrictionSpecialWithZeroDiscountAmountRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 1,
                DiscountAmount  = 0,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            restrictionSpecialWithZeroDiscountQtyRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 0,
                DiscountAmount  = 0.5f,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            specialsList = new List <ISpecial>();
            specialsList.Add(validPriceSpecial);
            specialsList.Add(validLimitSpecial);
        }