Exemplo n.º 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!");
        }
        /// <summary>
        /// Updates a fruit or vegetable.
        /// </summary>
        /// <param name="fruitORvegetable">the fruit or vegetable that will be updated.</param>
        public void Update(FruitAndVegetable fruitORvegetable)
        {
            var item = context.FruitsAndVegetables.Find(fruitORvegetable.Id);

            if (item != null)
            {
                context.Entry(item).CurrentValues.SetValues(fruitORvegetable);
                context.SaveChanges();
            }
        }
        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());
        }
 /// <summary>
 /// Adds a fruit or vegetable.
 /// </summary>
 /// <param name="fruitORvegetable">the fruit or vegetable that will be added.</param>
 public void Add(FruitAndVegetable fruitORvegetable)
 {
     context.FruitsAndVegetables.Add(fruitORvegetable);
     context.SaveChanges();
 }