Exemple #1
0
        public List<Crime> FetchCrimesNearLocation(Location location)
        {
            using (HttpClient client = new HttpClient())
            {

                client.BaseAddress = new Uri(AllStreetCrimesUri);
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                string uriQuerystring =
                    string.Format("?date=2013-07&lat={0}&lng={1}",
                         location.Latitude, location.Longitude  );

                HttpResponseMessage response = client.GetAsync(uriQuerystring).Result;
                if (response.IsSuccessStatusCode)
                {
                    var crimes = response.Content.ReadAsAsync<IEnumerable<Crime>>().Result;

                    return crimes.ToList();
                }
                else
                {
                    throw new Exception(
                        string.Format("{0} ({1})", (int) response.StatusCode, response.ReasonPhrase));
                }
            }
        }
Exemple #2
0
 public void CrimeFretcherCanFetchACrimeSomewhereNearALocation()
 {
     var crimeFretcher = new CrimeFetcher();
     var mosiLocation = new Location(-2.255562, 53.476788);
     var crimeList = crimeFretcher.FetchCrimesNearLocation(mosiLocation);
     Assert.AreNotEqual(0, crimeList.Count);
 }
 public void TestMethod1()
 {
     var crimeFretcher = new CrimeFetcher();
     var mosiLocation = new Location(-2.255562, 53.476788);
     var crimeList = crimeFretcher.FetchCrimesNearLocation(mosiLocation);
     var northEastDirection = new NorthEastDirection(x => x.Location.Longitude > mosiLocation.Longitude
                 && x.Location.Latitude > mosiLocation.Latitude, crimeList, mosiLocation);
     var numberOfCrimesToTheNorthEast = northEastDirection.Count;
     Assert.AreNotEqual(numberOfCrimesToTheNorthEast, crimeList.Count);
 }
Exemple #4
0
        public Crime GetACrimeSomewhereNearLocation(double lat, double lng)
        {
            var location = new Location(lng, lat);
            var crimeFetcher = new CrimeFetcher();
            var crimelist = crimeFetcher.FetchCrimesNearLocation(location);
            if (crimelist.Count > 0)
                return crimelist[0];

            return new Crime();
        }
Exemple #5
0
 public List<Crime> FetchSomeCrimes()
 {
     var mosiLocation = new Location(-2.255562, 53.476788);
     return FetchCrimesNearLocation(mosiLocation);
 }
 public Direction DirectionFromLocation(float lat, float lng)
 {
     var location = new Location(lng, lat);
     var directionFinder = new DirectionFinder(location);
     return directionFinder.BestDirection();
 }
Exemple #7
0
 public Crime()
 {
     Location = new Location(0, 0);
 }
Exemple #8
0
 public NorthEastDirection(Func<Crime, bool> predicate, List<Crime> crimelist, Location location)
 {
     Count = crimelist.Count( predicate);
 }
Exemple #9
0
 public DirectionFinder(Location location)
 {
     this.location = location;
 }