public function testGetReservationsPullsReservationFromTheRepositoryAndAddsThemToTheCoordinator()
 {
     $timezone = 'UTC';
     $startDate = Date::Now();
     $endDate = Date::Now();
     $scheduleId = 100;
     $range = new DateRange($startDate, $endDate);
     $repository = $this->getMock('IReservationViewRepository');
     $reservationListing = new TestReservationListing();
     $listingFactory = $this->getMock('IReservationListingFactory');
     $rows = FakeReservationRepository::GetReservationRows();
     $res1 = ReservationItemView::Populate($rows[0]);
     $res2 = ReservationItemView::Populate($rows[1]);
     $res3 = ReservationItemView::Populate($rows[2]);
     $date = Date::Now();
     $blackout1 = new TestBlackoutItemView(1, $date, $date, 1);
     $blackout2 = new TestBlackoutItemView(2, $date, $date, 2);
     $blackout3 = new TestBlackoutItemView(3, $date, $date, 3);
     $repository->expects($this->once())->method('GetReservationList')->with($this->equalTo($startDate), $this->equalTo($endDate), $this->isNull(), $this->isNull(), $this->equalTo($scheduleId), $this->isNull())->will($this->returnValue(array($res1, $res2, $res3)));
     $repository->expects($this->once())->method('GetBlackoutsWithin')->with($this->equalTo(new DateRange($startDate, $endDate)), $this->equalTo($scheduleId))->will($this->returnValue(array($blackout1, $blackout2, $blackout3)));
     $listingFactory->expects($this->once())->method('CreateReservationListing')->with($this->equalTo($timezone))->will($this->returnValue($reservationListing));
     $service = new ReservationService($repository, $listingFactory);
     $listing = $service->GetReservations($range, $scheduleId, $timezone);
     $this->assertEquals($reservationListing, $listing);
     $this->assertTrue(in_array($res1, $reservationListing->reservations));
     $this->assertTrue(in_array($res2, $reservationListing->reservations));
     $this->assertTrue(in_array($res3, $reservationListing->reservations));
     $this->assertTrue(in_array($blackout1, $reservationListing->blackouts));
     $this->assertTrue(in_array($blackout2, $reservationListing->blackouts));
     $this->assertTrue(in_array($blackout3, $reservationListing->blackouts));
 }
 public function GetAccessoryReservationList(Date $startDate, Date $endDate, $accessoryName)
 {
     $getReservations = new GetReservationsByAccessoryNameCommand($startDate, $endDate, $accessoryName);
     $result = ServiceLocator::GetDatabase()->Query($getReservations);
     $reservations = array();
     while ($row = $result->GetRow()) {
         $reservations[] = ReservationItemView::Populate($row);
     }
     $result->Free();
     return $reservations;
 }
 public function testGetsReservationListForDateRangeAndUser()
 {
     $startDate = Date::Parse('2011-01-01');
     $endDate = Date::Parse('2011-01-01');
     $referenceNumber1 = "ref1";
     $resource1 = "resource1";
     $start1 = Date::Parse('2011-08-09', 'UTC');
     $end1 = Date::Parse('2011-08-10', 'UTC');
     $resourceId = 929;
     $instanceId = 1000;
     $userLevelId = 2;
     $title = 'title';
     $description = 'description';
     $scheduleId = 213;
     $fname = 'fn';
     $lname = 'ln';
     $userId = 111;
     $phone = 'phone';
     $organization = 'organization';
     $position = 'position';
     $participant_list = '100=p 1!sep!200=p 2!sep!500=p 3';
     $invitee_list = '700=i 1!sep!800=1 2';
     $attributes = 'a1=av1,a2=av2';
     $preferences = 'p1=pv1,p2=pv2';
     $bufferTime = 3600;
     $rows[] = $this->GetReservationListRow($referenceNumber1, $resource1, $start1, $end1, $resourceId, $instanceId, $userLevelId, $title, $description, $scheduleId, $fname, $lname, $userId, $phone, $organization, $position, $participant_list, $invitee_list, $attributes, $preferences, $bufferTime);
     $rows[] = $this->GetReservationListRow("2", "resource", Date::Now(), Date::Now(), 1, 1, 1, null, null, 1, null, null, null, null, null, null);
     $this->db->SetRows($rows);
     $expectedCommand = new GetReservationListCommand($startDate, $endDate, $userId, ReservationUserLevel::OWNER, $scheduleId, $resourceId);
     $reservations = $this->repository->GetReservationList($startDate, $endDate, $userId, null, $scheduleId, $resourceId);
     $actualCommand = $this->db->_LastCommand;
     $this->assertEquals($expectedCommand, $actualCommand);
     $this->assertEquals(count($rows), count($reservations));
     $expectedItem1 = ReservationItemView::Populate($rows[0]);
     $this->assertEquals($expectedItem1, $reservations[0]);
 }