Esempio n. 1
0
        public async Task <IEnumerable <OrganisationType> > Handle(GetOrganisationTypesByCategoryRequest request, CancellationToken cancellationToken)
        {
            if (!_providerTypeValidator.IsValidProviderTypeId(request.ProviderTypeId))
            {
                string invalidProviderTypeError = $@"Invalid Provider Type Id [{request.ProviderTypeId}]";
                _logger.LogInformation(invalidProviderTypeError);
                throw new BadRequestException(invalidProviderTypeError);
            }

            if (!_categoryValidator.IsValidCategoryId(request.CategoryId))
            {
                string invalidMessage = $@"Invalid Category Id [{request.CategoryId}]";
                _logger.LogInformation(invalidMessage);
                throw new BadRequestException(invalidMessage);
            }

            _logger.LogInformation($@"Handling Organisation Types for a category lookup for Provider Type Id [{request.ProviderTypeId}], Category Id [{request.CategoryId}]");

            try
            {
                return(await _repository.GetOrganisationTypesForProviderTypeIdCategoryId(request.ProviderTypeId, request.CategoryId));
            }
            catch (Exception ex)
            {
                _logger.LogError("Unable to retrieve Organisation Types for a category lookup for Provider Type Id [{request.ProviderTypeId}], Category Id [{request.CategoryId}]", ex);
                throw new ApplicationException(ex.Message);
            }
        }
        public async Task <IActionResult> OrganisationTypesByCategory(int providerTypeId, int categoryId)
        {
            var request = new GetOrganisationTypesByCategoryRequest {
                ProviderTypeId = providerTypeId, CategoryId = categoryId
            };

            return(Ok(await _mediator.Send(request)));
        }
        public void Handler_returns_bad_request_for_invalid_provider_type(int providerTypeId)
        {
            var request = new GetOrganisationTypesByCategoryRequest {
                ProviderTypeId = providerTypeId, CategoryId = 1
            };

            Func <Task> result = async() => await
                                 _handler.Handle(request, new CancellationToken());

            result.Should().Throw <BadRequestException>();
        }
        public void Handler_retrieves_list_of_organisations_by_provider_type(int providerTypeId, int categoryId)
        {
            _repository.Setup((x => x.GetValidOrganisationCategoryIds())).ReturnsAsync(new List <int> {
                categoryId
            });
            var request = new GetOrganisationTypesByCategoryRequest {
                ProviderTypeId = providerTypeId, CategoryId = categoryId
            };

            var result = _handler.Handle(request, new CancellationToken()).Result;

            result.Should().NotBeNullOrEmpty();
        }
        public void Handler_returns_server_error_for_repository_exception()
        {
            var request = new GetOrganisationTypesByCategoryRequest {
                ProviderTypeId = 1
            };

            _repository.Setup(x => x.GetOrganisationTypesForProviderTypeIdCategoryId(It.IsAny <int>(), It.IsAny <int>()))
            .Throws(new Exception("Unit test exception"));

            Func <Task> result = async() => await
                                 _handler.Handle(request, new CancellationToken());

            result.Should().Throw <BadRequestException>();
        }