private function PopulateAttachmentIds(ExistingReservationSeries $series)
 {
     $getAttachments = new GetReservationAttachmentsCommand($series->SeriesId());
     $reader = ServiceLocator::GetDatabase()->Query($getAttachments);
     while ($row = $reader->GetRow()) {
         $series->WithAttachment($row[ColumnNames::FILE_ID], $row[ColumnNames::FILE_EXTENSION]);
     }
     $reader->Free();
 }
 public function testLoadByIdFullyHydratesReservationSeriesObject()
 {
     $seriesId = 10;
     $reservationId = 1;
     $referenceNumber = 'currentInstanceRefNum';
     $ownerId = 10;
     $resourceId = 100;
     $scheduleId = 1000;
     $title = 'title';
     $description = 'description';
     $resourceId1 = 99;
     $resourceId2 = 999;
     $begin = '2010-01-05 12:30:00';
     $end = '2010-01-05 18:30:00';
     $duration = DateRange::Create($begin, $end, 'UTC');
     $interval = 3;
     $repeatType = RepeatType::Daily;
     $terminationDateString = '2010-01-20 12:30:00';
     $terminationDate = Date::FromDatabase($terminationDateString);
     $repeatOptions = new RepeatDaily($interval, $terminationDate);
     $instance1Invitees = array(1, 2, 3);
     $instance1Participants = array(4, 5);
     $instance2Invitees = array(6);
     $instance2Participants = array(7, 8, 9);
     $resourceName = 'primary resource';
     $location = 'l';
     $contact = 'c';
     $notes = 'notes';
     $minLength = '3:00';
     $maxLength = null;
     $autoAssign = true;
     $requiresApproval = false;
     $allowMultiDay = true;
     $maxParticipants = 100;
     $minNotice = '2:10';
     $maxNotice = null;
     $statusId = ReservationStatus::Pending;
     $accessoryId1 = 8111;
     $accessoryId2 = 8222;
     $quantity1 = 11;
     $quantity2 = 22;
     $attributeId1 = 908;
     $attributeValue1 = 'custom1';
     $attributeId2 = 999;
     $attributeValue2 = 'custom2';
     $fileId = 100;
     $startReminderMinutes = 25;
     $endReminderMinutes = 120;
     $allowParticipation = true;
     $expected = new ExistingReservationSeries();
     $expected->WithId($seriesId);
     $expected->WithOwner($ownerId);
     $expected->WithPrimaryResource(new BookableResource($resourceId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithTitle($title);
     $expected->WithDescription($description);
     $expected->WithResource(new BookableResource($resourceId1, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithResource(new BookableResource($resourceId2, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithRepeatOptions($repeatOptions);
     $expected->WithStatus($statusId);
     $expected->WithAccessory(new ReservationAccessory($accessoryId1, $quantity1));
     $expected->WithAccessory(new ReservationAccessory($accessoryId2, $quantity2));
     $expected->WithAttribute(new AttributeValue($attributeId1, $attributeValue1));
     $expected->WithAttribute(new AttributeValue($attributeId2, $attributeValue2));
     $expected->WithAttachment($fileId, 'doc');
     $expected->AllowParticipation($allowParticipation);
     $instance1 = new Reservation($expected, $duration->AddDays(10));
     $instance1->SetReferenceNumber('instance1');
     $instance1->SetReservationId(909);
     $instance1->WithInvitees($instance1Invitees);
     $instance1->WithParticipants($instance1Participants);
     $instance2 = new Reservation($expected, $duration->AddDays(20));
     $instance2->SetReferenceNumber('instance2');
     $instance2->SetReservationId(1909);
     $instance2->WithInvitees($instance2Invitees);
     $instance2->WithParticipants($instance2Participants);
     $expected->WithInstance($instance1);
     $expected->WithInstance($instance2);
     $expectedInstance = new Reservation($expected, $duration);
     $expectedInstance->SetReferenceNumber($referenceNumber);
     $expectedInstance->SetReservationId($reservationId);
     $expected->WithCurrentInstance($expectedInstance);
     $expected->WithStartReminder(new ReservationReminder($startReminderMinutes, ReservationReminderInterval::Minutes));
     $expected->WithEndReminder(new ReservationReminder($endReminderMinutes / 60, ReservationReminderInterval::Hours));
     $reservationRow = new ReservationRow($reservationId, $begin, $end, $title, $description, $repeatType, $repeatOptions->ConfigurationString(), $referenceNumber, $seriesId, $ownerId, $statusId, $allowParticipation);
     $reservationInstanceRow = new ReservationInstanceRow($seriesId);
     $reservationInstanceRow->WithInstance($instance1->ReservationId(), $instance1->ReferenceNumber(), $instance1->Duration())->WithInstance($instance2->ReservationId(), $instance2->ReferenceNumber(), $instance2->Duration())->WithInstance($reservationId, $expectedInstance->ReferenceNumber(), $expectedInstance->Duration());
     $reservationResourceRow = new ReservationResourceRow($reservationId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, $scheduleId);
     $reservationResourceRow->WithPrimary($resourceId)->WithAdditional($resourceId1)->WithAdditional($resourceId2);
     $reservationUserRow = new ReservationUserRow();
     $reservationUserRow->WithParticipants($instance1, $instance1Participants)->WithParticipants($instance2, $instance2Participants)->WithInvitees($instance1, $instance1Invitees)->WithInvitees($instance2, $instance2Invitees);
     $reservationAccessoryRow = new ReservationAccessoryRow();
     $reservationAccessoryRow->WithAccessory($accessoryId1, $quantity1)->WithAccessory($accessoryId2, $quantity2);
     $attributeValueRow = new CustomAttributeValueRow();
     $attributeValueRow->With($attributeId1, $attributeValue1)->With($attributeId2, $attributeValue2);
     $attachmentRow = new ReservationAttachmentItemRow();
     $attachmentRow->With($fileId, $seriesId, null, 'doc');
     $reminderRow = new ReservationReminderRow();
     $reminderRow->With(1, $seriesId, $startReminderMinutes, ReservationReminderType::Start)->With(2, $seriesId, $endReminderMinutes, ReservationReminderType::End);
     $this->db->SetRow(0, $reservationRow->Rows());
     $this->db->SetRow(1, $reservationInstanceRow->Rows());
     $this->db->SetRow(2, $reservationResourceRow->Rows());
     $this->db->SetRow(3, $reservationUserRow->Rows());
     $this->db->SetRow(4, $reservationAccessoryRow->Rows());
     $this->db->SetRow(5, $attributeValueRow->Rows());
     $this->db->SetRow(6, $attachmentRow->Rows());
     $this->db->SetRow(7, $reminderRow->Rows());
     $actualReservation = $this->repository->LoadById($reservationId);
     $this->assertEquals($expected, $actualReservation);
     $getReservation = new GetReservationByIdCommand($reservationId);
     $getInstances = new GetReservationSeriesInstances($seriesId);
     $getResources = new GetReservationResourcesCommand($seriesId);
     $getParticipants = new GetReservationSeriesParticipantsCommand($seriesId);
     $getAccessories = new GetReservationAccessoriesCommand($seriesId);
     $getAttributeValues = new GetAttributeValuesCommand($seriesId, CustomAttributeCategory::RESERVATION);
     $getAttachments = new GetReservationAttachmentsCommand($seriesId);
     $getReminders = new GetReservationReminders($seriesId);
     $this->assertTrue($this->db->ContainsCommand($getReservation));
     $this->assertTrue($this->db->ContainsCommand($getInstances));
     $this->assertTrue($this->db->ContainsCommand($getResources));
     $this->assertTrue($this->db->ContainsCommand($getParticipants));
     $this->assertTrue($this->db->ContainsCommand($getAccessories));
     $this->assertTrue($this->db->ContainsCommand($getAttributeValues));
     $this->assertTrue($this->db->ContainsCommand($getAttachments));
     $this->assertTrue($this->db->ContainsCommand($getReminders));
 }