public void AddPromotion_ShouldThrowArgumentOutOfRangeException_WhenDiscountParameterIsMoreThanMaximumAllowed_CaseTwo()
        {
            // Arrange
            var validItemId      = 1;
            var invalidDiscount  = 12213;
            var promotionService = new PromotionService(this.dataMock.Object);

            // Act & Assert
            promotionService.AddPromotion(validItemId, invalidDiscount);
        }
        public void AddPromotion_ShouldThrowArgumentOutOfRangeException_WhenItemIdParameterIsNegative()
        {
            // Arrange
            var invalidItemId    = -5;
            var validDiscount    = 10;
            var promotionService = new PromotionService(this.dataMock.Object);

            // Act & Assert
            promotionService.AddPromotion(invalidItemId, validDiscount);
        }
        public void RemovePromotion_ShouldThrowObjectNotFoundInDatabaseException_WhenNoObjectWithTheGivenIdIsFound()
        {
            // Arrange
            var  itemId   = 1;
            var  discount = 50;
            Item item     = null;

            this.itemRepoMock.Setup(r => r.GetById(It.IsAny <int>())).Returns(item);
            this.dataMock.SetupGet(d => d.Items).Returns(this.itemRepoMock.Object);

            var promotionService = new PromotionService(this.dataMock.Object);

            // Act & Assert
            promotionService.AddPromotion(itemId, discount);
        }
        public void AddPromotion_ShouldIncreaseItemDiscount_WhenAllParametersAreValid_CaseThree()
        {
            // Arrange
            var itemId   = 53;
            var discount = 32;
            var item     = new Item();

            this.itemRepoMock.Setup(r => r.GetById(It.IsAny <int>())).Returns(item);
            this.dataMock.SetupGet(d => d.Items).Returns(this.itemRepoMock.Object);

            var promotionService = new PromotionService(this.dataMock.Object);

            // Act
            promotionService.AddPromotion(itemId, discount);

            // Assert
            Assert.AreEqual(discount, item.Discount);
        }
        public void AddPromotion_ShouldCallDataCommit_WhenAllParametersAreValid_CaseThree()
        {
            // Arrange
            var itemId   = 12;
            var discount = 33;
            var item     = new Item();

            this.itemRepoMock.Setup(r => r.GetById(It.IsAny <int>())).Returns(item);
            this.dataMock.SetupGet(d => d.Items).Returns(this.itemRepoMock.Object);

            var promotionService = new PromotionService(this.dataMock.Object);

            // Act
            promotionService.AddPromotion(itemId, discount);

            // Assert
            dataMock.Verify(d => d.Commit(), Times.Once);
        }
        public string AddPromotion(string name, int shopID, int discount, int basePurchase, DateTime startDate, string description, DateTime?endDate = null)
        {
            string    result        = "Fail";
            Promotion tempPromotion = new Promotion();

            tempPromotion.Name         = name;
            tempPromotion.ShopID       = shopID;
            tempPromotion.Discount     = discount;
            tempPromotion.BasePurchase = basePurchase;
            tempPromotion.StartDate    = startDate;
            tempPromotion.EndDate      = endDate;
            tempPromotion.Description  = description;

            if (promotionService.ValidateData(tempPromotion))  // Check Validator
            {
                if (promotionService.AddPromotion(tempPromotion) == true)
                {
                    result = tempPromotion.ID.ToString();
                }
            }
            return(result);
        }
예제 #7
0
 public ActionResult Create(promotion promo)
 {
     promServ.AddPromotion(promo);
     return(RedirectToAction("Index"));
 }
예제 #8
0
        static void ManagePromotion()
        {
            string            productCodeInput = "";
            int               productTypeInput = 0;
            int               requiredQuantity = 0;
            int               discountQuantity = 0;
            int               discountPercent  = 0;
            bool              isInt            = false;
            bool              isExist          = false;
            PromotionModel    promotion        = new PromotionModel();
            IProductService   productService   = null;
            IPromotionService promotionService = null;

            try
            {
                productService   = new ProductService();
                promotionService = new PromotionService();
                Console.Clear();
                Console.WriteLine("-- Promotion Management --");
                while (isExist == false)
                {
                    ProductModel selectedProduct = null;
                    do
                    {
                        Console.Write("Product Code: ");
                        productCodeInput = Console.ReadLine();
                        isExist          = productCodeInput.ToUpper().Equals("E0");
                        if (isExist == false)
                        {
                            selectedProduct = productService.GetProductInfoByCode(productCodeInput);
                        }
                    }while (isExist == false && selectedProduct == null);

                    if (isExist == false)
                    {
                        do
                        {
                            Console.Write("Promotion Type:");
                            isInt = int.TryParse(Console.ReadLine(), out productTypeInput);
                        } while (isInt == false ||
                                 (productTypeInput != (int)PromotionTypeEnum.Buy_X_Give_Y &&
                                  productTypeInput != (int)PromotionTypeEnum.SaleOff_X_Percent));

                        promotion.Products = new List <ProductModel>();
                        promotion.Products.Add(selectedProduct);
                        promotion.IsActive       = true;
                        promotion.OnlyMembership = false;
                        promotion.StartDate      = DateTime.Now;
                        promotion.EndDate        = DateTime.Now.AddDays(15);

                        if (productTypeInput == (int)PromotionTypeEnum.Buy_X_Give_Y)
                        {
                            do
                            {
                                Console.Write("Quantity Required: ");
                                isInt = int.TryParse(Console.ReadLine(), out requiredQuantity);
                                Console.Write("Quantity Discount: ");
                                isInt = isInt && int.TryParse(Console.ReadLine(), out discountQuantity);
                            } while (isInt == false || (discountQuantity > requiredQuantity));
                            promotion.PromotionTypeId  = (int)PromotionTypeEnum.Buy_X_Give_Y;
                            promotion.RequiredQuantity = requiredQuantity;
                            promotion.DiscountQuantity = discountQuantity;
                        }
                        else if (productTypeInput == (int)PromotionTypeEnum.SaleOff_X_Percent)
                        {
                            do
                            {
                                Console.Write("Discount (percentage): ");
                                isInt = int.TryParse(Console.ReadLine(), out discountPercent);
                            } while (isInt == false || (discountPercent < 0 || discountPercent >= 100));
                            promotion.PromotionTypeId = (int)PromotionTypeEnum.SaleOff_X_Percent;
                            promotion.Saleoff         = discountPercent;
                        }
                        promotionService.AddPromotion(promotion);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                productService = null;
            }
        }