예제 #1
0
        public void AddDiscountReturnsViewResultWithDiscountModel()
        {
            var mock       = new Mock <IDiscountRepository>();
            var controller = new DiscountController(mock.Object);

            controller.ModelState.AddModelError("Name", "Required");
            Discount newDiscount = new Discount();


            var result = controller.AddDiscount(newDiscount);


            var viewResult = Xunit.Assert.IsType <ViewResult>(result);

            Xunit.Assert.Equal(newDiscount, viewResult?.Model);
        }
예제 #2
0
        public void AddDiscountReturnsARedirectAndAddsDiscount()
        {
            var mock        = new Mock <IDiscountRepository>();
            var controller  = new DiscountController(mock.Object);
            var newDiscount = new Discount()
            {
                Id             = 5,
                SizeOfDiscount = "1",
                UserId         = "1"
            };

            var result = controller.AddDiscount(newDiscount);

            var redirectToActionResult = Xunit.Assert.IsType <RedirectToActionResult>(result);

            Xunit.Assert.Null(redirectToActionResult.ControllerName);
            Xunit.Assert.Equal("Index", redirectToActionResult.ActionName);
            mock.Verify(r => r.Create(newDiscount));
        }
        private void ConfrimCliked(object sender, EventArgs e)
        {
            var discount = new
            {
                DiscountID = 0,
                FoodId     = tbFoodId.Text,
                Amount     = Convert.ToInt32(tbAmount.Text),
                DName      = tbName.Text
            };
            var foodResult = FoodController.GetFood(tbFoodId.Text);

            if (foodResult != null)
            {
                int a = foodResult.Price - Convert.ToInt32(tbAmount.Text);
                if (a >= 0)
                {
                    var price = new
                    {
                        Price = a,
                        Id    = tbFoodId.Text
                    };
                    var discountResult = DiscountController.AddDiscount(discount);
                    if (discountResult)
                    {
                        var priceDeduct = FoodController.UpdateFood2(price);
                        MessageBox.Show("Discount Added Successfully", "Discount add", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Insuffficient Discount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Food Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }