public void TestOrderByDate()
        {
            // Arrange

            // First we have to create an IEnumerable of showings to use in the method that will be tested
            List <Showing> showingslist = new List <Showing> {
                // This showing is the furthest away so put this one in first
                new Showing {
                    BeginDateTime = new DateTime(2017, 4, 21, 17, 00, 00),
                    ShowingID     = 3
                },
                // This showing should stay in the middle
                new Showing {
                    BeginDateTime = new DateTime(2017, 4, 01, 17, 00, 00),
                    ShowingID     = 2
                },
                // This showing should be placed first after the method is called
                new Showing {
                    BeginDateTime = new DateTime(2017, 2, 15, 17, 00, 00),
                    ShowingID     = 1
                },
            };

            IEnumerable <Showing> showings = showingslist.ToEnumerable();

            // Act
            IEnumerable <Showing> results    = FilterLogic.OrderByDate(showings);
            List <Showing>        resultList = results.ToList();

            List <int> expectedresult = new List <int> {
                1,
                2,
                3
            };
            List <int> result = new List <int> {
                resultList[0].ShowingID,
                resultList[1].ShowingID,
                resultList[2].ShowingID
            };

            // Assert
            Assert.AreEqual(expectedresult[0], result[0]);
            Assert.AreEqual(expectedresult[1], result[1]);
            Assert.AreEqual(expectedresult[2], result[2]);
        }
Beispiel #2
0
        public ActionResult GetFilteredFilms()
        {
            CinemaViewModel model = (CinemaViewModel)TempData["model"];

            if (model == null)
            {
                model = new CinemaViewModel();
            }

            // Retrieve the user input
            string dayInput  = Request["searchDay"];  // format: 03-04-2017      (string)
            string timeInput = Request["searchTime"]; // format: 13 14 15 .... (int)

            // Initialize time variable that will be used to work with the user input
            DateTime time;

            // If a day has been entered, put this in time. Else, take the current day.
            if (dayInput != "")
            {
                time = DateTime.ParseExact(dayInput, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                time = DateTime.Now;
            }

            // If a time has been entered, put this in time.
            if (timeInput != "")
            {
                time = time.AddHours(Int32.Parse(timeInput));
            }

            var dayofweek = time.DayOfWeek;

            //First get all showings
            IEnumerable <Showing> allShowings = showingRepo.GetShowings();

            //Filter the list to only contain showings coming after the given time
            IEnumerable <Showing> showingsAfterDate = FilterLogic.GetShowingsAfterDate(allShowings, time);

            //Order the results by date so that the most near one will be shown first
            IEnumerable <Showing> showingsOrdered = FilterLogic.OrderByDate(showingsAfterDate);

            //Filter out showings that are not on the chosen day
            IEnumerable <Showing> todaysShowings = FilterLogic.TodaysShowings(showingsOrdered, time);

            //If the list contains more than 10, take the first 10 showings to show on the page
            List <Showing> allTenShowings = new List <Showing>();

            if (todaysShowings.Count() > 10)
            {
                allTenShowings = FilterLogic.TakeTen(todaysShowings);
            }
            else
            {
                allTenShowings = todaysShowings.ToList();
            }

            //Add the corresponding film to the list of showings,
            //so that the information of the film can be used
            List <Film> allFilms = new List <Film>();

            //Add every film that has been found in the result list of showings
            FilterLogic.AddFilms(allTenShowings, allFilms);

            List <Review> allReviews = reviewRepo.GetReviews().ToList();

            if (time.Day == DateTime.Now.Day)
            {
                ViewBag.selectedDate = Resources.Global.FilterControllerToday;
            }
            else
            {
                ViewBag.selectedDate = FilterLogic.GetDay(time.DayOfWeek) + " " + time.Day + "-" + time.Month;
            }

            ViewBag.reviews         = allReviews;
            ViewBag.selectedTime    = time.ToString("HH:mm");
            ViewBag.numberOfResults = allTenShowings.Count;
            ViewBag.resultShowings  = allTenShowings;
            ViewBag.resultFilms     = allFilms;

            TempData["Model"] = model;
            return(View("FilteredFilms", model));
        }