public function testGetsResourceById()
 {
     $resourceId = 8282;
     $resource = new FakeBookableResource($resourceId);
     $resource->SetBufferTime(3600);
     $attributes = new AttributeList();
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array($resourceId)))->will($this->returnValue($attributes));
     $this->service->GetResource($resourceId);
     $this->assertEquals(new ResourceResponse($this->server, $resource, $attributes), $this->server->_LastResponse);
 }
 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 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());
 }