Ejemplo n.º 1
0
    public async Task CalculateProviderLocationDistanceInMiles_Calculate_Distance_In_Miles_From_StudentPostcode_To_ProviderLocation_Using_Saved_Lat_Long(
        string studentPostcode,
        double studentLat,
        double studentLon,
        double providerLat,
        double providerLon,
        int expectedMileageInMilesAfterRounding)
    {
        var providerLocation = new ProviderLocation {
            Latitude = providerLat, Longitude = providerLon
        };
        var providerLocations = new List <ProviderLocation>
        {
            providerLocation
        };

        await _distanceCalculationService.CalculateProviderLocationDistanceInMiles(new PostcodeLocation
        {
            Postcode  = studentPostcode,
            Latitude  = studentLat,
            Longitude = studentLon
        }, providerLocations.AsQueryable());

        var roundedDistanceInMiles = (int)Math.Round(providerLocation.DistanceInMiles, MidpointRounding.AwayFromZero);

        roundedDistanceInMiles.Should().Be(expectedMileageInMilesAfterRounding);
    }
Ejemplo n.º 2
0
        public void Then_Maps_Feedback_Ratings_And_Attributes(ProviderLocation providerLocation)
        {
            var actual = GetProviderDetailResponse.Map(providerLocation);

            actual.FeedbackRatings.Count.Should().Be(providerLocation.FeedbackRating.Count);
            actual.FeedbackAttributes.Count.Should().Be(providerLocation.FeedbackAttributes.Count);
        }
Ejemplo n.º 3
0
        public static GetProviderDetailResponse Map(ProviderLocation provider, short age = 0)
        {
            var nationalAchievementRates = provider.AchievementRates.AsQueryable();

            if (age != 0)
            {
                nationalAchievementRates = nationalAchievementRates.Where(c => c.Age.Equals((Age)age));
            }

            return(new GetProviderDetailResponse
            {
                Ukprn = provider.Ukprn,
                Name = provider.Name,
                TradingName = provider.TradingName,
                MarketingInfo = provider.MarketingInfo,
                Email = provider.Email,
                ContactUrl = provider.ContactUrl,
                Phone = provider.Phone,
                StandardInfoUrl = provider.StandardInfoUrl,
                ProviderAddress = provider.Address,
                AchievementRates = nationalAchievementRates
                                   .Select(c => (GetNationalAchievementRateResponse)c).ToList(),
                DeliveryTypes = provider.DeliveryTypes.Select(c => (GetDeliveryTypesResponse)c).ToList(),
                FeedbackAttributes = provider.FeedbackAttributes.Select(x => (GetFeedbackAttributeResponse)x).ToList(),
                FeedbackRatings = provider.FeedbackRating.Select(x => (GetFeedbackRatingResponse)x).ToList(),
                ShortlistId = provider.ShortlistId
            });
        }
Ejemplo n.º 4
0
        public void Then_Only_All_Ages_Are_Returned(ProviderLocation provider)
        {
            //Arrange
            provider.AchievementRates = new List <AchievementRate>
            {
                new AchievementRate
                {
                    Age = Age.SixteenToEighteen,
                    ApprenticeshipLevel = ApprenticeshipLevel.AllLevels
                },
                new AchievementRate
                {
                    Age = Age.AllAges,
                    ApprenticeshipLevel = ApprenticeshipLevel.AllLevels
                },
                new AchievementRate
                {
                    Age = Age.AllAges,
                    ApprenticeshipLevel = ApprenticeshipLevel.Three
                }
            };

            //Act
            var actual = GetProviderDetailResponse.Map(provider, (short)Age.AllAges);

            //Assert
            actual.AchievementRates.Count.Should().Be(2);
        }
