public function testValidatesEachDateThatAReservationRepeatsOn()
 {
     $start = Date::Parse('2010-01-01');
     $end = Date::Parse('2010-01-02');
     $reservationDates = new DateRange($start, $end);
     $twoRepetitions = new RepeatWeekly(1, $start->AddDays(14), array($start->Weekday()));
     $repeatDates = $twoRepetitions->GetDates($reservationDates);
     $reservation = new TestReservationSeries();
     $reservation->WithResource(new FakeBookableResource(1));
     $reservation->WithDuration($reservationDates);
     $reservation->WithRepeatOptions($twoRepetitions);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->exactly(1 + count($repeatDates)))->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue(array()));
     $rule = new ResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
 }
 public function testConfigurationStringCanBeDeserialized()
 {
     $terminationDate = Date::Parse('2010-12-12 01:06:07', 'UTC');
     $dateString = $terminationDate->ToDatabase();
     $interval = 10;
     // none
     $config = RepeatConfiguration::Create(RepeatType::None, '');
     $this->assertEquals(RepeatType::None, $config->Type);
     // daily
     $daily = new RepeatDaily($interval, $terminationDate);
     $config = RepeatConfiguration::Create($daily->RepeatType(), $daily->ConfigurationString());
     $this->assertEquals(RepeatType::Daily, $config->Type);
     $this->assertEquals(10, $config->Interval);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     // weekly
     $weekdays = array(1, 3, 4, 5);
     $weekly = new RepeatWeekly($interval, $terminationDate, $weekdays);
     $config = RepeatConfiguration::Create($weekly->RepeatType(), $weekly->ConfigurationString());
     $this->assertEquals(RepeatType::Weekly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals($weekdays, $config->Weekdays);
     // day of month
     $dayOfMonth = new RepeatDayOfMonth($interval, $terminationDate);
     $config = RepeatConfiguration::Create($dayOfMonth->RepeatType(), $dayOfMonth->ConfigurationString());
     $this->assertEquals(RepeatType::Monthly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals(RepeatMonthlyType::DayOfMonth, $config->MonthlyType);
     // weekday of month
     $weekOfMonth = new RepeatWeekDayOfMonth($interval, $terminationDate);
     $config = RepeatConfiguration::Create($weekOfMonth->RepeatType(), $weekOfMonth->ConfigurationString());
     $this->assertEquals(RepeatType::Monthly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals(RepeatMonthlyType::DayOfWeek, $config->MonthlyType);
     // yearly
     $yearly = new RepeatYearly($interval, $terminationDate);
     $config = RepeatConfiguration::Create($yearly->RepeatType(), $yearly->ConfigurationString());
     $this->assertEquals(RepeatType::Yearly, $config->Type);
     $this->assertEquals(10, $config->Interval);
     $this->assertEquals($terminationDate, $config->TerminationDate);
 }