public function testGetsListOfReservationsThatThisUserCanAdminister()
 {
     $user = new User();
     $adminGroup2 = new UserGroup(2, null, 1, RoleLevel::GROUP_ADMIN);
     $adminGroup3 = new UserGroup(3, null, 1, RoleLevel::GROUP_ADMIN);
     $user->WithOwnedGroups(array($adminGroup2, $adminGroup3));
     $reservationRepo = $this->getMock('IReservationViewRepository');
     $reservationAuth = $this->getMock('IReservationAuthorization');
     $userRepo = $this->getMock('IUserRepository');
     $userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user));
     $service = new GroupAdminManageReservationsService($reservationRepo, $userRepo, $reservationAuth, $this->getMock('IReservationHandler'), $this->getMock('IUpdateReservationPersistenceService'));
     $reservationRows = FakeReservationRepository::GetReservationRows();
     $this->db->SetRow(0, array(array(ColumnNames::TOTAL => 4)));
     $this->db->SetRow(1, $reservationRows);
     $filter = new ReservationFilter();
     $results = $service->LoadFiltered(1, 2, $filter, $this->fakeUser);
     $getGroupReservationsCommand = new GetFullGroupReservationListCommand(array(2, 3));
     $filterCommand = new FilterCommand($getGroupReservationsCommand, $filter->GetFilter());
     $countCommand = new CountCommand($filterCommand);
     $this->assertEquals($countCommand, $this->db->_Commands[0]);
     $this->assertEquals($filterCommand, $this->db->_Commands[1]);
     $resultList = $results->Results();
     $this->assertEquals(count($reservationRows), count($resultList));
     $this->assertInstanceOf('ReservationItemView', $resultList[0]);
 }
 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));
 }