/// <summary> /// Gets a narrowed list of <see cref="Place" /> items that starts with the specified expression. /// </summary> /// <param name="startsWith">The search criteria.</param> /// <returns>A narrowed list of <see cref="Place" /> items.</returns> public IEnumerable<Place> Narrowed(string startsWith) { var repository = new PlaceRepository(); return repository.Get() .Where(p => p.Source.StartsWith(startsWith, StringComparison.InvariantCultureIgnoreCase)); }
// GET: api/Place?keyword=park&keyword=coffee... public HttpResponseMessage Get([FromUri] IList<string> keyword) { try { var repository = new PlaceRepository(); var calculateScores = new CalculateScores(); var calculatedPlaces = calculateScores.For(repository.Get(keyword)); var data = new Data { Places = calculatedPlaces, Max = 10 }; var json = JsonConvert.SerializeObject(data); return new HttpResponseMessage { Content = new StringContent(json), StatusCode = HttpStatusCode.OK }; } catch (Exception) { return new HttpResponseMessage {StatusCode = HttpStatusCode.InternalServerError}; } }
public void ReadAllPlacesTest() { var repositoryUnderTest = new PlaceRepository(); var places = repositoryUnderTest.Get(string.Empty).ToList(); places.Should().NotBeNull(); places.Any().Should().BeTrue(); }
public void ReadPlacesByKeywordTest() { var repositoryUnderTest = new PlaceRepository(); var places = repositoryUnderTest.Get("Bikes").ToList(); places.Should().NotBeNull(); places.Any().Should().BeTrue(); places.Count.Should().Be(1); }