예제 #1
0
        private void AddFruitOrVegetable()
        {
            var elements = ReadElements();
            FruitAndVegetable fruitOrVegetable = new FruitAndVegetable(elements[0], elements[1], decimal.Parse(elements[2]), int.Parse(elements[3]));

            fruitAndVegetableController.Add(fruitOrVegetable);
            Console.WriteLine("The product was successfully added!");
        }
        public void AddFruitAndVegetable_Add_A_FruitAndVegetable()
        {
            var mockSet          = new Mock <DbSet <FruitAndVegetable> >();
            var fruitOrVegetable = new FruitAndVegetable();
            var mockContext      = new Mock <ShopContext>();

            mockContext.Setup(m => m.FruitsAndVegetables).Returns(mockSet.Object);

            var controller = new FruitAndVegetableController(mockContext.Object);

            controller.Add(fruitOrVegetable);

            mockSet.Verify(m => m.Add(It.IsAny <FruitAndVegetable>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
예제 #3
0
 private void button12_Click(object sender, EventArgs e)
 {
     if (SectionNumber == 1)
     {
         Pastry pastry = new Pastry();
         pastry.Category = textBox1.Text;
         pastry.Name     = textBox2.Text;
         pastry.Price    = decimal.Parse(textBox3.Text);
         pastry.Quantity = int.Parse(textBox4.Text);
         pastryController.Add(pastry);
     }
     if (SectionNumber == 2)
     {
         FruitsAndVegetable fruitsAndVegetable = new FruitsAndVegetable();
         fruitsAndVegetable.Category = textBox1.Text;
         fruitsAndVegetable.Name     = textBox2.Text;
         fruitsAndVegetable.Price    = decimal.Parse(textBox3.Text);
         fruitsAndVegetable.Quantity = int.Parse(textBox4.Text);
         fruitAndVegetableController.Add(fruitsAndVegetable);
     }
     if (SectionNumber == 3)
     {
         Nut nut = new Nut();
         nut.Category = textBox1.Text;
         nut.Name     = textBox2.Text;
         nut.Price    = decimal.Parse(textBox3.Text);
         nut.Quantity = int.Parse(textBox4.Text);
         nutController.Add(nut);
     }
     if (SectionNumber == 4)
     {
         Drink drink = new Drink();
         drink.Category = textBox1.Text;
         drink.Name     = textBox2.Text;
         drink.Price    = decimal.Parse(textBox3.Text);
         drink.Quantity = int.Parse(textBox4.Text);
         drinkController.Add(drink);
     }
     MessageBox.Show("The product was successfully added!");
 }