private void AddNut() { var elements = ReadElements(); Nut nut = new Nut(elements[0], elements[1], decimal.Parse(elements[2]), int.Parse(elements[3])); nutController.Add(nut); Console.WriteLine("The product was successfully added!"); }
public void AddNut_Add_A_Nut() { var mockSet = new Mock <DbSet <Nut> >(); var nut = new Nut(); var mockContext = new Mock <ShopContext>(); mockContext.Setup(m => m.Nuts).Returns(mockSet.Object); var controller = new NutController(mockContext.Object); controller.Add(nut); mockSet.Verify(m => m.Add(It.IsAny <Nut>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
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!"); }