public function testReturnsAllBlackoutInstancesWithinDateRange()
 {
     $dateRange = new TestDateRange();
     $start = Date::Now();
     $end = Date::Now();
     $instanceId = 12;
     $seriesId = 222;
     $resourceId = 333;
     $userid = 444;
     $scheduleId = 555;
     $resourceName = 'resource 123';
     $firstName = 'f';
     $lastName = 'l';
     $title = 'title';
     $description = 'description';
     $repeatType = RepeatType::Daily;
     $repeat = new RepeatDaily(1, $end->AddDays(2));
     $repeatOptions = $repeat->ConfigurationString();
     $rows[] = $this->GetBlackoutRow($instanceId, $start, $end, $resourceId, $userid, $scheduleId, $title, $description, $firstName, $lastName, $resourceName, $seriesId, $repeatType, $repeatOptions);
     $rows[] = $this->GetBlackoutRow("1", Date::Now(), Date::Now());
     $this->db->SetRows($rows);
     $getBlackoutsCommand = new GetBlackoutListCommand($dateRange->GetBegin(), $dateRange->GetEnd(), ReservationViewRepository::ALL_SCHEDULES);
     $blackouts = $this->repository->GetBlackoutsWithin($dateRange);
     $b = new BlackoutItemView($instanceId, $start->ToUtc(), $end->ToUtc(), $resourceId, $userid, $scheduleId, $title, $description, $firstName, $lastName, $resourceName, $seriesId, $repeatOptions, $repeatType);
     $this->assertEquals($getBlackoutsCommand, $this->db->_LastCommand);
     $this->assertEquals(2, count($blackouts));
     $this->assertEquals($b, $blackouts[0]);
 }
 public function testDeletesWholeSeriesWhenAdminRegardlessOfDate()
 {
     $r1 = new TestReservation();
     $r1->SetReservationDate(TestDateRange::CreateWithDays(-1));
     $r2 = new TestReservation();
     $r2->SetReservationDate(TestDateRange::CreateWithDays(-2));
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithCurrentInstance($r1);
     $builder->WithInstance($r2);
     $series = $builder->Build();
     $series->ApplyChangesTo(SeriesUpdateScope::FullSeries);
     $series->Delete($this->admin);
     $events = $series->GetEvents();
     $this->assertEquals(1, count($events));
     $this->assertTrue(in_array(new SeriesDeletedEvent($series), $events));
 }
 public function testWithUpdatedInstances()
 {
     $seriesId = 3929;
     $dateRange = new TestDateRange();
     $instance1 = new TestReservation('323', $dateRange->AddDays(3));
     $instance2 = new TestReservation('423', $dateRange->AddDays(4));
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithEvent(new InstanceUpdatedEvent($instance1, $builder->series));
     $builder->WithEvent(new InstanceUpdatedEvent($instance2, $builder->series));
     $series = $builder->BuildTestVersion();
     $series->WithId($seriesId);
     $this->repository->Update($series);
     $updateReservationCommand1 = $this->GetUpdateReservationCommand($seriesId, $instance1);
     $updateReservationCommand2 = $this->GetUpdateReservationCommand($seriesId, $instance2);
     $commands = $this->db->GetCommandsOfType('UpdateReservationCommand');
     $this->assertEquals(2, count($commands));
     $this->assertTrue(in_array($updateReservationCommand1, $this->db->_Commands));
     $this->assertTrue(in_array($updateReservationCommand2, $this->db->_Commands));
 }
 public function testWhenApplyingSimpleUpdatesToFullSeries()
 {
     $currentResource = new FakeBookableResource(8);
     $newResource = new FakeBookableResource(10);
     $repeatOptions = new RepeatDaily(1, Date::Now());
     $dateRange = new TestDateRange();
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithPrimaryResource($currentResource);
     $builder->WithRepeatOptions($repeatOptions);
     $builder->WithInstance(new TestReservation('123', $dateRange));
     $builder->WithCurrentInstance(new TestReservation('1', $dateRange->AddDays(5)));
     $series = $builder->Build();
     $series->ApplyChangesTo(SeriesUpdateScope::FullSeries);
     $series->Repeats($repeatOptions);
     $series->Update($series->UserId(), $newResource, 'new', 'new', new FakeUserSession());
     $events = $series->GetEvents();
     $this->assertEquals($newResource, $series->Resource());
     $this->assertEquals(2, count($series->Instances()));
     $this->assertEquals(2, count($events));
     $this->assertTrue(in_array(new ResourceRemovedEvent($currentResource, $series), $events));
     $this->assertTrue(in_array(new ResourceAddedEvent($newResource, ResourceLevel::Primary, $series), $events));
 }