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)); }