public function testSucceedsWhenStartAndEndTimeMatchPeriods()
 {
     $date = Date::Now();
     $dates = new DateRange($date, $date);
     $scheduleId = 1232;
     $resource = new FakeBookableResource(1);
     $resource->SetScheduleId($scheduleId);
     $series = ReservationSeries::Create(1, $resource, null, null, $dates, new RepeatNone(), $this->fakeUser);
     $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)))->will($this->returnValue($this->layout));
     $period = new SchedulePeriod($date, $date);
     $this->layout->expects($this->at(0))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->StartDate()))->will($this->returnValue($period));
     $this->layout->expects($this->at(1))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->EndDate()))->will($this->returnValue($period));
     $result = $this->rule->Validate($series);
     $this->assertTrue($result->IsValid());
 }
 public function testWhenPeriodStartTimeIsInPast()
 {
     $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::CURRENT);
     $scheduleId = 123;
     $now = Date::Parse('2011-04-04 12:13:15', 'UTC');
     Date::_SetNow($now);
     $start = $now->AddDays(-5);
     $end = $now->AddDays(5);
     $periodStart = Date::Parse('2011-04-04 12:13:14', 'UTC');
     $periodEnd = Date::Parse('2011-04-04 12:13:16', 'UTC');
     $reservation = new TestReservationSeries();
     $reservation->WithScheduleId($scheduleId);
     $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end)));
     $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC')))->will($this->returnValue($this->layout));
     $period = new SchedulePeriod($periodStart, $periodEnd);
     $this->layout->expects($this->once())->method('GetPeriod')->with($this->equalTo($end))->will($this->returnValue($period));
     $rule = new ReservationStartTimeRule($this->scheduleRepository);
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }