public async Task Then_The_Postcode_API_Is_Called_With_Query_And_Count( string query, PostcodeData postcode, [Frozen] Mock <IPostcodeApiService> postcodeApiService, PostcodeService postcodeService) { //Arrange postcodeApiService.Setup(x => x.GetPostcodeData(query)) .ReturnsAsync(postcode); //Act var actual = await postcodeService.GetPostcodeByFullPostcode(query); //Assert actual.Should().Be(postcode); }
public async Task Then_The_Outcode_Api_Is_Called_With_The_Query_And_Returns_District_Data( string query, SuggestedLocation location, [Frozen] Mock <IPostcodeApiService> apiService, PostcodeService service ) { //Arrange apiService.Setup(x => x.GetDistrictData(query)).ReturnsAsync(location); //Act var actual = await service.GetDistrictNameByOutcodeQuery(query); actual.Lat.Should().Be(location.Lat); //Assert actual.Should().BeEquivalentTo(location); }
public async Task Then_The_Api_Is_Called_With_The_Query_And_Count_And_Returns_Postcode_Data( int resultCount, string query, IEnumerable <SuggestedLocation> locations, [Frozen] Mock <IPostcodeApiService> apiService, PostcodeService service ) { //Arrange apiService.Setup(x => x.GetAllStartingWithOutcode(query, resultCount)) .ReturnsAsync(locations); //Act var actual = await service.GetPostcodesByOutcodeQuery(query, resultCount); //Assert actual.Should().BeEquivalentTo(locations); }
private async Task <PostcodeResult?> GetPostcodeResultAsync(FarmData farmData) { PostcodeResult?postcodeLookup = null; if (!string.IsNullOrWhiteSpace(farmData.Postcode)) { postcodeLookup = await PostcodeService.GetPostcodeInfoAsync(farmData.Postcode); } if (postcodeLookup == null && !string.IsNullOrWhiteSpace(farmData.Town)) { postcodeLookup = await PostcodeService.GetPlaceAsync(farmData.Town); } if (postcodeLookup == null && !string.IsNullOrWhiteSpace(farmData.County)) { postcodeLookup = await PostcodeService.GetPlaceAsync(farmData.County); } return(postcodeLookup); }
private async void PostcodeButton_Click(object sender, RoutedEventArgs e) { _clearStatus(); if (_validatePostcode()) { // get long lat from api _postcode = new PostcodeService(PostcodeTextBox.Text); var result = await _postcode.GetLongLatAsync(); if (result == null) { _updateStatus("Unknown postcode"); } else { // pass postcode result into location service var locationService = new LocationService(result); _buildLocationUI(locationService.ValidLocations); } } }
// GET: CourseDirectory // ASB TODO - Should we not be returning OK objects? rather than empty Views if something goes wrong? public ActionResult CourseSearchResult([FromQuery] CourseSearchRequestModel requestModel) { Telemetry.TrackEvent($"Logging: Started: Controller = {nameof(CourseDirectoryController)}: Action = {nameof(CourseSearchResult)}: {nameof(Environment.MachineName)} = {Environment.MachineName}: {nameof(CorrelationContextAccessor.CorrelationContext.CorrelationId)} = {CorrelationContextAccessor.CorrelationContext.CorrelationId}"); var dtStart = DateTime.Now; var isPostcodeInvalid = false; if (TempData != null) { isPostcodeInvalid = (TempData["Location_IsInvalid"] != null && (bool)TempData["Location_IsInvalid"] == true); if (!string.IsNullOrWhiteSpace(requestModel.Location)) { var postcodeResult = PostcodeService.IsValidAsync(requestModel.Location).Result; if (postcodeResult.IsFailure) { isPostcodeInvalid = true; TempData["Location_IsInvalid"] = isPostcodeInvalid; TempData["Location_Postcode"] = requestModel.Location; if (new UriBuilder(Request.Headers["Referer"]).Path != Request.Path) { return(RedirectToAction(nameof(Index))); } } } else { TempData.Remove("Location_IsInvalid"); TempData.Remove("Location_Postcode"); } } Telemetry.TrackEvent($"[{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture)}] Starting to create course search criteria."); var criteria = CourseDirectory.CreateCourseSearchCriteria(requestModel); Telemetry.TrackEvent($"[{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture)}] Finished creating course search criteria."); Telemetry.TrackEvent($"[{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture)}] Starting call to course directory search from the course directory service."); var result = Service.CourseDirectorySearch(criteria, new PagingOptions(CourseDirectoryHelper.GetSortBy(requestModel.SortBy), requestModel.PageNo)); Telemetry.TrackEvent($"[{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture)}] Finished calling course directory search from the course directory service."); if (!CourseDirectory.IsSuccessfulResult(result, Telemetry, "Course Search", requestModel.SubjectKeyword, dtStart)) { return(View(nameof(Error), new Models.ErrorViewModel() { RequestId = "Course Search: " + requestModel.SubjectKeyword.ToString() + ". " + (null != result ? result.Error : string.Empty) })); } //DEBUG_FIX - Add the flush to see if working straightaway //ASB TODO Why are we flushing here? We may not end up here due to higher up returns. //So that we could test the telemetry, a la the DEBUG_FIX Telemetry.Flush(); int perPage = int.TryParse(Configuration["Tribal:PerPage"], out perPage) ? perPage : 0; Telemetry.TrackEvent($"Logging: Ended: Controller = {nameof(CourseDirectoryController)}: Action = {nameof(CourseSearchResult)}: {nameof(Environment.MachineName)} = {Environment.MachineName}: {nameof(CorrelationContextAccessor.CorrelationContext.CorrelationId)} = {CorrelationContextAccessor.CorrelationContext.CorrelationId}"); return(View(new CourseSearchResultViewModel(result) { SubjectKeyword = requestModel.SubjectKeyword, Location = requestModel.Location, LocationHasError = isPostcodeInvalid, LocationRadius = (RadiusDistance)requestModel.LocationRadius, PerPage = perPage, StudyModes = requestModel.StudyModes, AttendanceModes = requestModel.AttendanceModes, AttendancePatterns = requestModel.AttendancePatterns, QualificationLevels = requestModel.QualificationLevels, IsDfe1619Funded = requestModel.IsDfe1619Funded, SortBy = CourseDirectoryHelper.GetSortBy(requestModel.SortBy), })); }
public void Initialize() { _webServiceMock = new Mock <IWebService>(); _service = new PostcodeService(_webServiceMock.Object); }