public function testScheduleResponseReturnsLayoutForEachDayOfWeek() { $schedule = new FakeSchedule(); $layout = $this->getMock('IScheduleLayout'); $timezone = $this->server->GetSession()->Timezone; $date1 = Date::Now()->ToTimezone($timezone); $date2 = $date1->AddDays(1); $date3 = $date1->AddDays(2); $date4 = $date1->AddDays(3); $date5 = $date1->AddDays(4); $date6 = $date1->AddDays(5); $date7 = $date1->AddDays(6); $periods1 = array(new SchedulePeriod($date1, $date1)); $periods2 = array(new SchedulePeriod($date2, $date2)); $periods3 = array(new SchedulePeriod($date3, $date3)); $periods4 = array(new SchedulePeriod($date4, $date4)); $periods5 = array(new SchedulePeriod($date5, $date5)); $periods6 = array(new SchedulePeriod($date6, $date6)); $periods7 = array(new SchedulePeriod($date7, $date7)); $layout->expects($this->at(0))->method('GetLayout')->with($this->equalTo($date1))->will($this->returnValue($periods1)); $layout->expects($this->at(1))->method('GetLayout')->with($this->equalTo($date2))->will($this->returnValue($periods2)); $layout->expects($this->at(2))->method('GetLayout')->with($this->equalTo($date3))->will($this->returnValue($periods3)); $layout->expects($this->at(3))->method('GetLayout')->with($this->equalTo($date4))->will($this->returnValue($periods4)); $layout->expects($this->at(4))->method('GetLayout')->with($this->equalTo($date5))->will($this->returnValue($periods5)); $layout->expects($this->at(5))->method('GetLayout')->with($this->equalTo($date6))->will($this->returnValue($periods6)); $layout->expects($this->at(6))->method('GetLayout')->with($this->equalTo($date7))->will($this->returnValue($periods7)); $response = new ScheduleResponse($this->server, $schedule, $layout); $this->assertEquals(array(new SchedulePeriodResponse($periods1[0])), $response->periods[$date1->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods2[0])), $response->periods[$date2->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods3[0])), $response->periods[$date3->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods4[0])), $response->periods[$date4->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods5[0])), $response->periods[$date5->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods6[0])), $response->periods[$date6->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods7[0])), $response->periods[$date7->Weekday()]); }
public function testSignsUserOut() { $userId = 'ddddd'; $sessionToken = 'sssss'; $request = new SignOutRequest($userId, $sessionToken); $this->server->SetRequest($request); $this->authentication->expects($this->once())->method('Logout')->with($this->equalTo($userId), $this->equalTo($sessionToken)); $this->service->SignOut($this->server); }
public function testWhenScheduleIdIsProvided() { $scheduleId = 12346; $this->server->SetQueryString(WebServiceQueryStringKeys::SCHEDULE_ID, $scheduleId); $this->reservationViewRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($this->defaultStartDate), $this->equalTo($this->defaultEndDate), $this->isNull(), $this->isNull(), $this->equalTo($scheduleId), $this->isNull())->will($this->returnValue(array())); $this->service->GetReservations(); }
public function testFailedDelete() { $userId = 123; $errors = array('error'); $controllerResult = new UserControllerResult(null, $errors); $this->controller->expects($this->once())->method('Delete')->with($this->equalTo($userId), $this->equalTo($this->server->GetSession()))->will($this->returnValue($controllerResult)); $this->service->Delete($userId); $this->assertEquals(new FailedResponse($this->server, $errors), $this->server->_LastResponse); $this->assertEquals(RestResponse::BAD_REQUEST_CODE, $this->server->_LastResponseCode); }
public function testWhenApproveValidationFails() { $referenceNumber = '123'; $errors = array('error'); $controllerResult = new ReservationControllerResult($referenceNumber); $controllerResult->SetErrors($errors); $this->controller->expects($this->once())->method('Approve')->with($this->equalTo($this->server->GetSession()), $this->equalTo($referenceNumber))->will($this->returnValue($controllerResult)); $this->service->Approve($referenceNumber); $expectedResponse = new FailedResponse($this->server, $errors); $this->assertEquals($expectedResponse, $this->server->_LastResponse); $this->assertEquals(RestResponse::BAD_REQUEST_CODE, $this->server->_LastResponseCode); }
public function testWhenNotHidingUserDetails() { $this->HideUsers(false); $userId = 999; $user = new FakeUser($userId); $attributes = $this->getMock('IEntityAttributeList'); $this->userRepositoryFactory->expects($this->once())->method('Create')->with($this->equalTo($this->server->GetSession()))->will($this->returnValue($this->userRepository)); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes)); $expectedResponse = new UserResponse($this->server, $user, $attributes); $this->service->GetUser($userId); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }
public function testGetsSingleResourceAvailabilityForARequestTime() { $date = Date::Parse('2014-01-01 04:30:00', 'America/Chicago'); $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso()); $resourceId1 = 1; $startTime = $date->AddHours(-1); $endTime = $date->AddHours(1); $resource = new FakeBookableResource($resourceId1); $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId1))->will($this->returnValue($resource)); $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1); $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1); $upcoming2 = new TestReservationItemView(3, $endTime->AddHours(3), $endTime->AddHours(4), $resourceId1); $upcoming3 = new TestReservationItemView(4, $endTime->AddHours(5), $endTime->AddHours(6), $resourceId1); $reservations = array($conflicting, $upcoming, $upcoming2, $upcoming3); $endDate = $date->AddDays(7); $this->reservationRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($date->AddDays(-1)->ToUtc()), $this->equalTo($endDate->ToUtc()), $this->isEmpty(), $this->isEmpty(), $this->isEmpty(), $this->equalTo($resourceId1))->will($this->returnValue($reservations)); $this->service->GetAvailability($resourceId1); $resources = array(new ResourceAvailabilityResponse($this->server, $resource, $conflicting, $upcoming, $endTime->AddHours(4), $endDate)); $this->assertEquals(new ResourcesAvailabilityResponse($this->server, $resources), $this->server->_LastResponse); }