public async Task <ProviderVenueDetailViewModel> GetVenueAsync(int providerVenueId) { var venue = await _providerVenueRepository.GetSingleOrDefaultAsync(pv => pv.Id == providerVenueId); var dto = venue == null ? null : _mapper.Map <ProviderVenue, ProviderVenueDetailViewModel>(venue); return(dto); }
public When_ProviderVenueService_Is_Called_To_Get_Venue_By_Provider_Id_And_Postcode() { var config = new MapperConfiguration(c => c.AddMaps(typeof(ProviderVenueMapper).Assembly)); var mapper = new Mapper(config); _providerVenueRepository = Substitute.For <IProviderVenueRepository>(); _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >()) .Returns(new Domain.Models.ProviderVenue { Id = ProviderVenueId, ProviderId = ProviderId, Name = Name, Postcode = Postcode, IsRemoved = IsRemoved, IsEnabledForReferral = IsEnabledForReferral, Source = DataSource }); var googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); var locationService = Substitute.For <ILocationApiClient>(); var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient); _result = providerVenueService.GetVenueAsync(ProviderId, Postcode).GetAwaiter().GetResult(); }
public When_ProviderVenueService_Is_Called_To_Remove_Venue() { var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var config = new MapperConfiguration(c => { c.AddMaps(typeof(ProviderMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <RemoveProviderVenueViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <RemoveProviderVenueViewModel, Domain.Models.ProviderVenue>(new DateTimeProvider()) : null); }); var mapper = new Mapper(config); var googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); var locationService = Substitute.For <ILocationApiClient>(); _providerVenueRepository = Substitute.For <IProviderVenueRepository>(); _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >()) .Returns(new ValidProviderVenueBuilder().Build()); var service = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient); var viewModel = new RemoveProviderVenueViewModel { ProviderId = 1, ProviderVenueId = 1 }; service.UpdateVenueAsync(viewModel).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 When_ProviderVenueService_Is_Called_To_Get_Venue_Postcode() { var config = new MapperConfiguration(c => c.AddMaps(typeof(ProviderVenueMapper).Assembly)); var mapper = new Mapper(config); var googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); var locationService = Substitute.For <ILocationApiClient>(); _providerVenueRepository = Substitute.For <IProviderVenueRepository>(); _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >()) .Returns(new ValidProviderVenueBuilder().Build()); var service = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient); _result = service.GetVenuePostcodeAsync(1).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(); }