public function testConfigurationStringCanBeDeserialized() { $terminationDate = Date::Parse('2010-12-12 01:06:07', 'UTC'); $dateString = $terminationDate->ToDatabase(); $interval = 10; // none $config = RepeatConfiguration::Create(RepeatType::None, ''); $this->assertEquals(RepeatType::None, $config->Type); // daily $daily = new RepeatDaily($interval, $terminationDate); $config = RepeatConfiguration::Create($daily->RepeatType(), $daily->ConfigurationString()); $this->assertEquals(RepeatType::Daily, $config->Type); $this->assertEquals(10, $config->Interval); $this->assertEquals($terminationDate, $config->TerminationDate); // weekly $weekdays = array(1, 3, 4, 5); $weekly = new RepeatWeekly($interval, $terminationDate, $weekdays); $config = RepeatConfiguration::Create($weekly->RepeatType(), $weekly->ConfigurationString()); $this->assertEquals(RepeatType::Weekly, $config->Type); $this->assertEquals($terminationDate, $config->TerminationDate); $this->assertEquals($weekdays, $config->Weekdays); // day of month $dayOfMonth = new RepeatDayOfMonth($interval, $terminationDate); $config = RepeatConfiguration::Create($dayOfMonth->RepeatType(), $dayOfMonth->ConfigurationString()); $this->assertEquals(RepeatType::Monthly, $config->Type); $this->assertEquals($terminationDate, $config->TerminationDate); $this->assertEquals(RepeatMonthlyType::DayOfMonth, $config->MonthlyType); // weekday of month $weekOfMonth = new RepeatWeekDayOfMonth($interval, $terminationDate); $config = RepeatConfiguration::Create($weekOfMonth->RepeatType(), $weekOfMonth->ConfigurationString()); $this->assertEquals(RepeatType::Monthly, $config->Type); $this->assertEquals($terminationDate, $config->TerminationDate); $this->assertEquals(RepeatMonthlyType::DayOfWeek, $config->MonthlyType); // yearly $yearly = new RepeatYearly($interval, $terminationDate); $config = RepeatConfiguration::Create($yearly->RepeatType(), $yearly->ConfigurationString()); $this->assertEquals(RepeatType::Yearly, $config->Type); $this->assertEquals(10, $config->Interval); $this->assertEquals($terminationDate, $config->TerminationDate); }
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 testLoadsBlackoutSeriesByBlackoutId() { $id = 19191; $seriesId = 110101; $ownerId = 919199; $title = 'title'; $description = 'description'; $tz = 'UTC'; $repeatType = RepeatType::Daily; $repeatDaily = new RepeatDaily(1, Date::Parse('2013-04-15', $tz)); $b1Start = Date::Parse('2013-04-14 12:30:00', $tz); $b1End = Date::Parse('2013-04-14 13:30:00', $tz); $series = new BlackoutSeriesRow(); $series->With($seriesId, $ownerId, $title, $repeatType, $repeatDaily->ConfigurationString(), $b1Start, $b1End); $instances = new BlackoutInstanceRow(); $instances->With($seriesId, 1, $b1Start->ToDatabase(), $b1End->ToDatabase()); $instances->With($seriesId, 2, Date::Parse('2013-04-15 12:30:00', $tz)->ToDatabase(), Date::Parse('2013-04-15 13:30:00', $tz)->ToDatabase()); $resources = new BlackoutResourceRow(); $resources->With(1, 'r1', 2, 3, 4); $resources->With(2, 'r2', 4); $this->db->SetRow(0, $series->Rows()); $this->db->SetRow(1, $instances->Rows()); $this->db->SetRow(2, $resources->Rows()); $loadBlackoutCommand = new GetBlackoutSeriesByBlackoutIdCommand($id); $loadBlackoutInstancesCommand = new GetBlackoutInstancesCommand($seriesId); $loadBlackoutResourcesCommand = new GetBlackoutResourcesCommand($seriesId); $series = $this->repository->LoadByBlackoutId($id); $this->assertEquals($loadBlackoutCommand, $this->db->_Commands[0]); $this->assertTrue($this->db->ContainsCommand($loadBlackoutInstancesCommand)); $this->assertTrue($this->db->ContainsCommand($loadBlackoutResourcesCommand)); $this->assertEquals($seriesId, $series->Id()); $this->assertEquals($ownerId, $series->OwnerId()); $this->assertEquals($title, $series->Title()); $this->assertEquals($repeatType, $series->RepeatType()); $this->assertEquals($repeatDaily->ConfigurationString(), $series->RepeatConfigurationString()); $this->assertEquals(2, count($series->AllBlackouts())); $instances = $series->AllBlackouts(); $this->assertEquals($b1Start, $instances[0]->StartDate()); $this->assertEquals($b1End, $instances[0]->EndDate()); $this->assertEquals(count($resources->Rows()), count($series->Resources())); $this->assertEquals($b1Start, $series->CurrentBlackout()->StartDate()); }