public function testLoadsExistingReservationAndUpdatesData()
 {
     $seriesId = 109809;
     $expectedSeries = new ExistingReservationSeries();
     $currentDuration = new DateRange(Date::Now()->AddDays(1), Date::Now()->AddDays(2), 'UTC');
     $removedResourceId = 190;
     $resource = new FakeBookableResource(1);
     $additionalId1 = $this->page->resourceIds[0];
     $additionalId2 = $this->page->resourceIds[1];
     $additional1 = new FakeBookableResource($additionalId1);
     $additional2 = new FakeBookableResource($additionalId2);
     $reservation = new Reservation($expectedSeries, $currentDuration);
     $expectedSeries->WithId($seriesId);
     $expectedSeries->WithCurrentInstance($reservation);
     $expectedSeries->WithPrimaryResource($resource);
     $expectedSeries->WithResource(new FakeBookableResource($removedResourceId));
     $expectedSeries->WithAttribute(new AttributeValue(100, 'to be removed'));
     $referenceNumber = $this->page->existingReferenceNumber;
     $timezone = $this->user->Timezone;
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->page->resourceId))->will($this->returnValue($resource));
     $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalId1))->will($this->returnValue($additional1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalId2))->will($this->returnValue($additional2));
     $this->page->repeatType = RepeatType::Daily;
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->page, $this->user->Timezone);
     $expectedDuration = DateRange::Create($this->page->GetStartDate() . " " . $this->page->GetStartTime(), $this->page->GetEndDate() . " " . $this->page->GetEndTime(), $timezone);
     $attachment = new FakeUploadedFile();
     $this->page->attachment = $attachment;
     $this->page->hasEndReminder = false;
     $existingSeries = $this->presenter->BuildReservation();
     $expectedAccessories = array(new ReservationAccessory(1, 2, 'accessoryname'));
     $expectedAttributes = array(1 => new AttributeValue(1, 'something'));
     $this->assertEquals($seriesId, $existingSeries->SeriesId());
     $this->assertEquals($this->page->seriesUpdateScope, $existingSeries->SeriesUpdateScope());
     $this->assertEquals($this->page->title, $existingSeries->Title());
     $this->assertEquals($this->page->description, $existingSeries->Description());
     $this->assertEquals($this->page->userId, $existingSeries->UserId());
     $this->assertEquals($resource, $existingSeries->Resource());
     $this->assertEquals($repeatOptions, $existingSeries->RepeatOptions());
     $this->assertEquals(array($additional1, $additional2), $existingSeries->AdditionalResources());
     $this->assertEquals($this->page->participants, $existingSeries->CurrentInstance()->AddedParticipants());
     $this->assertEquals($this->page->invitees, $existingSeries->CurrentInstance()->AddedInvitees());
     $this->assertTrue($expectedDuration->Equals($existingSeries->CurrentInstance()->Duration()), "Expected: {$expectedDuration} Actual: {$existingSeries->CurrentInstance()->Duration()}");
     $this->assertEquals($this->user, $expectedSeries->BookedBy());
     $this->assertEquals($expectedAccessories, $existingSeries->Accessories());
     $this->assertEquals($expectedAttributes, $existingSeries->AttributeValues());
     $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $seriesId);
     $this->assertEquals(array($expectedAttachment), $expectedSeries->AddedAttachments());
     $this->assertEquals($this->page->removedFileIds, $existingSeries->RemovedAttachmentIds());
     $this->assertEquals(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()), $existingSeries->GetStartReminder());
     $this->assertEquals(ReservationReminder::None(), $existingSeries->GetEndReminder());
 }
 /**
  * @return ExistingReservationSeries
  */
 public function Build()
 {
     $this->series->WithId($this->id);
     $this->series->WithCurrentInstance($this->currentInstance);
     $this->series->WithRepeatOptions($this->repeatOptions);
     foreach ($this->instances as $reservation) {
         $this->series->WithInstance($reservation);
     }
     foreach ($this->events as $event) {
         $this->series->AddEvent($event);
     }
     $this->series->WithPrimaryResource($this->resource);
     $this->series->Update(1, $this->resource, 'title', 'description', $this->bookedBy);
     return $this->series;
 }
 /**
  * @param IReader $reader
  * @return ExistingReservationSeries
  */
 private function BuildSeries($reader)
 {
     $series = new ExistingReservationSeries();
     if ($row = $reader->GetRow()) {
         $repeatType = $row[ColumnNames::REPEAT_TYPE];
         $configurationString = $row[ColumnNames::REPEAT_OPTIONS];
         $repeatOptions = $this->BuildRepeatOptions($repeatType, $configurationString);
         $series->WithRepeatOptions($repeatOptions);
         $seriesId = $row[ColumnNames::SERIES_ID];
         $title = $row[ColumnNames::RESERVATION_TITLE];
         $description = $row[ColumnNames::RESERVATION_DESCRIPTION];
         $series->WithId($seriesId);
         $series->WithTitle($title);
         $series->WithDescription($description);
         $series->WithOwner($row[ColumnNames::RESERVATION_OWNER]);
         $series->WithStatus($row[ColumnNames::RESERVATION_STATUS]);
         $series->AllowParticipation($row[ColumnNames::RESERVATION_ALLOW_PARTICIPATION]);
         $startDate = Date::FromDatabase($row[ColumnNames::RESERVATION_START]);
         $endDate = Date::FromDatabase($row[ColumnNames::RESERVATION_END]);
         $duration = new DateRange($startDate, $endDate);
         $instance = new Reservation($series, $duration, $row[ColumnNames::RESERVATION_INSTANCE_ID], $row[ColumnNames::REFERENCE_NUMBER]);
         $series->WithCurrentInstance($instance);
     }
     $reader->Free();
     return $series;
 }
 public function testDeleteSeries()
 {
     $seriesId = 981;
     $eventSeries = new ExistingReservationSeries();
     $eventSeries->WithId($seriesId);
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithEvent(new SeriesDeletedEvent($eventSeries));
     $series = $builder->BuildTestVersion();
     $series->WithId($seriesId);
     $this->repository->Delete($series);
     $deleteSeriesCommand = new DeleteSeriesCommand($eventSeries->SeriesId(), Date::Now());
     $this->assertEquals(1, count($this->db->_Commands));
     $this->assertTrue(in_array($deleteSeriesCommand, $this->db->_Commands));
 }