Example #1
0
        public async Task <List <OrganisationType> > Handle(GetOrganisationTypesRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Handling GetOrganisationsType Request");
            var result = await _registerQueryRepository.GetOrganisationTypes();

            return(result.ToList());
        }
        public async Task <IActionResult> OrganisationTypes(int providerTypeId)
        {
            var request = new GetOrganisationTypesRequest {
                ProviderTypeId = providerTypeId
            };

            return(Ok(await _mediator.Send(request)));
        }
        public void Handler_retrieves_list_of_organisations_by_provider_type(int providerTypeId)
        {
            var request = new GetOrganisationTypesRequest {
                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 GetOrganisationTypesRequest {
                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 GetOrganisationTypesRequest {
                ProviderTypeId = 1
            };

            _repository.Setup(x => x.GetOrganisationTypesForProviderTypeId(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 <OrganisationType> > Handle(GetOrganisationTypesRequest 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 Types lookup for Provider Type Id [{request.ProviderTypeId}]");

            try
            {
                return(await _repository.GetOrganisationTypesForProviderTypeId(request.ProviderTypeId));
            }
            catch (Exception ex)
            {
                _logger.LogError("Unable to retrieve Organisation Types", ex);
                throw new ApplicationException(ex.Message);
            }
        }