Exemple #1
0
        public async Task WhenICall_WithHappyPath_ICallRequiredFunctions()
        {
            var users = await _helperService.GetHelpersWithinRadius("T35T 3TY", It.IsAny <double?>(), new CancellationToken());

            _repository.Verify(x => x.GetLatitudeAndLongitude("T35T 3TY"), Times.Once);
            _volunteerCache.Verify(x => x.GetCachedVolunteersAsync(VolunteerType.Helper | VolunteerType.StreetChampion, It.IsAny <CancellationToken>()), Times.Once);
            _distanceCalculator.Verify(x => x.GetDistanceInMiles(1, 2, 1, 2), Times.Once);
            _distanceCalculator.Verify(x => x.GetDistanceInMiles(1, 2, 3, 4), Times.Once);
            _repository.Verify(x => x.GetVolunteersByIdsAsync(new List <int> {
                1, 2
            }), Times.Once);
        }
        public async Task <GetHelpersByPostcodeResponse> Handle(GetHelpersByPostcodeRequest request, CancellationToken cancellationToken)
        {
            request.Postcode = PostcodeFormatter.FormatPostcode(request.Postcode);

            var helpers = await _helperService.GetHelpersWithinRadius(request.Postcode, null, cancellationToken);

            GetHelpersByPostcodeResponse response = new GetHelpersByPostcodeResponse()
            {
                Users = helpers.Select(x => x.User).ToList()
            };

            return(response);
        }
Exemple #3
0
        public async Task <GetVolunteersByPostcodeAndActivityResponse> Handle(GetVolunteersByPostcodeAndActivityRequest request, CancellationToken cancellationToken)
        {
            request.VolunteerFilter.Postcode = PostcodeFormatter.FormatPostcode(request.VolunteerFilter.Postcode);

            var users = await _helperService.GetHelpersWithinRadius(request.VolunteerFilter.Postcode, request.VolunteerFilter.OverrideVolunteerRadius, cancellationToken);

            GetVolunteersByPostcodeAndActivityResponse response = new GetVolunteersByPostcodeAndActivityResponse
            {
                Volunteers = users.Where(x => x.User.SupportActivities.Any(sa => request.VolunteerFilter.Activities.Any(ra => sa == ra)))
                             .Select(x => new VolunteerSummary
                {
                    UserID          = x.User.ID,
                    DistanceInMiles = x.Distance
                }).ToList()
            };

            return(response);
        }