Ejemplo n.º 5
0
    public async Task CalculateProviderLocationDistanceInMiles_Calculate_Distance_In_Miles_From_StudentPostcode_To_ProviderLocation_Using_LocationApi(
        string studentPostcode,
        double studentLat,
        double studentLon,
        double providerLat,
        double providerLon,
        int expectedMileageInMilesAfterRounding)
    {
        var postcodeLookupResultDto = new PostcodeLookupResultDto {
            Postcode = studentPostcode, Latitude = studentLat, Longitude = studentLon
        };

        _locationApiClient.GetGeoLocationDataAsync(studentPostcode).Returns(postcodeLookupResultDto);

        var providerLocation = new ProviderLocation {
            Latitude = providerLat, Longitude = providerLon
        };
        var providerLocations = new List <ProviderLocation>
        {
            providerLocation
        };

        await _distanceCalculationService.CalculateProviderLocationDistanceInMiles(new PostcodeLocation { Postcode = studentPostcode }, providerLocations.AsQueryable());

        var roundedDistanceInMiles = (int)Math.Round(providerLocation.DistanceInMiles, MidpointRounding.AwayFromZero);

        roundedDistanceInMiles.Should().Be(expectedMileageInMilesAfterRounding);

        await _locationApiClient.Received(1).GetGeoLocationDataAsync(studentPostcode);
    }
Ejemplo n.º 6
0
        public void Then_The_Fields_Are_Correctly_Mapped(Provider source)
        {
            var actual = new ProviderLocation(source);

            actual.Name.Should().Be(source.Name);
            actual.TradingName.Should().Be(source.TradingName);
            actual.Ukprn.Should().Be(source.Ukprn);
            actual.AchievementRates.Should().NotBeEmpty();
            actual.DeliveryTypes.Should().BeEmpty();
        }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (ProviderLocation == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "ProviderLocation");
     }
     if (ProviderLocation != null)
     {
         ProviderLocation.Validate();
     }
 }
Ejemplo n.º 8
0
        public async Task Then_Gets_Providers_List_From_Mediator_Using_Params(
            int id,
            GetProvidersByStandardRequest request,
            ProviderLocation provider,
            ProviderLocation provider2,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] CoursesController controller)
        {
            request.Age = Age.AllAges;
            provider.AchievementRates.Clear();
            provider.AchievementRates.Add(new NationalAchievementRate
            {
                Age = Domain.Entities.Age.SixteenToEighteen,
                ApprenticeshipLevel = ApprenticeshipLevel.AllLevels
            });
            provider2.AchievementRates.Clear();
            provider2.AchievementRates.Add(new NationalAchievementRate
            {
                Age = Domain.Entities.Age.AllAges,
                ApprenticeshipLevel = ApprenticeshipLevel.AllLevels
            });

            var queryResult = new GetCourseProvidersQueryResponse
            {
                Providers = new List <ProviderLocation> {
                    provider, provider2
                }
            };

            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetCourseProvidersQuery>(query =>
                                                       query.StandardId == id &&
                                                       query.Lat.Equals(request.Lat) &&
                                                       query.Lon.Equals(request.Lon) &&
                                                       query.SortOrder.Equals((short)request.SortOrder) &&
                                                       query.SectorSubjectArea.Equals(request.SectorSubjectArea) &&
                                                       query.Level.Equals((short)request.Level) &&
                                                       query.ShortlistUserId.Equals(request.ShortlistUserId)
                                                       ),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(queryResult);

            var controllerResult = await controller.GetProvidersByStandardId(id, request) as ObjectResult;

            var model = controllerResult.Value as GetCourseProvidersListResponse;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            model.Providers.Count().Should().Be(queryResult.Providers.Count());
            model.Providers.Sum(c => c.AchievementRates.Count).Should().Be(1);
            model.TotalResults.Should().Be(queryResult.Providers.Count());
        }
Ejemplo n.º 9
0
        public string GetDirectionsLink(string fromPostcode, ProviderLocation toLocation)
        {
            //See https://developers.google.com/maps/documentation/urls/get-started#forming-the-directions-url

            var uriBuilder = new StringBuilder(BaseUrl);

            uriBuilder.Append($"origin={WebUtility.UrlEncode(fromPostcode)}");
            uriBuilder.Append($"&destination={WebUtility.UrlEncode(toLocation.Postcode)}");
            // ReSharper disable once StringLiteralTypo
            uriBuilder.Append("&travelmode=transit");

            return(uriBuilder.ToString());
        }
