Esempio n. 1
0
        public void Validate__Sightseeing_hour_is_is_not_during_opening_hours__Should_be_invalid()
        {
            // DateTime is 15 minutes after closing.
            var invalidGroup = new SightseeingGroup {
                SightseeingDate = _info.GetClosingDateTime(DateTime.Now).AddMinutes(15)
            };

            _validator.ShouldHaveValidationErrorFor(x => x.SightseeingDate, invalidGroup);
        }
Esempio n. 2
0
        public void ClosingDateTime__ClosingHour_is_18_00__Should_return_date_time_with_hour_equals_18_00()
        {
            int hour   = 18;
            int minute = 0;
            var now    = DateTime.Now;

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

            var datetime = _info.GetClosingDateTime(now);

            datetime.Hour.Should().Be(hour);
            datetime.Minute.Should().Be(minute);
            datetime.Date.Should().BeSameDateAs(now.Date);
        }
Esempio n. 3
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);
        }