public void GetLocationsWithCoordsTest() { List <Location> locations = locationPersistence.GetLocations("Loca", 19.0f, -100.0f).ToList(); Assert.AreEqual(2, locations.Count); LocationMatch match1 = (LocationMatch)locations.Find(location => location.Name.Contains("Location1")); LocationMatch match2 = (LocationMatch)locations.Find(location => location.Name.Contains("Location2")); Assert.Greater(match2.Score, match1.Score); }
/* * Returns a list of locations that contain the city name and have the latitude and/or longitude specified. * A score is provided to determine how closely the city matches the query. */ private IEnumerable <Location> GetMatchingLocations(string inputCityName, float?latitude, float?longitude) { List <Location> matchingLocations = locationDb.Select(location => location.Value).Where(location => location.Name.Contains(inputCityName)).ToList(); List <LocationMatch> results = new List <LocationMatch>(); LocationMatch locationMatch = null; foreach (LocationInfo location in matchingLocations) { double score = CalculateScore(location, inputCityName, latitude, longitude); locationMatch = new LocationMatch(location.GetFullLocationString(), location.Latitude, location.Longitude, score); results.Add(locationMatch); } return(results.OrderByDescending(location => location.Score).ToList()); }