public void testAssignmentWhenDriverIsOnHoliday()
        {
            Driver        driverOne = new Driver();
            DriverHoliday hols      = new DriverHoliday();

            hols.From = new DateTime(2012, 12, 12);
            hols.To   = new DateTime(2012, 12, 20);
            driverOne.Holidays.Add(hols);

            Route routeOne = new Route();

            routeOne.DeliverBy = new DateTime(2012, 12, 17);
            List <Route> routes = new List <Route> {
                routeOne
            };


            LocationService         locationService   = new LocationService(null);
            DriverAssignmentService assignmentService = new DriverAssignmentService(locationService);
            RouteAssignment         result            = assignmentService.assignMultipleRoutes(routes, new List <Driver> {
                driverOne
            });

            Assert.Equal(1, result.TempRouteData.Count());
            Assert.Null(result.TempRouteData.ElementAt(0).Driver);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AutomaticAssign()
        {
            var             routesToAssign = company.Routes.Where(r => r.DriverID == null).ToList();
            RouteAssignment assignemnt     = DriverAssignmentService.assignMultipleRoutes(routesToAssign, company.Team.Drivers.ToList());

            TempData["Assignment"] = JsonConvert.SerializeObject(assignemnt);
            var TempRouteData = assignemnt.TempRouteData;

            foreach (TempRoute tempRoute in TempRouteData)
            {
                Route route = company.Routes.Where(r => r.ID == tempRoute.RouteId).First();
                if (tempRoute.Driver != null)
                {
                    Driver driverEntity = _context.Drivers.Where(d => d.ID == tempRoute.Driver.ID).FirstOrDefault();
                    route.DriverID = driverEntity.ID;
                    await notificationService.SendAnEmailToDriverAboutAssignedRouteAsync(route, driverEntity.User);
                }
                route.DeliveryDate = tempRoute.ModifiedDeliverByDate.AddDays(-1);
                if (tempRoute.DriversVehicle != null)
                {
                    route.VehicleID = tempRoute.DriversVehicle.ID;
                }
                _context.Routes.Update(route);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction("AssignmentResult"));
        }
        public void testAssignMultipleRoutesAllForDifferentDaysWithOneDriver()
        {
            Driver driverOne = new Driver();

            driverOne.Address = new DriverAddress();
            Vehicle vehicleOne = new Vehicle(300, 100, 109, 100);

            driverOne.Vehicles.Add(vehicleOne);


            List <Driver> drivers = new List <Driver> {
                driverOne
            };

            var responseMessageOne = new HttpResponseMessage();

            responseMessageOne.Content = new StringContent("{\"destination_addresses\":[\"Village Way, Brighton BN1, United Kingdom\"],\"origin_addresses\":[\"Arts Rd, Falmer, Brighton BN1 9QN, United Kingdom\"],\"rows\":[{\"elements\":[{\"distance\":{\"text\":\"0.8 mi\",\"value\":2},\"duration\":{\"text\":\"4 min\",\"value\":235},\"status\":\"OK\"}]}],\"status\":\"OK\"}");

            var responseMessageTwo = new HttpResponseMessage();

            responseMessageTwo.Content = new StringContent("{\"destination_addresses\":[\"Village Way, Brighton BN1, United Kingdom\"],\"origin_addresses\":[\"Arts Rd, Falmer, Brighton BN1 9QN, United Kingdom\"],\"rows\":[{\"elements\":[{\"distance\":{\"text\":\"3.6 mi\",\"value\":10},\"duration\":{\"text\":\"4 min\",\"value\":235},\"status\":\"OK\"}]}],\"status\":\"OK\"}");
            List <HttpResponseMessage> responses = new List <HttpResponseMessage> {
                responseMessageOne, responseMessageTwo
            };
            TestGoogleMapsUtil googleMaps = new TestGoogleMapsUtil(responses);

            Route routeOne = new Route();

            routeOne.DeliverBy     = new DateTime(2015, 12, 13);
            routeOne.PickUpAddress = (PickUpAddress)getAddress(false);
            Delivery delivery = new Delivery();

            delivery.ItemWeight = 20;
            delivery.ItemSize   = ItemSize.Small;
            routeOne.Deliveries.Add(delivery);

            Route routeTwo = new Route();

            routeTwo.DeliverBy     = new DateTime(2015, 12, 14);
            routeTwo.PickUpAddress = (PickUpAddress)getAddress(false);
            Delivery deliveryTwo = new Delivery();

            deliveryTwo.ItemWeight = 20;
            deliveryTwo.ItemSize   = ItemSize.Small;
            routeTwo.Deliveries.Add(delivery);

            List <Route> routes = new List <Route> {
                routeOne, routeTwo
            };


            LocationService         locationService   = new LocationService(googleMaps);
            DriverAssignmentService assignmentService = new DriverAssignmentService(locationService);
            RouteAssignment         result            = assignmentService.assignMultipleRoutes(routes, drivers);

            Assert.Equal(2, result.TempRouteData.Count());
            Assert.Equal(driverOne, result.TempRouteData.ElementAt(0).Driver);
            Assert.Equal(driverOne, result.TempRouteData.ElementAt(1).Driver);
        }
        public void testDriverSelectionWhenBothDriversAreNotAvailable()
        {
            Driver driverOne = new Driver();

            driverOne.Address = new DriverAddress();
            Vehicle vehicleOne = new Vehicle(300, 100, 109, 100);

            driverOne.Vehicles.Add(vehicleOne);
            Route driverRoute = new Route();

            driverRoute.DeliverBy = new DateTime(2015, 12, 12);
            driverOne.Routes.Add(driverRoute);


            Driver driverTwo = new Driver();

            driverTwo.Address = new DriverAddress();
            driverTwo.Vehicles.Add(vehicleOne);
            driverTwo.Address = (DriverAddress)getAddress(true);
            List <Driver> drivers = new List <Driver> {
                driverOne, driverTwo
            };

            driverTwo.Routes.Add(driverRoute);

            var responseMessageOne = new HttpResponseMessage();

            responseMessageOne.Content = new StringContent("{\"destination_addresses\":[\"Village Way, Brighton BN1, United Kingdom\"],\"origin_addresses\":[\"Arts Rd, Falmer, Brighton BN1 9QN, United Kingdom\"],\"rows\":[{\"elements\":[{\"distance\":{\"text\":\"0.8 mi\",\"value\":2},\"duration\":{\"text\":\"4 min\",\"value\":235},\"status\":\"OK\"}]}],\"status\":\"OK\"}");

            var responseMessageTwo = new HttpResponseMessage();

            responseMessageTwo.Content = new StringContent("{\"destination_addresses\":[\"Village Way, Brighton BN1, United Kingdom\"],\"origin_addresses\":[\"Arts Rd, Falmer, Brighton BN1 9QN, United Kingdom\"],\"rows\":[{\"elements\":[{\"distance\":{\"text\":\"3.6 mi\",\"value\":10},\"duration\":{\"text\":\"4 min\",\"value\":235},\"status\":\"OK\"}]}],\"status\":\"OK\"}");
            List <HttpResponseMessage> responses = new List <HttpResponseMessage> {
                responseMessageOne, responseMessageTwo
            };
            TestGoogleMapsUtil googleMaps = new TestGoogleMapsUtil(responses);

            Route route = new Route();

            route.DeliverBy     = new DateTime(2015, 12, 13);
            route.PickUpAddress = (PickUpAddress)getAddress(false);
            Delivery delivery = new Delivery();

            delivery.ItemWeight = 20;
            delivery.ItemSize   = ItemSize.Small;
            route.Deliveries.Add(delivery);

            LocationService         locationService   = new LocationService(googleMaps);
            DriverAssignmentService assignmentService = new DriverAssignmentService(locationService);

            DriverAssignmentResult result = assignmentService.getBestDriverForRoute(route, drivers, new List <Driver>(), new List <Driver>(), new DateTime(2015, 12, 12));

            Assert.Equal(result.Driver, driverOne);
            Assert.Equal(result.DeliverByDate, new DateTime(2015, 12, 13));
        }
        public void testAssignmentWhenDriverIsOnHolidayButDeliveryIsRolledBackACoupleOfDays()
        {
            Driver        driverOne = new Driver();
            DriverHoliday hols      = new DriverHoliday();

            hols.From = new DateTime(2012, 12, 12);
            hols.To   = new DateTime(2012, 12, 20);
            driverOne.Holidays.Add(hols);
            driverOne.Address = new DriverAddress();
            Vehicle vehicleOne = new Vehicle(300, 100, 109, 100);

            driverOne.Vehicles.Add(vehicleOne);
            Route driverRoute = new Route();

            driverRoute.DeliverBy = new DateTime(2015, 12, 12);
            driverOne.Routes.Add(driverRoute);

            var responseMessageOne = new HttpResponseMessage();

            responseMessageOne.Content = new StringContent("{\"destination_addresses\":[\"Village Way, Brighton BN1, United Kingdom\"],\"origin_addresses\":[\"Arts Rd, Falmer, Brighton BN1 9QN, United Kingdom\"],\"rows\":[{\"elements\":[{\"distance\":{\"text\":\"0.8 mi\",\"value\":2},\"duration\":{\"text\":\"4 min\",\"value\":235},\"status\":\"OK\"}]}],\"status\":\"OK\"}");


            List <HttpResponseMessage> responses = new List <HttpResponseMessage> {
                responseMessageOne, responseMessageOne, responseMessageOne, responseMessageOne, responseMessageOne
            };
            TestGoogleMapsUtil googleMaps = new TestGoogleMapsUtil(responses);

            Route routeOne = new Route();

            routeOne.PickUpAddress = (PickUpAddress)getAddress(false);
            routeOne.DeliverBy     = new DateTime(2012, 12, 13);
            List <Route> routes = new List <Route> {
                routeOne
            };


            LocationService         locationService   = new LocationService(googleMaps);
            DriverAssignmentService assignmentService = new DriverAssignmentService(locationService);
            RouteAssignment         result            = assignmentService.assignMultipleRoutes(routes, new List <Driver> {
                driverOne
            });

            Assert.Equal(1, result.TempRouteData.Count());
            Assert.Equal(driverOne, result.TempRouteData.ElementAt(0).Driver);
        }
Exemplo n.º 6
0
 public SchedulingController(ApplicationDbContext context, IHttpContextAccessor contextAccessor, RouteCreationService routeService, DriverAssignmentService driverService, INotificationService notService) : base(context, contextAccessor)
 {
     this.RouteCreationService    = routeService;
     this.DriverAssignmentService = driverService;
     this.notificationService     = notService;
 }