public async Task <GetReservationResult> Handle(GetReservationQuery request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request); if (!validationResult.IsValid()) { throw new ValidationException(validationResult.ConvertToDataAnnotationsValidationResult(), null, null); } var apiRequest = new ReservationApiRequest(_options.Url, request.Id); var result = await _apiClient.Get <GetReservationResponse>(apiRequest); if (request.UkPrn != default(uint) && !await _reservationAuthorisationService.ProviderReservationAccessAllowed(request.UkPrn, result)) { throw new UnauthorizedAccessException(); } return(new GetReservationResult { ReservationId = result.Id, StartDate = result.StartDate, ExpiryDate = result.ExpiryDate, Course = result.Course ?? new Course(null, null, 0), AccountLegalEntityId = result.AccountLegalEntityId, AccountLegalEntityName = result.AccountLegalEntityName, UkPrn = result.ProviderId }); }
public void Then_It_Sets_The_GetAllUrl( string url, long accountId) { var request = new ReservationApiRequest(url, accountId); request.GetAllUrl.Should().Be($"{url}api/accounts/{accountId}/reservations"); }
public void Then_It_Sets_The_GetUrl( string url, Guid expectedId) { var request = new ReservationApiRequest(url, expectedId); request.GetUrl.Should().Be($"{url}api/reservations/{expectedId}"); }
public void Then_It_Sets_The_DeleteUrl( string url, bool employerDeleted, Guid reservationId) { var request = new ReservationApiRequest(url, reservationId, employerDeleted); request.DeleteUrl.Should().Be($"{url}api/reservations/{reservationId}?employerDeleted={employerDeleted}"); }
public async Task <CreateReservationResult> Handle(CreateReservationCommand command, CancellationToken cancellationToken) { var queryValidationResult = await _createReservationValidator.ValidateAsync(command); if (!queryValidationResult.IsValid()) { throw new ValidationException(queryValidationResult.ConvertToDataAnnotationsValidationResult(), null, null); } CachedReservation cachedReservation; if (!command.UkPrn.HasValue) { cachedReservation = await _cachedReservationRepository.GetEmployerReservation(command.Id); } else { cachedReservation = await _cachedReservationRepository.GetProviderReservation(command.Id, command.UkPrn.Value); } if (cachedReservation == null) { throw new CachedReservationNotFoundException(command.Id); } var createValidationResult = await _cachedReservationValidator.ValidateAsync(cachedReservation); if (!createValidationResult.IsValid()) { throw new ValidationException(createValidationResult.ConvertToDataAnnotationsValidationResult(), null, null); } var apiRequest = new ReservationApiRequest( _apiOptions.Value.Url, cachedReservation.AccountId, cachedReservation.IsEmptyCohortFromSelect ? null : cachedReservation.UkPrn, new DateTime(cachedReservation.TrainingDate.StartDate.Year, cachedReservation.TrainingDate.StartDate.Month, 1), cachedReservation.Id, cachedReservation.AccountLegalEntityId, cachedReservation.AccountLegalEntityName, cachedReservation.CourseId, command.UserId); var response = await _apiClient.Create <CreateReservationResponse>(apiRequest); await _cacheStorageService.DeleteFromCache(command.Id.ToString()); return(new CreateReservationResult { Id = response.Id, AccountLegalEntityPublicHashedId = cachedReservation.AccountLegalEntityPublicHashedId, CohortRef = cachedReservation.CohortRef, IsEmptyCohortFromSelect = cachedReservation.IsEmptyCohortFromSelect, ProviderId = cachedReservation.UkPrn, JourneyData = cachedReservation.JourneyData }); }
public void Then_It_Sets_Values() { var startDate = DateTime.Now.AddDays(-10); var courseId = "1-2-3"; var userId = Guid.NewGuid(); var request = new ReservationApiRequest("test", 1, 2, startDate, Guid.NewGuid(), 1, "Test Name", courseId, userId); request.StartDate.Should().Be(startDate.ToString("yyyy-MMM-dd")); request.CourseId.Should().Be(courseId); request.UserId.Should().Be(userId); }
public async Task <Unit> Handle(DeleteReservationCommand command, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(command); if (!validationResult.IsValid()) { throw new ValidationException( validationResult.ConvertToDataAnnotationsValidationResult(), null, null); } var apiRequest = new ReservationApiRequest(_apiOptions.Value.Url, command.ReservationId, command.DeletedByEmployer); await _apiClient.Delete(apiRequest); return(Unit.Value); }
public async Task Then_Sends_Delete_Request_To_Reservations_Api( DeleteReservationCommand command, [Frozen] Mock <IValidator <DeleteReservationCommand> > mockValidator, [Frozen] Mock <IApiClient> mockApiClient, [Frozen] Mock <IOptions <ReservationsApiConfiguration> > mockOptions, DeleteReservationCommandHandler handler) { var expectedApiRequest = new ReservationApiRequest(mockOptions.Object.Value.Url, command.ReservationId, command.DeletedByEmployer); mockValidator .Setup(validator => validator.ValidateAsync(command)) .ReturnsAsync(new ValidationResult()); await handler.Handle(command, CancellationToken.None); mockApiClient .Verify(client => client.Delete( It.Is <IDeleteApiRequest>(request => request.DeleteUrl == expectedApiRequest.DeleteUrl)), Times.Once); }
public void Then_It_Sets_CreateUrl( [Frozen] string url, ReservationApiRequest request) { request.CreateUrl.Should().Be($"{url}api/accounts/{request.AccountId}/reservations"); }
public void Then_It_Sets_Id( [Frozen] Guid id, ReservationApiRequest request) { request.Id.Should().Be(id); }