public void ShouldRemoveScheduledHoursFromRemainingWorkHoursInDay()
        {
            // given
            var repoMock           = new Mock <IReservationsRepository>();
            var workHoursValidator = new WorkHoursValidator(repoMock.Object);
            var workDay            = new WorkDay(new DateTime(2017, 8, 1, 7, 0, 0));
            var schedule           = new Schedule()
            {
                StartDate = new DateTime(2017, 8, 1, 11, 15, 0),
                EndDate   = new DateTime(2017, 8, 1, 11, 45, 0)
            };
            var expected = workDay.GetRemainingHours();

            expected.Remove(new WorkHour(11, 15));
            expected.Remove(new WorkHour(11, 30));

            // when
            workHoursValidator.CheckAndUpdate(new List <WorkDay>()
            {
                workDay
            });
            var result = workDay.GetRemainingHours();

            // then
            Assert.AreEqual(expected.Count, result.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
Beispiel #2
0
        public void ShouldReturnSubsetOfWorkHoursStartingWithNotEqualHourInTheMiddleOfOpenHours()
        {
            // given
            var dateTime      = new DateTime(2017, 8, 1, 14, 30, 0);
            var workDay       = new WorkDay(dateTime);
            var expectedHours = new List <WorkHour>();

            int startingMinute = 30;

            for (int i = 14; i < 16; i++)
            {
                for (int j = startingMinute; j < 60; j += 15)
                {
                    expectedHours.Add(new WorkHour(i, j));
                }
                startingMinute = 0;
            }

            // when
            var resultHours = workDay.GetRemainingHours();

            // then
            int index = 0;

            Assert.AreEqual(expectedHours.Count, resultHours.Count);
            foreach (var hour in resultHours)
            {
                Assert.AreEqual(hour.Hour, expectedHours[index].Hour);
                Assert.AreEqual(hour.Minute, expectedHours[index].Minute);
                index++;
            }
        }
Beispiel #3
0
        public void ShouldReturnWorkingHoursWhenTimeOfDayIsBeforeStartingHour()
        {
            // given
            var dateTime      = new DateTime(2017, 8, 1, 7, 0, 0);
            var workDay       = new WorkDay(dateTime);
            var expectedHours = new List <WorkHour>();

            for (int i = 8; i < 16; i++)
            {
                for (int j = 0; j < 60; j += 15)
                {
                    expectedHours.Add(new WorkHour(i, j));
                }
            }

            // when
            var resultHours = workDay.GetRemainingHours();

            // then
            int index = 0;

            Assert.AreEqual(expectedHours.Count, resultHours.Count);
            foreach (var hour in resultHours)
            {
                Assert.AreEqual(hour.Hour, expectedHours[index].Hour);
                Assert.AreEqual(hour.Minute, expectedHours[index].Minute);
                index++;
            }
        }
Beispiel #4
0
        public List <string> WorkingHoursLeftToString(WorkDay day)
        {
            var hoursLeft       = day.GetRemainingHours();
            var hoursLeftString = new List <string>();

            foreach (var hour in hoursLeft)
            {
                hoursLeftString.Add(hour.ToString());
            }

            return(hoursLeftString);
        }
Beispiel #5
0
 private bool dayHasWorkingHours(WorkDay day)
 {
     return(day.GetRemainingHours().Count > 0 ? true : false);
 }