public void Can_Create_With_Booking_And_Update_TimeSots()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 50, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 15, 0)}
                },              DateTime = new DateTime(2000,1,1,9,0,0) },
                new Booking() {Treatments = new List<Treatment>
                {                       new Treatment {Duration = new TimeSpan(0, 0, 45, 0)},
                                        new Treatment { Duration = new TimeSpan(0, 1, 0, 0) }},
                                DateTime = new DateTime(2000, 1, 1, 12, 30, 0)}
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh,bookings);

            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 4).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts=>ts.Number == 5).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 9).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 13).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 14).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 18).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 19).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 25).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 26).IsAvailable);
        }
        public void Can_Add_Booking()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {  Id = 1,
                                Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 50, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 15, 0)}
                },              DateTime = new DateTime(2000,1,1,9,0,0) },
                new Booking() {Id =2,
                                Treatments = new List<Treatment>
                {                       new Treatment {Duration = new TimeSpan(0, 0, 45, 0)},
                                        new Treatment { Duration = new TimeSpan(0, 1, 0, 0) }},
                                DateTime = new DateTime(2000, 1, 1, 12, 30, 0)}
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh, bookings);
            Booking booking = new Booking() {Id = 3,
                Treatments = new List<Treatment>()
            {
                new Treatment() {Duration = new TimeSpan(0,0,45,0,0)}
            } , DateTime = new DateTime(2000,1,1,14,15,0)};
            agendaService.AddBooking(booking);

            Assert.AreEqual(3,agendaService.Bookings.Count);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts=>ts.Number == 26).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 28).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 29).IsAvailable);
        }
 private void Create_WorkingHours_With_Invalid_MultiplicityStartTime()
 {
     Time starTime = new Time(7, 2);          //7:02
     Time endTime = new Time(15, 30);         //15:30
     Time starLunchTime = new Time(12, 0);   //12:00 START LUNCH
     TimeSpan lunchDuration = new TimeSpan(0, 30, 0);                //30 min
     DayWorkingHours wh = new DayWorkingHours(starTime, endTime, starLunchTime, lunchDuration);
 }
 private void Create_WorkingHours_StartLunchSameSomEndTime()
 {
     Time starTime = new Time(7, 0);          //7:00
     Time endTime = new Time(15,30);         //15:30
     Time starLunchTime = new Time(15, 30);   //15:30 START LUNCH
     TimeSpan lunchDuration = new TimeSpan(0, 30, 0);                //30 min
     DayWorkingHours wh = new DayWorkingHours(starTime, endTime, starLunchTime, lunchDuration);
 }
        public void Can_Create_Right_Antal_TimeSlots()
        {
            IDayWorkingHours wh = new DayWorkingHours(new Time(8,0), new Time(15, 25),
                new Time(11,30), new TimeSpan(0,0,30,0));
            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000,1,1), wh);

            int amounOfTimeSlots = agendaService.TimeSlots.Count;

            Assert.AreEqual(30,amounOfTimeSlots);
        }
        public void Can_Create_TimeSlots_With_Unavailable_Slots_For_Lunch()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
                new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh);

            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 14).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 15).IsAvailable);
            Assert.IsFalse(agendaService.TimeSlots.Find(ts => ts.Number == 16).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 17).IsAvailable);
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            CreateTherapistViewModel model = (CreateTherapistViewModel) bindingContext.Model
                                             ?? new CreateTherapistViewModel();

            model.WorkingHourses = new List<DayWorkingHours>();

            HttpRequestBase request = controllerContext.HttpContext.Request;

            for (int i = 0; i < 7; i++)
            {
                string start = request.Form.Get("WorkingHourses.[" + i + "].StartTime");
                string end = request.Form.Get("WorkingHourses.[" + i + "].EndTime");
                string startLunch = request.Form.Get("WorkingHourses.[" + i + "].StartLunch");
                string duration = request.Form.Get("WorkingHourses.[" + i + "].LunchDuration");

                Time startTime = new Time(GetHours(start),GetMinutes(start));
                Time endTime = new Time(GetHours(end), GetMinutes(end));
                Time startLunchTime = new Time(GetHours(startLunch), GetMinutes(startLunch));
                TimeSpan durationTime = new TimeSpan(GetHours(duration),GetMinutes(duration),GetSeconds(duration));

                try
                {
                    DayWorkingHours wh = new DayWorkingHours(startTime, endTime, startLunchTime, durationTime);
                    wh.DayOfWeek = (i + 1) % 7;
                    model.WorkingHourses.Add(wh);
                }
                catch (Exception)
                {
                   // Ignore
                }

            }
            model.Description = GetValue(request, "Description");
            model.Name =  GetValue(request, "Name");

            string [] treatmentsId =  request.Form.GetValues("SelectedTreatmentId");
            if (treatmentsId != null) model.SelectedTreatmentId =
                    Array.ConvertAll(treatmentsId , int.Parse);

            return model;
        }
        public void Can_calculate_slotsAmount_from_workingHours()
        {
            int amount = 0;
            TimeSlot timeslot = new TimeSlot(0,new Time(0,0), new TimeSpan(0,0,15,0),true );

            IDayWorkingHours dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 30),
                new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            amount = timeslot.GetSlotsAmount(dayWorkingHours);
            Assert.AreEqual(30,amount);

            dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 35),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            amount = timeslot.GetSlotsAmount(dayWorkingHours);
            Assert.AreEqual(31,amount);

            dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 20),
             new Time( 11, 30), new TimeSpan(0, 0, 30, 0));
            amount = timeslot.GetSlotsAmount(dayWorkingHours);
            Assert.AreEqual(30, amount);

            dayWorkingHours = new DayWorkingHours(new Time(8,0),new Time(15,30),new Time(12,0),new TimeSpan(0,0,0) );
            amount = timeslot.GetSlotsAmount(dayWorkingHours);
            Assert.AreEqual(30, amount);
        }
 private void Create_Working_Hours_StartGreaterThanEnd()
 {
     Time startTime = new Time(7,0);         //7:00  START
     Time endTime = new Time(6,30);          //6:30  END
     Time startLunchTime = new Time(12, 0);   //12:00
     TimeSpan lunchDuration = new TimeSpan(0, 30, 0);                //30 min
     DayWorkingHours wh = new DayWorkingHours(startTime, endTime, startLunchTime, lunchDuration);
 }
 private void Create_WorkingHours_With_LongLunch()
 {
     Time starTime = new Time(7, 0);          //7:00
     Time endTime = new Time(15, 30);         //15:30
     Time starLunchTime = new Time(14, 00);   //14:00 START LUNCH
     TimeSpan lunchDuration = new TimeSpan(0, 91, 0);                //90 min
     DayWorkingHours wh = new DayWorkingHours(starTime, endTime, starLunchTime, lunchDuration);
 }
        public void Is_Place_For_Booking()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {  Id = 1,
                                Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 50, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 15, 0)}
                },              DateTime = new DateTime(2000,1,1,9,0,0) },
                new Booking() {Id =2,
                                Treatments = new List<Treatment>
                {                       new Treatment {Duration = new TimeSpan(0, 0, 45, 0)},
                                        new Treatment { Duration = new TimeSpan(0, 1, 0, 0) }},
                                DateTime = new DateTime(2000, 1, 1, 12, 30, 0)}
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh, bookings);
            Booking booking = new Booking()
            {
                Id = 3,
                Treatments = new List<Treatment>()
            {
                new Treatment() {Duration = new TimeSpan(0,1,15,0,0)} //1time 15min
            }};

            Assert.IsTrue(agendaService.IsAvailableForBooking(booking));
            booking.Treatments = new List<Treatment> { new Treatment() { Duration = new TimeSpan(0, 1, 16, 0, 0) } };
            Assert.IsFalse(agendaService.IsAvailableForBooking(booking));
        }
        public void Can_Remove_Booking_With_Given_Id()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
                 new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            DateTime now = System.DateTime.Now;
            DateTime twoDaysFromNow = now.AddDays(2);
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {  Id = 1,
                                Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 50, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 15, 0)}
                },              DateTime = new DateTime(twoDaysFromNow.Year,twoDaysFromNow.Month,twoDaysFromNow.Day,9,0,0) },
                new Booking() {Id =2,
                                Treatments = new List<Treatment>
                {                       new Treatment {Duration = new TimeSpan(0, 0, 45, 0)},
                                        new Treatment { Duration = new TimeSpan(0, 1, 0, 0) }},
                                DateTime = new DateTime(twoDaysFromNow.Year,twoDaysFromNow.Month,twoDaysFromNow.Day, 12, 30, 0)}
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(now.Year, now.Month, now.Day).AddDays(2), wh, bookings);
            agendaService.RemoveBooking(1);

            Assert.AreEqual(1, agendaService.Bookings.Count);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 5).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 13).IsAvailable);
            Assert.IsTrue(agendaService.TimeSlots.Find(ts => ts.Number == 14).IsAvailable);
        }
        public void Can_Not_Create_Agenda_With_Wrong_Booking_Duration()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 60, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 35, 0)} //duration 2t 35min
                },              DateTime = new DateTime(2000,1,1,9,0,0) }
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh, bookings);
        }
        public void Can_Not_Add_Boking_If_No_Place()
        {
            DayWorkingHours wh = new DayWorkingHours(new Time(8, 0), new Time(15, 25),
               new Time(11, 30), new TimeSpan(0, 0, 30, 0));
            List<Booking> bookings = new List<Booking>
            {
                new Booking() {  Id = 1,
                                Treatments = new List<Treatment>()
                {                    new Treatment { Duration = new TimeSpan(0, 0, 50, 0)},
                                     new Treatment {Duration = new TimeSpan(0, 1, 15, 0)}
                },              DateTime = new DateTime(2000,1,1,9,0,0) },
                new Booking() {Id =2,
                                Treatments = new List<Treatment>
                {                       new Treatment {Duration = new TimeSpan(0, 0, 45, 0)},
                                        new Treatment { Duration = new TimeSpan(0, 1, 0, 0) }},
                                DateTime = new DateTime(2000, 1, 1, 12, 30, 0)}
            };

            DayAgendaService agendaService = new DayAgendaService(new DateTime(2000, 1, 1), wh, bookings);
            Booking booking = new Booking()
            {
                Id = 3,
                Treatments = new List<Treatment>()
            {
                new Treatment() {Duration = new TimeSpan(0,1,5,0,0)}
            },
                DateTime = new DateTime(2000, 1, 1, 8, 0, 0)
            };
            agendaService.AddBooking(booking);
        }
 public DayAgendaService GetDayAgenda(DateTime date, DayWorkingHours wh, List<Booking> bookings)
 {
     return new DayAgendaService(date,wh,bookings);
 }