Beispiel #1
0
        public void OpeningDateTime__OpeningHour_is_10_30__Should_return_date_time_with_hour_equals_10_30()
        {
            int hour   = 10;
            int minute = 30;
            var now    = DateTime.Now;

            _info.OpeningHours.ToArray().First(x => x.DayOfWeek == now.DayOfWeek).OpeningHour = new TimeSpan(hour, minute, 0);

            var datetime = _info.GetOpeningDateTime(now);

            datetime.Hour.Should().Be(hour);
            datetime.Minute.Should().Be(minute);
            datetime.Date.Should().BeSameDateAs(now.Date);
        }
Beispiel #2
0
        private IList <GroupInfo> GetDailyDates(VisitInfo info, DateTime dateTime, IEnumerable <SightseeingGroup> futureGroups)
        {
            List <GroupInfo> availableDates = new List <GroupInfo>();
            var sightseeingDuration         = info.SightseeingDuration;
            var openingDateTime             = info.GetOpeningDateTime(dateTime);
            var openingHoursNumber          = info.GetClosingDateTime(dateTime) - openingDateTime;
            int groupsPerDay = (int)(openingHoursNumber.Hours / sightseeingDuration);

            // Get available sightseeing dates for one day.
            for (int i = 0; i < groupsPerDay; i++)
            {
                GroupInfo groupInfo     = new GroupInfo();
                var       groupDateTime = openingDateTime.AddHours(i * sightseeingDuration);

                // Get existed group with the same date as currently processing.
                var existedGroup = futureGroups.Where(z => z.SightseeingDate == groupDateTime);

                if (existedGroup.Count() == 0)
                {
                    groupInfo.AvailablePlace = info.MaxAllowedGroupSize;
                }
                else
                {
                    var group = existedGroup.FirstOrDefault();

                    if (group.IsAvailablePlace)
                    {
                        groupInfo.AvailablePlace = group.MaxGroupSize - group.CurrentGroupSize;
                    }
                    else
                    {
                        // If there is no group with available places, do not add the group and start the next iteration.
                        continue;
                    }
                }

                groupInfo.SightseeingDate = groupDateTime;
                availableDates.Add(groupInfo);
            }

            return(availableDates);
        }