public void GetFruitOrVegetableById_Gives_FruitOrVegetable_By_Id()
        {
            var data = new List <FruitAndVegetable>()
            {
                new FruitAndVegetable {
                    Id = 1, Name = "FruitAndVegetable1"
                },
                new FruitAndVegetable {
                    Id = 2, Name = "FruitAndVegetable2"
                },
                new FruitAndVegetable {
                    Id = 3, Name = "FruitAndVegetable3"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <FruitAndVegetable> >();

            mockSet.As <IQueryable <FruitAndVegetable> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <FruitAndVegetable> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <FruitAndVegetable> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <FruitAndVegetable> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <ShopContext>();

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

            var controller = new FruitAndVegetableController(mockContext.Object);

            var fruitOrVegetable = controller.GetFruitOrVegetableById(1);

            Assert.AreEqual(1, fruitOrVegetable.Id);
        }
Exemplo n.º 2
0
        private void FindFruitOrVegetableById()
        {
            Console.Write("Enter ID: ");
            var id = int.Parse(Console.ReadLine());
            var fruitOrVegetable = fruitAndVegetableController.GetFruitOrVegetableById(id);

            if (fruitOrVegetable != null)
            {
                Console.WriteLine(new string('*', 40));
                Console.WriteLine("ID: " + fruitOrVegetable.Id);
                Console.WriteLine("Category: " + fruitOrVegetable.Category);
                Console.WriteLine("Name: " + fruitOrVegetable.Name);
                Console.WriteLine("Price: " + fruitOrVegetable.Price + "lv/kg");
                Console.WriteLine("Quantity: " + fruitOrVegetable.Quantity + "kg.");
                Console.WriteLine(new string('*', 40));
            }
            else
            {
                Console.WriteLine("The product was not found!");
            }
        }
Exemplo n.º 3
0
        private void button11_Click(object sender, EventArgs e)
        {
            label3.Text = "";

            if (SectionNumber == 1)
            {
                var id     = int.Parse(textBox1.Text);
                var pastry = pastryController.GetPastryById(id);
                if (pastry != null)
                {
                    label3.Text += ("ID: " + pastry.Id);
                    label3.Text += ("\nCategory: " + pastry.Category);
                    label3.Text += ("\nName: " + pastry.Name);
                    label3.Text += ("\nPrice: " + pastry.Price + "lv/pcs");
                    label3.Text += ("\nQuantity: " + pastry.Quantity + "pcs.");
                }
                else
                {
                    MessageBox.Show("The product was not found!");
                }
            }
            if (SectionNumber == 2)
            {
                var id = int.Parse(textBox1.Text);
                var fruitAndVegetable = fruitAndVegetableController.GetFruitOrVegetableById(id);
                if (fruitAndVegetable != null)
                {
                    label3.Text += ("ID: " + fruitAndVegetable.Id);
                    label3.Text += ("\nCategory: " + fruitAndVegetable.Category);
                    label3.Text += ("\nName: " + fruitAndVegetable.Name);
                    label3.Text += ("\nPrice: " + fruitAndVegetable.Price + "lv/pcs");
                    label3.Text += ("\nQuantity: " + fruitAndVegetable.Quantity + "pcs.");
                }
                else
                {
                    MessageBox.Show("The product was not found!");
                }
            }
            if (SectionNumber == 3)
            {
                var id  = int.Parse(textBox1.Text);
                var nut = nutController.GetNutById(id);
                if (nut != null)
                {
                    label3.Text += ("ID: " + nut.Id);
                    label3.Text += ("\nCategory: " + nut.Category);
                    label3.Text += ("\nName: " + nut.Name);
                    label3.Text += ("\nPrice: " + nut.Price + "lv/pcs");
                    label3.Text += ("\nQuantity: " + nut.Quantity + "pcs.");
                }
                else
                {
                    MessageBox.Show("The product was not found!");
                }
            }
            if (SectionNumber == 4)
            {
                var id    = int.Parse(textBox1.Text);
                var drink = drinkController.GetDrinkById(id);
                if (drink != null)
                {
                    label3.Text += ("ID: " + drink.Id);
                    label3.Text += ("\nCategory: " + drink.Category);
                    label3.Text += ("\nName: " + drink.Name);
                    label3.Text += ("\nPrice: " + drink.Price + "lv/pcs");
                    label3.Text += ("\nQuantity: " + drink.Quantity + "pcs.");
                }
                else
                {
                    MessageBox.Show("The product was not found!");
                }
            }
        }