Ejemplo n.º 10
0
        public void Then_Maps_Fields(ProviderLocation provider)
        {
            var actual = GetProviderDetailResponse.Map(provider);

            actual.Ukprn.Should().Be(provider.Ukprn);
            actual.Name.Should().Be(provider.Name);
            actual.TradingName.Should().Be(provider.TradingName);
            actual.ProviderAddress.Should().BeEquivalentTo(provider.Address);
            actual.Email.Should().Be(provider.Email);
            actual.Phone.Should().Be(provider.Phone);
            actual.ContactUrl.Should().Be(provider.ContactUrl);
            actual.StandardInfoUrl.Should().Be(provider.StandardInfoUrl);
            actual.MarketingInfo.Should().Be(provider.MarketingInfo);
        }
Ejemplo n.º 11
0
        public void Then_The_Fields_Are_Correctly_Mapped(string name, int ukprn, string contactUrl,
                                                         string email,
                                                         string phone,
                                                         string tradingName,
                                                         string marketingInfo,
                                                         double providerDistanceInMiles,
                                                         string providerHeadOfficeAddress1,
                                                         string providerHeadOfficeAddress2,
                                                         string providerHeadOfficeAddress3,
                                                         string providerHeadOfficeAddress4,
                                                         string providerHeadOfficeAddressTown,
                                                         string providerHeadOfficeAddressPostcode,
                                                         string standardInfoUrl,
                                                         Guid?shortlistId,
                                                         List <ProviderWithStandardAndLocation> providerWithStandardAndLocations)
        {
            var actual = new ProviderLocation(ukprn, name, tradingName, contactUrl, phone, email, standardInfoUrl,
                                              providerDistanceInMiles,
                                              providerHeadOfficeAddress1,
                                              providerHeadOfficeAddress2,
                                              providerHeadOfficeAddress3,
                                              providerHeadOfficeAddress4,
                                              providerHeadOfficeAddressTown,
                                              providerHeadOfficeAddressPostcode,
                                              shortlistId,
                                              marketingInfo,
                                              providerWithStandardAndLocations);

            actual.Name.Should().Be(name);
            actual.TradingName.Should().Be(tradingName);
            actual.Ukprn.Should().Be(ukprn);
            actual.ContactUrl.Should().Be(contactUrl);
            actual.Email.Should().Be(email);
            actual.Phone.Should().Be(phone);
            actual.ShortlistId.Should().Be(shortlistId);
            actual.AchievementRates.Should().NotBeEmpty();
            actual.DeliveryTypes.Should().NotBeEmpty();
            actual.Address.Address1.Should().Be(providerHeadOfficeAddress1);
            actual.Address.Address2.Should().Be(providerHeadOfficeAddress2);
            actual.Address.Address3.Should().Be(providerHeadOfficeAddress3);
            actual.Address.Address4.Should().Be(providerHeadOfficeAddress4);
            actual.Address.Town.Should().Be(providerHeadOfficeAddressTown);
            actual.Address.Postcode.Should().Be(providerHeadOfficeAddressPostcode);
            actual.Address.DistanceInMiles.Should().Be(providerDistanceInMiles);
            actual.StandardInfoUrl.Should().Be(standardInfoUrl);
            actual.MarketingInfo.Should().Be(marketingInfo);
            actual.DeliveryTypes.ToList().Count.Should().Be(providerWithStandardAndLocations.Count);
        }
Ejemplo n.º 12
0
        public async Task Then_Gets_Shortlist_From_The_Services(
            GetShortlistForUserQuery query,
            List <Domain.Models.Shortlist> shortlistFromService,
            ProviderLocation providerLocationFromService,
            [Frozen] Mock <IShortlistService> mockShortlistService,
            GetShortlistForUserQueryHandler handler)
        {
            //Arrange
            mockShortlistService
            .Setup(x => x.GetAllForUserWithProviders(query.UserId))
            .ReturnsAsync(shortlistFromService);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.Shortlist.Should().BeEquivalentTo(shortlistFromService);
        }
