public async Task <IActionResult> OrganisationCategories(int providerTypeId) { var request = new GetOrganisationCategoriesRequest { ProviderTypeId = providerTypeId }; return(Ok(await _mediator.Send(request))); }
public void Handler_retrieves_list_of_organisations_by_provider_type(int providerTypeId) { var request = new GetOrganisationCategoriesRequest { ProviderTypeId = providerTypeId }; var result = _handler.Handle(request, new CancellationToken()).Result; result.Should().NotBeNullOrEmpty(); }
public void Handler_returns_bad_request_for_invalid_provider_type(int providerTypeId) { var request = new GetOrganisationCategoriesRequest { ProviderTypeId = providerTypeId }; Func <Task> result = async() => await _handler.Handle(request, new CancellationToken()); result.Should().Throw <BadRequestException>(); }
public void Handler_returns_server_error_for_repository_exception() { var request = new GetOrganisationCategoriesRequest { ProviderTypeId = 1 }; _repository.Setup(x => x.GetOrganisationCategories(It.IsAny <int>())) .Throws(new Exception("Unit test exception")); Func <Task> result = async() => await _handler.Handle(request, new CancellationToken()); result.Should().Throw <ApplicationException>(); }
public async Task <IEnumerable <OrganisationCategory> > Handle(GetOrganisationCategoriesRequest request, CancellationToken cancellationToken) { if (!_providerTypeValidator.IsValidProviderTypeId(request.ProviderTypeId)) { string invalidProviderTypeError = $@"Invalid Provider Type Id [{request.ProviderTypeId}]"; _logger.LogInformation(invalidProviderTypeError); throw new BadRequestException(invalidProviderTypeError); } _logger.LogInformation($@"Handling Organisation Categories lookup for Provider Type Id [{request.ProviderTypeId}]"); try { return(await _repository.GetOrganisationCategories(request.ProviderTypeId)); } catch (Exception ex) { _logger.LogError($@"Unable to retrieve Organisation Categories for Provider Type Id [{request.ProviderTypeId}]", ex); throw new ApplicationException(ex.Message); } }