public When_Proximity_BackFillEmployerPostTown_Function_Fires() { _opportunityItemRepository = Substitute.For <IRepository <OpportunityItem> >(); _opportunityItemRepository.GetManyAsync(Arg.Any <Expression <Func <OpportunityItem, bool> > >()) .Returns(new List <OpportunityItem> { new OpportunityItem { Postcode = "CV1 2WT", Town = null } }.AsQueryable()); var providerVenueRepository = Substitute.For <IRepository <ProviderVenue> >(); _functionLogRepository = Substitute.For <IRepository <FunctionLog> >(); _googleMapsApiClient = Substitute.For <IGoogleMapApiClient>(); _googleMapsApiClient.GetAddressDetailsAsync("CV1 2WT").Returns("Coventry"); _locationApiClient = Substitute.For <ILocationApiClient>(); _locationApiClient.IsValidPostcodeAsync(Arg.Any <string>(), Arg.Any <bool>()).Returns((true, "CV1 2WT")); var proximityFunctions = new Functions.Proximity( _locationApiClient, _googleMapsApiClient, _opportunityItemRepository, providerVenueRepository, _functionLogRepository); proximityFunctions.BackFillEmployerPostTownAsync( new TimerInfo(new ConstantSchedule(TimeSpan.Zero), null), new ExecutionContext(), new NullLogger <Functions.Proximity>() ).GetAwaiter().GetResult(); }
public When_ProviderVenueService_Is_Called_To_Update_Venue() { var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); httpContextAccessor.HttpContext.Returns(new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, "TestUser") })) }); var dateTimeProvider = Substitute.For <IDateTimeProvider>(); dateTimeProvider.UtcNow().Returns(new DateTime(2019, 1, 1)); _locationApiClient = Substitute.For <ILocationApiClient>(); _locationApiClient.IsValidPostcodeAsync(Arg.Any <string>(), Arg.Any <bool>()) .Returns(callinfo => callinfo.Arg <string>() == "CV1 2WT" ? (true, "CV1 2WT") : (false, null)); var config = new MapperConfiguration(c => { c.AddMaps(typeof(ProviderVenueMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserEmailResolver") ? new LoggedInUserEmailResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) : type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(dateTimeProvider) : type.Name.Contains("VenueNameResolver") ? (object)new VenueNameResolver(_locationApiClient) : null); }); var mapper = new Mapper(config); _providerVenueRepository = Substitute.For <IProviderVenueRepository>(); _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >()) .Returns(new ValidProviderVenueBuilder().Build()); var googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); var locationService = Substitute.For <ILocationApiClient>(); var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient); var viewModel = new ProviderVenueDetailViewModel { Id = 1, Postcode = "CV1 2WT", Name = "Test provider venue", IsEnabledForReferral = true }; providerVenueService.UpdateVenueAsync(viewModel).GetAwaiter().GetResult(); }
public ProviderVenueService(IMapper mapper, IProviderVenueRepository providerVenueRepository, ILocationApiClient locationApiClient, IGoogleMapApiClient googleMapApiClient) { _mapper = mapper; _locationApiClient = locationApiClient; _googleMapApiClient = googleMapApiClient; _providerVenueRepository = providerVenueRepository; }
public DistanceCalculationService( ILocationApiClient locationApiClient, IDateTimeService dateTimeService, IMemoryCache cache, ConfigurationOptions configuration, ILogger <DistanceCalculationService> logger) { _locationApiClient = locationApiClient ?? throw new ArgumentNullException(nameof(locationApiClient)); _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService)); _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _cacheExpiryInSeconds = configuration?.PostcodeCacheExpiryInSeconds ?? 60; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public Proximity( ILocationApiClient locationApiClient, IGoogleMapApiClient googleMapApiClient, IRepository <OpportunityItem> opportunityItemRepository, IRepository <ProviderVenue> providerVenueRepository, IRepository <FunctionLog> functionLogRepository) { _googleMapApiClient = googleMapApiClient; _locationApiClient = locationApiClient; _opportunityItemRepository = opportunityItemRepository; _providerVenueRepository = providerVenueRepository; _functionLogRepository = functionLogRepository; }
public When_Proximity_BackFillProximityData_Function_Fires() { var opportunityItemRepository = Substitute.For <IRepository <OpportunityItem> >(); _providerVenueRepository = Substitute.For <IRepository <ProviderVenue> >(); var mockProviderVenueDbSet = new List <ProviderVenue> { new ProviderVenue { Postcode = "CV1 2WT", Town = null } } .AsQueryable() .BuildMockDbSet(); _providerVenueRepository.GetManyAsync(Arg.Any <Expression <Func <ProviderVenue, bool> > >()) .Returns(mockProviderVenueDbSet); _functionLogRepository = Substitute.For <IRepository <FunctionLog> >(); var googleMapsApiClient = Substitute.For <IGoogleMapApiClient>(); googleMapsApiClient.GetAddressDetailsAsync("CV1 2WT").Returns("Coventry"); _locationApiClient = Substitute.For <ILocationApiClient>(); _locationApiClient.GetGeoLocationDataAsync(Arg.Any <string>(), Arg.Any <bool>()) .Returns(new PostcodeLookupResultDto { Postcode = "CV1 2WT", Latitude = "52.400997", Longitude = "-1.508122" }); var proximityFunctions = new Functions.Proximity( _locationApiClient, googleMapsApiClient, opportunityItemRepository, _providerVenueRepository, _functionLogRepository); proximityFunctions.BackFillProximityDataAsync( new TimerInfo(new ConstantSchedule(TimeSpan.Zero), null), new ExecutionContext(), new NullLogger <Functions.Proximity>() ).GetAwaiter().GetResult(); }
public When_ProviderVenueService_Is_Called_To_Create_Venue() { var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var config = new MapperConfiguration(c => { c.AddMaps(typeof(ProviderVenueMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserEmailResolver") ? new LoggedInUserEmailResolver <AddProviderVenueViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) : type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <AddProviderVenueViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <AddProviderVenueViewModel, Domain.Models.ProviderVenue>(new DateTimeProvider()) : null); }); var mapper = new Mapper(config); _providerVenueRepository = Substitute.For <IProviderVenueRepository>(); _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >()) .Returns(new Domain.Models.ProviderVenue()); _locationApiClient = Substitute.For <ILocationApiClient>(); _locationApiClient.GetGeoLocationDataAsync(UnFormattedPostcode, true).Returns(new PostcodeLookupResultDto { Postcode = FormattedPostcode, Longitude = "1.2", Latitude = "1.2" }); _googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); _googleMapApiClient.GetAddressDetailsAsync(Arg.Is <string>(s => s == FormattedPostcode)).Returns("Coventry"); var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, _locationApiClient, _googleMapApiClient); var viewModel = new AddProviderVenueViewModel { Postcode = UnFormattedPostcode }; providerVenueService.CreateVenueAsync(viewModel).GetAwaiter().GetResult(); }
public DistanceCalculationServiceUnitTests() { _locationApiClient = Substitute.For <ILocationApiClient>(); var dateTimeService = Substitute.For <IDateTimeService>(); var logger = Substitute.For <ILogger <DistanceCalculationService> >(); var cache = Substitute.For <IMemoryCache>(); var configuration = new ConfigurationOptions { PostcodeCacheExpiryInSeconds = 120 }; _distanceCalculationService = new DistanceCalculationService( _locationApiClient, dateTimeService, cache, configuration, logger); }
public LocationService(ILocationApiClient locationApiClient) { _locationApiClient = locationApiClient; }
public GetAddressesQueryHandler(ILocationApiClient <LocationApiConfiguration> locationApiClient, FindAnApprenticeshipConfiguration config) { _locationApiClient = locationApiClient; _config = config; }
public GetAddressesQueryHandler(ILocationApiClient <LocationApiConfiguration> locationApiClient, RecruitConfiguration config) { _locationApiClient = locationApiClient; _config = config; }
public DistanceCalculationService(ILocationApiClient locationApiClient) { _locationApiClient = locationApiClient ?? throw new ArgumentNullException(nameof(locationApiClient)); }
public LocationRepository(ILocationApiClient apiClient, ILocationCache locationCache) { _apiClient = apiClient; _locationCache = locationCache; }
public LocationLookupService(ILocationApiClient <LocationApiConfiguration> locationApiClient) { _locationApiClient = locationApiClient; }
public DistanceCalculationServiceUnitTests() { _locationApiClient = Substitute.For <ILocationApiClient>(); _distanceCalculationService = new DistanceCalculationService(_locationApiClient); }
public GetAddressesQueryHandler(ILocationApiClient <LocationApiConfiguration> locationApiClient, EmployerContactFormsConfiguration config) { _locationApiClient = locationApiClient; _config = config; }
public VenueNameResolver(ILocationApiClient locationApiClient) { _locationApiClient = locationApiClient; }
private LocationRepository GetItemUnderTest(ILocationApiClient apiClient, ILocationCache cache) { return(new LocationRepository(apiClient, cache)); }
public GetLocationsQueryHandler(ILocationApiClient <LocationApiConfiguration> apiClient) { _apiClient = apiClient; }
public LocationsApiHealthCheck(ILocationApiClient <LocationApiConfiguration> apiClient, ILogger <LocationsApiHealthCheck> logger) { _apiClient = apiClient; _logger = logger; }