public void GetAnimalProductById_Gives_AnimalProduct_By_Id() { var data = new List <AnimalProduct>() { new AnimalProduct { Id = 1, Name = "AnimalProduct1" }, new AnimalProduct { Id = 2, Name = "AnimalProduct2" }, new AnimalProduct { Id = 3, Name = "AnimalProduct3" }, }.AsQueryable(); var mockSet = new Mock <DbSet <AnimalProduct> >(); mockSet.As <IQueryable <AnimalProduct> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <AnimalProduct> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <AnimalProduct> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <AnimalProduct> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <ShopContext>(); mockContext.Setup(c => c.AnimalProducts).Returns(mockSet.Object); var controller = new AnimalProductController(mockContext.Object); var animalProduct = controller.GetAnimalProductById(1); Assert.AreEqual(1, animalProduct.Id); }
private void UpdateAnimalProduct() { Console.Write("Enter ID: "); int id = int.Parse(Console.ReadLine()); var animalProduct = animalProductController.GetAnimalProductById(id); if (animalProduct != null) { Console.WriteLine($"{animalProduct.Id} {animalProduct.Category} {animalProduct.Name} {animalProduct.Price}lv/kg {animalProduct.Quantity}kg."); var elements = ReadElements(); animalProduct.Category = elements[0]; animalProduct.Name = elements[1]; animalProduct.Price = decimal.Parse(elements[2]); animalProduct.Quantity = int.Parse(elements[3]); animalProductController.Update(animalProduct); Console.WriteLine("The product was updated successfully!"); } else { Console.WriteLine("The product was not found"); } }