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);
        }
 public bool Equals(Booking booking)
 {
     if (booking==null)
        {
        return false;
        }
        return booking.Id == Id;
 }
        public void Can_get_duration_time()
        {
            Treatment treament1 = new Treatment();
            Treatment treament2 = new Treatment();

            treament1.Duration = new TimeSpan(0,1,0,0);
            treament2.Duration = new TimeSpan(0,0,45,0);

            Booking booking = new Booking();

            Assert.AreEqual(new TimeSpan(0,0,0,0),booking.GetDuration());

            booking.Treatments.Add(treament1);
            booking.Treatments.Add(treament2);

            TimeSpan timeSpan = new TimeSpan(0,1,45,0).Duration();

            Assert.AreEqual(timeSpan,booking.GetDuration());
        }
        public ActionResult Create(CreateBookingViewModel model)
        {
            try
            {
                Booking booking = new Booking();
                booking.BookingDate = DateTime.Now;
                booking.DateTime = model.date
                    .AddHours(model.Time.Hour)
                    .AddMinutes(model.Time.Minute);

                booking.CustomerProfileId = User.Identity.GetUserId<int>();

                booking.TherapistId = model.therapistId;

                booking.Treatments = new List<Treatment>();
                foreach (int treatmendId in model.SelectedTreatmentsId)
                {
                    booking.Treatments.Add( factory.TreatmentGateway.GetOne(treatmendId));
                }

                factory.BookingGateway.CreateOne(booking);

                return RedirectToAction("Index",new { userId = User.Identity.GetUserId<int>()});
            }
            catch
            {
                return View();
            }
        }
        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_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);
        }