// 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 CalculateScoresForPlacesTest() { var places = new List<Place> { new Place {Latitude = 53.1234, Longitude = 13.1234, Score = 7, ZipCode = "123456"}, new Place {Latitude = 53.2234, Longitude = 13.1234, Score = 8, ZipCode = "123456"}, new Place {Latitude = 53.3234, Longitude = 13.1234, Score = 9, ZipCode = "123456"}, new Place {Latitude = 53.4234, Longitude = 13.1234, Score = 7, ZipCode = "123456"}, new Place {Latitude = 54.1234, Longitude = 14.1234, Score = 2, ZipCode = "223456"}, new Place {Latitude = 54.2234, Longitude = 14.1234, Score = 3, ZipCode = "223456"}, new Place {Latitude = 54.3234, Longitude = 14.1234, Score = 4, ZipCode = "223456"}, new Place {Latitude = 54.4234, Longitude = 14.1234, Score = 5, ZipCode = "223456"} }; var calculateScores = new CalculateScores(); var results = calculateScores.For(places).ToList(); results.Should().NotBeNull(); results.Any().Should().BeTrue(); results.Count.Should().Be(2); results[0].Score.Should().Be(7.75); results[1].Score.Should().Be(3.5); }