public async Task <GetVolunteersByPostcodeAndActivityResponse> GetVolunteersByPostcodeAndActivity(string postcode, List <SupportActivities> activities, double?shiftRadius, CancellationToken cancellationToken)
        {
            string path = $"api/GetVolunteersByPostcodeAndActivity";
            GetVolunteersByPostcodeAndActivityRequest request = new GetVolunteersByPostcodeAndActivityRequest
            {
                VolunteerFilter = new VolunteerFilter
                {
                    Postcode   = postcode,
                    Activities = activities,
                    OverrideVolunteerRadius = shiftRadius
                }
            };

            using (HttpResponseMessage response = await _httpClientWrapper.GetAsync(HttpClientConfigName.UserService, path, request, cancellationToken).ConfigureAwait(false))
            {
                string jsonResponse = await response.Content.ReadAsStringAsync();

                var helperResponse = JsonConvert.DeserializeObject <ResponseWrapper <GetVolunteersByPostcodeAndActivityResponse, UserServiceErrorCode> >(jsonResponse);

                if (helperResponse.HasContent && helperResponse.IsSuccessful)
                {
                    return(helperResponse.Content);
                }
                else
                {
                    throw new System.Exception(helperResponse.Errors.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public async Task WhenIGetHelper_WithNoStreetChampionButWithLinkedActivity_IGetOneUserReturened()
        {
            GetVolunteersByPostcodeAndActivityRequest request = new GetVolunteersByPostcodeAndActivityRequest()
            {
                VolunteerFilter = new VolunteerFilter
                {
                    Postcode   = "NG1 1AA",
                    Activities = new List <SupportActivities> {
                        SupportActivities.Shopping
                    }
                }
            };

            GetVolunteersByPostcodeAndActivityHandler getVolunteersByPostcodeAndActivityHandler = new GetVolunteersByPostcodeAndActivityHandler(_helperService.Object, _repository.Object);

            GetVolunteersByPostcodeAndActivityResponse result = await getVolunteersByPostcodeAndActivityHandler.Handle(request, CancellationToken.None);

            Assert.AreEqual(1, result.Volunteers.Count());
            _helperService.Verify(X => X.GetHelpersWithinRadius("NG1 1AA", It.IsAny <double?>(), It.IsAny <CancellationToken>()));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
            [RequestBodyType(typeof(GetVolunteersByPostcodeAndActivityRequest), "Get Volunteers By Postcode And Activity")] GetVolunteersByPostcodeAndActivityRequest req,
            ILogger log)
        {
            try
            {
                NewRelic.Api.Agent.NewRelic.SetTransactionName("UserService", "GetHelpersContactInformationByPostcode");
                log.LogInformation("C# HTTP trigger function processed a request.");

                GetVolunteersByPostcodeAndActivityResponse response = await _mediator.Send(req);

                return(new OkObjectResult(ResponseWrapper <GetVolunteersByPostcodeAndActivityResponse, UserServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                LogError.Log(log, exc, req);
                return(new ObjectResult(ResponseWrapper <GetVolunteersByPostcodeAndActivityResponse, UserServiceErrorCode> .CreateUnsuccessfulResponse(UserServiceErrorCode.UnhandledError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }