コード例 #1
0
        public void CreateSchedule_WhenValidTestPassed_ShouldSetTwoSchedules(int countFilm, int countHall, int expectedCountUniqueFilms, bool expectedAllScheduleIsUnique)
        {
            Cinema          actualCinema   = GetCinemaForValidTest(countFilm, countHall);
            List <Film>     allFilms       = new List <Film>(Cinema.AllFilm);
            List <Schedule> actualSchedule = new List <Schedule>();

            actualCinema.CreateSchedules();
            actualSchedule = actualCinema.GetSchedules();
            int actualCountUniqueFilms = 0;
            int actualEmptyTime        = 0;

            foreach (Schedule schedule in actualSchedule)
            {
                actualEmptyTime += schedule.EmptyTime;
                foreach (Film scheduleFilm in schedule.Films)
                {
                    if (allFilms.Contains(scheduleFilm))
                    {
                        allFilms.Remove(scheduleFilm);
                        ++actualCountUniqueFilms;
                    }
                }
            }

            actualEmptyTime = actualEmptyTime / actualSchedule.Count;

            bool            actualAllScheduleIsUnique = true;
            List <Schedule> allSchedules = new List <Schedule>();
            var             temp         = !actualCinema.Halls.GroupBy(x => x.Schedule).
                                           Any(y => y.ToList().Count > 1);

            foreach (Hall hall in actualCinema.Halls)
            {
                if (allSchedules.Contains(hall.Schedule))
                {
                    actualAllScheduleIsUnique = false;
                    break;
                }

                allSchedules.Add(new Schedule(hall.Schedule));
            }

            Assert.AreEqual(actualAllScheduleIsUnique, temp);

            Assert.AreEqual(expectedCountUniqueFilms, actualCountUniqueFilms);
            Assert.IsTrue(actualEmptyTime >= 0);
            Assert.AreEqual(expectedAllScheduleIsUnique, actualAllScheduleIsUnique);
        }