Esempio n. 1
0
        public void GetAllItemsFromDatabase()
        {
            var data = new List <Item>
            {
                new Item {
                    Name = "First"
                },
                new Item {
                    Name = "Second"
                },
                new Item {
                    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 items      = controller.GetAllItems();

            Assert.AreEqual(3, items.Count);
            Assert.AreEqual("First", items[0].Name);
            Assert.AreEqual("Second", items[1].Name);
            Assert.AreEqual("Third", items[2].Name);
        }
Esempio n. 2
0
        private void ListByGenderAndType(string gender, string status)
        {
            var items = rentalController.GetAllItems();

            foreach (var item in items.Where(it => it.Gender == gender))
            {
                if (item.Status == status)
                {
                    //Console.WriteLine($"{item.Id}: {item.Name} ({item.Size} size), costs {item.Price} lv", Color.Orange);

                    string   text = "{0}: {1} ({2} size), costs {3} lv";
                    string[] data = new string[]
                    {
                        item.Id.ToString(),
                             item.Name,
                             item.Size,
                             item.Price.ToString()
                    };

                    Console.WriteLineFormatted(text, Color.Salmon, Color.White, data);
                }
            }
        }