Esempio n. 1
0
        public void GetItem()
        {
            var data = new List <Item>
            {
                new Item {
                    Id = 1, Name = "First"
                },
                new Item {
                    Id = 2, Name = "Second"
                },
                new Item {
                    Id = 3, Name = "Third"
                },
            }.AsQueryable();

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

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

            var mockContext = new Mock <SkiResortContext>();

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

            var controller = new RentalController(mockContext.Object);
            var item       = controller.GetItem(1);

            Assert.AreEqual("First", item.Name);
        }
Esempio n. 2
0
        private Item GetById()
        {
            Item item = new Item();

            Console.WriteLine("\nEnter ID :");

            int value;

            if (!int.TryParse(Console.ReadLine(), out value))
            {
                Console.WriteLine("Input must be a number!", Color.Pink);
            }
            else
            {
                int id = value;
                item = rentalController.GetItem(id);
            }


            return(item);
        }