public void LogLocation(int truckId, GeoLocation location)
 {
     if (runtimeStorage.ContainsKey(truckId))
         runtimeStorage[truckId] = location;
     else
         runtimeStorage.Add(truckId, location);
 }
        public void SingleTruckOverrideLocation()
        {
            GeoLocation l1 = new GeoLocation("123 Fake Street");
            GeoLocation l2 = new GeoLocation("456 Fake Street");

            Assert.IsNull(storage.GetLocation(1));

            storage.LogLocation(1, l1);
            Assert.AreEqual(l1, storage.GetLocation(1));

            storage.LogLocation(1, l2);
            Assert.AreEqual(l2, storage.GetLocation(1));
        }
        public DeliveryPriceDto Get([FromUri]decimal lat, [FromUri]decimal lng)
        {
            var location = new GeoLocation(lat, lng);
            var trucks = truckStorage.GetAllTruckLocations();
            //var closestTruck = trucks.OrderByDescending(t => location.DistanceTo(t)).First();
            var closestTruck = new GeoLocation(49.1384125m,-123.16684400000001m);
            var distance = closestTruck.DistanceTo(location);
            var costForDelivery = DeliveryPricing.CostForDelivery(distance);

            return new DeliveryPriceDto()
            {
                ClosestTruck = closestTruck,
                Kilometres = (int)(distance + 0.5),
                Cost = costForDelivery
            };
        }
        public void MultipeTrucksMultipleLocations()
        {
            GeoLocation l1 = new GeoLocation("123 Fake Street");
            GeoLocation l2 = new GeoLocation("456 Fake Street");
            GeoLocation l3 = new GeoLocation("789 Fake Street");

            Assert.IsNull(storage.GetLocation(1));
            Assert.IsNull(storage.GetLocation(2));

            storage.LogLocation(1, l1);
            Assert.AreEqual(l1, storage.GetLocation(1));
            Assert.IsNull(storage.GetLocation(2));

            storage.LogLocation(2, l2);
            Assert.AreEqual(l1, storage.GetLocation(1));
            Assert.AreEqual(l2, storage.GetLocation(2));

            storage.LogLocation(1, l3);
            Assert.AreEqual(l3, storage.GetLocation(1));
            Assert.AreEqual(l2, storage.GetLocation(2));
        }
示例#5
0
 public double DistanceTo(GeoLocation location)
 {
     return this.ToCoordinate().GetDistanceTo(location.ToCoordinate());
 }