Ejemplo n.º 13
0
        public async Task Then_Gets_Provider_From_The_Service_By_Ukprn_And_StandardId_And_Passes_Empty_Guid_If_No_Shortlist_UserId(
            string sectorSubjectArea,
            GetCourseProviderQuery query,
            ProviderLocation providerStandard,
            [Frozen] Mock <IProviderService> providerService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            query.ShortlistUserId             = null;
            providerStandard.AchievementRates = null;
            providerService.Setup(x => x.GetProviderByUkprnAndStandard(query.Ukprn, query.StandardId, query.Lat, query.Lon, query.SectorSubjectArea, Guid.Empty)).ReturnsAsync(providerStandard);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.ProviderStandardLocation.Should().BeEquivalentTo(providerStandard);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (AggregationLevel == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "AggregationLevel");
     }
     if (ProviderLocation == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "ProviderLocation");
     }
     if (ReachabilityReport == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "ReachabilityReport");
     }
     if (ProviderLocation != null)
     {
         ProviderLocation.Validate();
     }
 }
Ejemplo n.º 15
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 10, Configuration.FieldSeparator),
                       Id,
                       ProviderRole != null ? string.Join(Configuration.FieldRepeatSeparator, ProviderRole.Select(x => x.ToDelimitedString())) : null,
                       ProviderName != null ? string.Join(Configuration.FieldRepeatSeparator, ProviderName.Select(x => x.ToDelimitedString())) : null,
                       ProviderAddress != null ? string.Join(Configuration.FieldRepeatSeparator, ProviderAddress.Select(x => x.ToDelimitedString())) : null,
                       ProviderLocation?.ToDelimitedString(),
                       ProviderCommunicationInformation != null ? string.Join(Configuration.FieldRepeatSeparator, ProviderCommunicationInformation.Select(x => x.ToDelimitedString())) : null,
                       PreferredMethodOfContact?.ToDelimitedString(),
                       ProviderIdentifiers != null ? string.Join(Configuration.FieldRepeatSeparator, ProviderIdentifiers.Select(x => x.ToDelimitedString())) : null,
                       EffectiveStartDateOfProviderRole.HasValue ? EffectiveStartDateOfProviderRole.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       EffectiveEndDateOfProviderRole.HasValue ? EffectiveEndDateOfProviderRole.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Ejemplo n.º 16
0
        public async Task Then_Gets_Provider_From_The_Service_By_Ukprn_And_StandardId(
            string sectorSubjectArea,
            GetCourseProviderQuery query,
            ProviderLocation providerStandard,
            [Frozen] Mock <IProviderService> providerService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            providerStandard.AchievementRates = providerStandard.AchievementRates.Select(c =>
            {
                c.SectorSubjectArea = sectorSubjectArea;
                return(c);
            }).ToList();
            providerService.Setup(x => x.GetProviderByUkprnAndStandard(query.Ukprn, query.StandardId, query.Lat, query.Lon, query.SectorSubjectArea, query.ShortlistUserId.Value)).ReturnsAsync(providerStandard);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.ProviderStandardLocation.Should().BeEquivalentTo(providerStandard);
        }
Ejemplo n.º 17
0
 public string GetDirectionsLink(string fromPostcode, ProviderLocation toLocation)
 {
     //See https://developers.google.com/maps/documentation/urls/get-started#forming-the-directions-url
     return($"{BaseUrl}origin={WebUtility.UrlEncode(fromPostcode)}&destination={WebUtility.UrlEncode(toLocation.Postcode)}&travelmode=transit");
 }
Ejemplo n.º 18
0
        public void Then_The_Delivery_Modes_Are_Mapped_If_Available(ProviderLocation providerLocation)
        {
            var actual = GetProviderDetailResponse.Map(providerLocation);

            actual.DeliveryTypes.Count.Should().Be(providerLocation.DeliveryTypes.Count);
        }