public function testGetsConflictingReservationTimesForSingleDateSingleResourceWithBufferTimes()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $conflict2 = new TestReservationItemView(3, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource1->GetId());
     $conflict2->WithBufferTime($bufferTime);
     $nonConflict1 = new TestReservationItemView(4, Date::Parse('2010-04-04 06:00', 'UTC'), Date::Parse('2010-04-04 07:30', 'UTC'), 2);
     $nonConflict1->WithBufferTime($bufferTime);
     $nonConflict2 = new TestReservationItemView(5, Date::Parse('2010-04-04 02:30', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId());
     $nonConflict2->WithBufferTime($bufferTime);
     $nonConflict3 = new TestReservationItemView(6, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId());
     $nonConflict3->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60)))->will($this->returnValue(array($conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3)));
     $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 public function testGetsAllResourceAvailabilityForARequestTime()
 {
     $date = Date::Parse('2014-01-01 04:30:00', 'America/Chicago');
     $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso());
     $resourceId1 = 1;
     $resourceId2 = 2;
     $resourceId3 = 3;
     $startTime = $date->AddHours(-1);
     $endTime = $date->AddHours(1);
     $resources = array(new FakeBookableResource($resourceId1), new FakeBookableResource($resourceId2), new FakeBookableResource($resourceId3));
     $this->repository->expects($this->once())->method('GetResourceList')->will($this->returnValue($resources));
     $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1);
     $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1);
     $upcoming2 = new TestReservationItemView(3, $endTime->AddHours(3), $endTime->AddHours(4), $resourceId1);
     $upcoming3 = new TestReservationItemView(4, $endTime->AddHours(5), $endTime->AddHours(6), $resourceId1);
     $upcoming4 = new TestReservationItemView(5, $endTime->AddHours(3), $endTime->AddHours(3), $resourceId2);
     $upcoming5 = new TestReservationItemView(6, $startTime, $endTime->AddHours(2), $resourceId3);
     $reservations = array($conflicting, $upcoming, $upcoming2, $upcoming3, $upcoming4, $upcoming5);
     $endDate = $date->AddDays(7);
     $this->reservationRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($date->AddDays(-1)->ToUtc()), $this->equalTo($endDate->ToUtc()))->will($this->returnValue($reservations));
     $this->service->GetAvailability();
     $resources = array(new ResourceAvailabilityResponse($this->server, $resources[0], $conflicting, $upcoming, $endTime->AddHours(4), $endDate), new ResourceAvailabilityResponse($this->server, $resources[1], null, $upcoming2, null, $endDate), new ResourceAvailabilityResponse($this->server, $resources[2], $upcoming5, null, $upcoming5->GetEndDate(), $endDate));
     $this->assertEquals(new ResourcesAvailabilityResponse($this->server, $resources), $this->server->_LastResponse);
 }
 public function testApplicationAdminsAreExcludedFromBufferConstraints()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $reservation->WithBookedBy(new FakeUserSession(true));
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 06:00', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate), $this->equalTo($endDate))->will($this->returnValue(array($conflict1)));
     $rule = new ResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
 public function testSkipsAddingBufferSlotsIfThereIsAnotherItemAtThatTime()
 {
     $tz = 'America/Chicago';
     $listDate = Date::Parse('2011-02-08', $tz);
     $layout = new ScheduleLayout($tz);
     $layout->AppendPeriod(Time::Parse('0:00', $tz), Time::Parse('0:30', $tz));
     $layout->AppendPeriod(Time::Parse('0:30', $tz), Time::Parse('1:00', $tz));
     $layout->AppendPeriod(Time::Parse('1:00', $tz), Time::Parse('1:30', $tz));
     $layout->AppendPeriod(Time::Parse('1:30', $tz), Time::Parse('2:00', $tz));
     $layout->AppendPeriod(Time::Parse('2:00', $tz), Time::Parse('6:00', $tz));
     $layout->AppendPeriod(Time::Parse('6:00', $tz), Time::Parse('0:00', $tz));
     $item1 = new TestReservationItemView(1, Date::Parse('2011-02-08 0:30', $tz)->ToUtc(), Date::Parse('2011-02-08 1:00', $tz)->ToUtc(), 1);
     $item2 = new TestReservationItemView(2, Date::Parse('2011-02-08 1:30', $tz)->ToUtc(), Date::Parse('2011-02-08 2:00', $tz)->ToUtc(), 1);
     $item1->WithBufferTime(60 * 60);
     $item2->WithBufferTime(60 * 60);
     $r1 = new ReservationListItem($item1);
     $r2 = new ReservationListItem($item2);
     $list = new ScheduleReservationList(array($r1, $r2), $layout, $listDate, false);
     /** @var IReservationSlot[] $slots */
     $slots = $list->BuildSlots();
     $this->assertTrue($slots[0]->Begin()->Equals(Time::Parse('0:00', $tz)));
     $this->assertTrue($slots[0]->End()->Equals(Time::Parse('0:30', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
     $this->assertTrue($slots[1]->Begin()->Equals(Time::Parse('0:30', $tz)));
     $this->assertTrue($slots[1]->End()->Equals(Time::Parse('1:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[1]);
     $this->assertTrue($slots[2]->Begin()->Equals(Time::Parse('1:00', $tz)));
     $this->assertTrue($slots[2]->End()->Equals(Time::Parse('1:30', $tz)));
     $this->assertInstanceOf('EmptyReservationSlot', $slots[2]);
     $this->assertTrue($slots[3]->Begin()->Equals(Time::Parse('1:30', $tz)));
     $this->assertTrue($slots[3]->End()->Equals(Time::Parse('2:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[3]);
     $this->assertTrue($slots[4]->Begin()->Equals(Time::Parse('2:00', $tz)));
     $this->assertTrue($slots[4]->End()->Equals(Time::Parse('6:00', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
 }