Exemple #1
0
        public void GetHikeFromDatabaseById()
        {
            var data = new List <Hike>
            {
                new Hike {
                    Id = 1, StartPoint = "First"
                },
                new Hike {
                    Id = 2, StartPoint = "Second"
                },
                new Hike {
                    Id = 3, StartPoint = "Third"
                },
            }.AsQueryable();

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

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

            var mockContext = new Mock <SkiResortContext>();

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

            var controller = new HikeController(mockContext.Object);
            var hike       = controller.Get(1);

            Assert.AreEqual("First", hike.StartPoint);
        }
Exemple #2
0
        private Hike GetHike()
        {
            Hike hike = new Hike();
            int  value;

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



            return(hike);
        }