Example #1
0
        public void CalculateValidPriceForStudent()
        {
            var data = new List <LiftPass>
            {
                new LiftPass {
                    Type = "Student", Duration = 91
                },
                new LiftPass {
                    Type = "Adult", Duration = 91, Price = 271
                }
            }.AsQueryable();

            var expectedResult = 189.7;
            var mockSet        = new Mock <DbSet <LiftPass> >();

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

            var mockContext = new Mock <SkiResortContext>();

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

            var controller = new LiftPassController(mockContext.Object);

            var liftPasses      = controller.GetAll();
            var liftPassStudent = liftPasses[0];
            var liftPassAdult   = liftPasses[1];

            liftPassStudent.Price = liftPassAdult.Price;
            liftPassStudent.Price = controller.CalculatePrice(liftPassStudent);

            Assert.AreEqual(expectedResult, liftPassStudent.Price);
        }
Example #2
0
        private void Buy()
        {
            ListAllTypes();

            LiftPass liftPass = SelectType();

            string type;
            int    i = 1;

            do
            {
                if (i > 1)
                {
                    Console.WriteLine("Invalid input!", Color.Pink);
                }
                Console.WriteLine("\nAre you a (Adult / Kid / Student / Retired):");
                type = Console.ReadLine();
                i++;
            } while (type.ToLower() != "adult" && type.ToLower() != "kid" && type.ToLower() != "student" && type.ToLower() != "retired");
            liftPass.Type = FirstCharToUpper(type);


            var price = liftPassController.CalculatePrice(liftPass);

            Console.WriteLine($"\nIt costs {price} lv. ", Color.LightGreen);
            boughtPasses.Add(liftPass);
            Console.WriteLine();
            Console.WriteLine(new string('-', 52), Color.LightGoldenrodYellow);
            Console.WriteLine(new string(' ', 19) + "You have bought:", Color.LightGoldenrodYellow);
            Console.WriteLine(new string('-', 52), Color.LightGoldenrodYellow);

            foreach (var pass in boughtPasses)
            {
                Console.WriteLine(new string(' ', 18) + $"{pass.Description} for {pass.Type} ");
                Console.WriteLine();
            }
        }