public void ReturnDefaulView_WithCorrectViewModel() { // Arrange var mockedTripService = new Mock <ITripService>(); var mockedMappingProvider = new Mock <IMappingProvider>(); var controller = new SearchController(mockedTripService.Object, mockedMappingProvider.Object); var searchViewModel = new SearchTripViewModel(); searchViewModel.Origin = "Pazardzhik"; searchViewModel.Destination = "Sofia"; var tripsBasinInfo = new TripSearchResult(); tripsBasinInfo.FoundTrips = new List <TripBasicInfo>(); mockedTripService.Setup(x => x.GetTripsFor(searchViewModel.Origin, searchViewModel.Destination, 0)) .Returns(tripsBasinInfo); var tripsViewModel = new List <TripBasicInfoViewModel>(); mockedMappingProvider.Setup(x => x.Map <IEnumerable <TripBasicInfo>, IEnumerable <TripBasicInfoViewModel> >(tripsBasinInfo.FoundTrips)) .Returns(tripsViewModel); // Act and Assert controller.WithCallTo(x => x.Result(searchViewModel)) .ShouldRenderDefaultView() .WithModel(searchViewModel); }
public void ShowSearchResult(TripSearchResult result) { tripSearchAdapter.Update(result); if (tripSearchAdapter.Count == 0) { this.tvNoResultsFound.Visibility = ViewStates.Visible; } ShowBusy(false); }
public static void StartTripDetails(Activity activity, Itinerary itinerary, TripSearchResult searchResult) { ItineraryDetailsIntent.itinerary = itinerary; Intent intent = new Intent(activity.ApplicationContext, typeof(ItineraryDetailsActivity)); intent.PutExtra(ItineraryDetailsActivity.KEY_startLocation, searchResult.searchCriteria.GetStartLocationString()); intent.PutExtra(ItineraryDetailsActivity.KEY_endLocation, searchResult.searchCriteria.GetEndLocationString()); activity.StartActivityForResult(intent, 1); }
public async Task <TripSearchResult> SearchForTrip(TripSearch search) { TripSearchResult val = await Task.Factory.StartNew <TripSearchResult>(() => { TripSearchResult searchResult = new TripSearchResult(); var client = new RestClient(URI_STRING); client.UserAgent = USER_AGENT; var request = new RestRequest("/api/OTP", Method.GET); request.RequestFormat = DataFormat.Json; request.AddParameter("startLatitude", search.StartLatitude); request.AddParameter("startLongitude", search.StartLongitude); request.AddParameter("startLocation", search.StartLocation); request.AddParameter("endLatitude", search.EndLatitude); request.AddParameter("endLongitude", search.EndLongitude); request.AddParameter("endLocation", search.EndLocation); request.AddParameter("searchByArriveByTime", search.SearchByArriveByTime); request.AddParameter("time", search.Time); request.AddParameter("needWheelchairAccess", search.NeedWheelchairAccess); request.AddParameter("maxWalkMeters", search.MaxWalkMeters); IRestResponse <TripSearchResult> response = client.Execute <TripSearchResult>(request); searchResult = response.Data; if (searchResult != null) { foreach (Itinerary itinerary in searchResult.itineraries) { if (itinerary.legs != null) { foreach (Leg leg in itinerary.legs) { if (leg.legGeometry != null) { if (leg.legGeometry.points != null) { leg.googlePoints = GooglePoints.Decode(leg.legGeometry.points); } } } } } } return(searchResult); }); return(val); }
public async Task <TripSearchResult> Search() { TripSearchResult searchResult = new TripSearchResult(); if (_isSearchable) { UserTripDataManager dataManager = new UserTripDataManager(); searchResult = await dataManager.SearchForTrips(_startLocation, _endLocation, _maxWalkDistance, _date, _isDeparture, _cityString, _stateString); } return(searchResult); }
public void Update(TripSearchResult result) { if (result == null) { this.tripSearchResult = new TripSearchResult(); this._count = 0; } else { this.tripSearchResult = result; this._count = this.tripSearchResult.itineraries.Count; } NotifyDataSetChanged(); }
public async Task <TripSearchResult> SearchForTrips(string startLocation, string endLocation, double maxWalkMeters, DateTime date, bool isDeparture, String cityString, String stateString) { TripSearch criteria = new TripSearch(); criteria.MaxWalkMeters = maxWalkMeters; criteria.NeedWheelchairAccess = false; criteria.SearchByArriveByTime = !isDeparture; criteria.Time = date; criteria = parseLocationString(criteria, startLocation, true, cityString, stateString); criteria = parseLocationString(criteria, endLocation, false, cityString, stateString); TripSearchResult searchResult = await mTripManager.SearchForTrip(criteria); if (searchResult != null) { searchResult.searchCriteria = criteria; searchResult.itineraries.Sort((a, b) => a.startTime.CompareTo(b.startTime)); } return(searchResult); }
public async void SearchAndDisplayResults(SearchIntent searchIntent) { this.view.ShowBusy(true); try{ searchResult = await searchIntent.Search(); }catch (Exception e) { Console.WriteLine(e.Message); searchResult = null; } if (searchResult != null) { activity.sendGaEvent("ui_action", "search trips", "search results", searchResult.itineraries.Count); } else { activity.sendGaEvent("ui_action", "search trips", "search results", -1); } this.view.ShowSearchResult(searchResult); this.view.ShowBusy(false); }
public TripSearchResult GetTripsFor(string origin, string destination, int page = 0) { origin = origin?.ToLower(); destination = destination?.ToLower(); int size = 5; // handle zero based paging page = page - 1 >= 0 ? page - 1 : 0; var totalTrips = this.tripRepo .GetAll(x => x.Origin.Name.ToLower().Contains(origin) && x.Destination.Name.ToLower().Contains(destination) && !x.IsDeleted && !x.IsFinished, x => x.Id); var totalCount = totalTrips.Count(); var trips = this.tripRepo .GetAllMappedWithAscSort <DateTime, TripBasicInfo>( where => where.Origin.Name.ToLower().Contains(origin) && where.Destination.Name.ToLower().Contains(destination) && !where.IsFinished && !where.IsDeleted, x => x.TimeOfDeparture, page, size); var result = new TripSearchResult(); result.FoundTrips = trips; result.TotalTrips = totalCount; return(result); }
async private Task search() { //Save Date Time var userPrefs = NSUserDefaults.StandardUserDefaults; userPrefs.SetString(txtMaxWalk.Text, MAX_WALK_DIST_USER_PREF); userPrefs.Synchronize(); String maxWalkString = txtMaxWalk.Text.Replace("Mile", "").Trim(); double maxWalkDistMeters = 500; if (maxWalkString.Equals("1/4")) { maxWalkDistMeters = 403; } else if (maxWalkString.Equals("1/2")) { maxWalkDistMeters = 805; } else if (maxWalkString.Equals("3/4")) { maxWalkDistMeters = 1207; } else if (maxWalkString.Equals("1")) { maxWalkDistMeters = 1610; } bool isDeparture = true; DateTime tripDate = DateTime.Parse(txtDate.Text); int selectedIndex = segmentDateType.SelectedSegment; string selectedValue = segmentDateType.TitleAt(selectedIndex); if (selectedValue.Equals("Departure")) { isDeparture = true; } else { isDeparture = false; } string startLocation = txtStartLocation.Text; string endLocation = txtEndLocation.Text; if (startLocation.Equals(CURRENT_LOCATION_STRING)) { startLocation = mCurrentLocation.Latitude.ToString() + "," + mCurrentLocation.Longitude.ToString(); } if (endLocation.Equals(CURRENT_LOCATION_STRING)) { endLocation = mCurrentLocation.Latitude.ToString() + "," + mCurrentLocation.Longitude.ToString(); } mSearchResults = await mUserTripDataManager.SearchForTrips(startLocation, endLocation, maxWalkDistMeters, tripDate, isDeparture, mCityString, mStateString); if (mSearchResults != null) { GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("ui_action", "search trips", "search results", mSearchResults.itineraries.Count).Build()); this.PerformSegue("SearchResultsSegue", this); } else { GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("ui_action", "search trips", "search results", -1).Build()); UIAlertView alert = new UIAlertView("No Results", "No trips found. Please check your start and end location. Location can be either current location or an address.", null, "OK", null); alert.Show(); } }
public TripSearchResultAdapter(LayoutInflater inflater) { this.inflater = inflater; this.tripSearchResult = new TripSearchResult(); _count = 0; }
public void ReturnTrips_FromProvidedOrigin_ToProvidedDestination_InspiteOfCasing() { // Arrange var mockedTripRepo = new Mock <IProjectableRepositoryEf <Trip> >(); var mockedUserTripRepo = new Mock <IProjectableRepositoryEf <UsersTrips> >(); var mockedCityService = new Mock <ICityService>(); var mockedTagService = new Mock <ITagService>(); var mockedDateTimpeProvider = new Mock <IDateTimeProvider>(); var mockedMappingProvider = new Mock <IMappingProvider>(); var mockedUnitOfWork = new Mock <IUnitOfWorkEF>(); var tripService = new TripService( () => mockedUnitOfWork.Object, mockedUserTripRepo.Object, mockedCityService.Object, mockedMappingProvider.Object, mockedTagService.Object, mockedTripRepo.Object, mockedDateTimpeProvider.Object); string originName = "Sofia"; string destinationName = "Plovdiv"; var origin = new City() { Name = originName }; var destination = new City() { Name = destinationName }; var trip1 = new Trip() { Origin = origin, Destination = destination, DateCreated = DateTime.Now, TimeOfDeparture = DateTime.Now }; var data = new List <Trip>() { trip1 }; IEnumerable <int> allTrisIds = null; mockedTripRepo.Setup(x => x.GetAll( It.IsAny <Expression <Func <Trip, bool> > >(), It.IsAny <Expression <Func <Trip, int> > >())) .Returns((Expression <Func <Trip, bool> > predicate, Expression <Func <Trip, int> > select) => { allTrisIds = data.Where(predicate.Compile()).Select(select.Compile()); return(allTrisIds); }); int page = 0; int size = 5; IEnumerable <TripBasicInfo> paggedTrips = null; mockedTripRepo.Setup(x => x.GetAllMappedWithAscSort <DateTime, TripBasicInfo>( It.IsAny <Expression <Func <Trip, bool> > >(), It.IsAny <Expression <Func <Trip, DateTime> > >(), page, size)) .Returns(( Expression <Func <Trip, bool> > predicate, Expression <Func <Trip, DateTime> > sort, int pageNum, int sizeToTake) => { paggedTrips = data .Where(predicate.Compile()) .OrderBy(sort.Compile()) .Skip(pageNum * sizeToTake) .Take(sizeToTake) .Select(x => new TripBasicInfo() { Id = x.Id, DestinationName = x.Destination.Name, OriginName = x.Origin.Name, Price = x.Price, TakenSeats = x.TakenSeats, TimeOfDeparture = x.TimeOfDeparture, TotalSeats = x.TotalSeats, }); return(paggedTrips); }); // Act TripSearchResult result = tripService.GetTripsFor(origin.Name, destination.Name); int totalTripsCount = allTrisIds.Count(); TripSearchResult expected = new TripSearchResult() { FoundTrips = paggedTrips, TotalTrips = totalTripsCount }; // Assert Assert.AreEqual(expected.TotalTrips, result.TotalTrips); Assert.AreEqual(expected.FoundTrips.ToList()[0].Id, result.FoundTrips.ToList()[0].Id); Assert.AreEqual(expected.FoundTrips.ToList()[0].OriginName, result.FoundTrips.ToList()[0].OriginName); Assert.AreEqual(expected.FoundTrips.ToList()[0].DestinationName, result.FoundTrips.ToList()[0].DestinationName); }
public SearchResultsTableSource(TripSearchResult searchResult) { mSearchResult = searchResult; }
public async Task <TripSearchResult> SearchForTrips(string startLocation, string endLocation, DateTime date, bool isDeparture, double maxWalkDistanceMeters = QUARTER_MILE_IN_METERS) { TripSearchResult searchResult = await SearchForTrips(startLocation, endLocation, maxWalkDistanceMeters, date, isDeparture, "", ""); return(searchResult); }