public void TestTakeTen() { // 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> { // Put showings in the list with ID's 1 to 11, and check if only 1 to 10 stayed(first 10) new Showing { ShowingID = 1 }, new Showing { ShowingID = 2 }, new Showing { ShowingID = 3 }, new Showing { ShowingID = 4 }, new Showing { ShowingID = 5 }, new Showing { ShowingID = 6 }, new Showing { ShowingID = 7 }, new Showing { ShowingID = 8 }, new Showing { ShowingID = 9 }, new Showing { ShowingID = 10 }, new Showing { ShowingID = 11 } }; IEnumerable <Showing> showings = showingslist.ToEnumerable(); // Act List <Showing> resultList = FilterLogic.TakeTen(showings); List <int> expectedResult = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; List <int> results = new List <int> { resultList[0].ShowingID, resultList[1].ShowingID, resultList[2].ShowingID, resultList[3].ShowingID, resultList[4].ShowingID, resultList[5].ShowingID, resultList[6].ShowingID, resultList[7].ShowingID, resultList[8].ShowingID, resultList[9].ShowingID }; // Assert Assert.AreEqual(expectedResult[0], results[0]); Assert.AreEqual(expectedResult[9], results[9]); }
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)); }