예제 #1
0
        /// <summary>
        /// Will find the first route which has a stop eligible for moving and save off the route and stop detals to the ScenerioContext
        /// </summary>
        /// <param name="centerNumber"></param>
        /// <param name="filterStartDate"></param>
        /// <param name="filterEndDate"></param>
        public static void FindRandomRouteAndStopNumberWhichHasAnOrderAndNotDispatched(int centerNumber, DateTime filterStartDate, DateTime filterEndDate)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                DeepSearch      = true
            };
            var routes = SearchAsync(searchCriteria).Result;
            var Routes_WithNonRemovedStopsWithOrders = routes.Where(r =>
                                                                    r.RouteStops.Any(s => s.RoutePlanModificationTypeId != 1 && s.RoutePlanModificationTypeId != 4) && // give you non-removed stops
                                                                    r.RouteStops.Any(s => s.OrderId != 0 && s.StopNumber != 0 && s.Weight > 0));                       // give you with Order
            //Gets routes that have not been dispatched
            var Routes_WithNonRemovedStopWithOrders_NotDispatched = Routes_WithNonRemovedStopsWithOrders.Where(route => route.RouteStops.Any(s => s.TelogisArrivalDeliveryDateTime.HasValue) == false);

            Routes_WithNonRemovedStopWithOrders_NotDispatched.Count().Should().BeGreaterOrEqualTo(1, "should have found a route with at least 1 stop that's eligible for a stop move");
            //Randomly select one of the routes
            var selectedRoute = Routes_WithNonRemovedStopWithOrders_NotDispatched.ElementAt(rand.Next(Routes_WithNonRemovedStopWithOrders_NotDispatched.Count() - 1));
            var selectedRoute_WithOnlyNonRemovedStopsAndWithOrders = selectedRoute.RouteStops.Where(r => r.OrderId != 0 &&                                                                       //Give you stops with an order
                                                                                                    (r.RoutePlanModificationTypeId != 1 && r.RoutePlanModificationTypeId != 4 && r.Weight > 0)); //Give you non-removed stops
            var selectedStop = selectedRoute_WithOnlyNonRemovedStopsAndWithOrders.First();                                                                                                       //Select the first stop from the list

            //Save off details of the selectedStop for use later
            ScenarioContext.Current["SourceRouteDispatchDay"]       = (selectedStop.AdjustedDeliveryDateTime);
            ScenarioContext.Current["SourceRouteNumber"]            = selectedStop.RouteNumber;
            ScenarioContext.Current["SourceRouteId"]                = selectedStop.RouteId;
            ScenarioContext.Current["SourceStopNumber"]             = selectedStop.StopNumber;
            ScenarioContext.Current["SourceStopInitialTotalWeight"] = selectedStop.Weight;
            ScenarioContext.Current["SourceStopInitialTotalCubes"]  = selectedStop.Cubes;
            ScenarioContext.Current["SourceStopInitialTotalCases"]  = selectedStop.Cases;
        }
예제 #2
0
        public static Tuple <int, string, int> FindRandomRouteAndStopNumberWhichHasRemovedStatus(int centerNumber, DateTime filterStartDate, DateTime filterEndDate)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                DeepSearch      = true
            };
            var routes = SearchAsync(searchCriteria).Result;
            var listOfRoutes_WithRemovedStops = routes.Where(r =>
                                                             r.RouteStops.Any(s => s.RoutePlanModificationTypeId == 1 || s.RoutePlanModificationTypeId == 4)); // give you removed stops

            listOfRoutes_WithRemovedStops.Count().Should().BeGreaterOrEqualTo(1, "did not find any routes with at least 1 removed stop");
            var rand = new Random();
            //Randomly select one of the routes
            var selectedRoute = listOfRoutes_WithRemovedStops.ElementAt(rand.Next(listOfRoutes_WithRemovedStops.Count() - 1));

            var selectedRoute_ListOfRemovedStops = selectedRoute.RouteStops.Where(stop => stop.RoutePlanModificationTypeId == 1 || stop.RoutePlanModificationTypeId == 4); //Give you only removed stops in selectedRoute
            //Randomly select a removed stop from the selectedRoute
            var selectedStop = selectedRoute_ListOfRemovedStops.ElementAt(rand.Next(0, selectedRoute_ListOfRemovedStops.Count() - 1));
            var routeId      = selectedStop.RouteId;
            var routeNumber  = selectedStop.RouteNumber;
            var stopNumber   = Convert.ToInt32(selectedStop.StopNumber);

            return(Tuple.Create(routeId, routeNumber, stopNumber));
        }
예제 #3
0
        public async Task <ActionResult> Destination(int id, int centerNumber, string routeNumber, DateTime sourceStopPlannedDeliveryDateTime)
        {
            if (id != 0)
            {
                var model = new RouteViewModel(await RouteService.GetByRouteIdAndCenterNumberAndRouteNumberAsync(id, centerNumber, routeNumber));
                return(Json(JsonConvert.SerializeObject(model), JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (string.IsNullOrEmpty(routeNumber))
                {
                    return(null);
                }

                var weekending = Dates.GetWeekending(sourceStopPlannedDeliveryDateTime.Date).AddHours(12);
                var startWeek  = weekending.AddDays(-6);
                var criteria   = new SearchRoute
                {
                    CenterNumber    = centerNumber,
                    RouteNumber     = routeNumber,
                    FilterStartDate = startWeek,
                    FilterEndDate   = weekending
                };

                var routes = await RouteService.SearchAsync(criteria);

                if (routes == null || !routes.Any() || routes.Count() == 0)
                {
                    return(null);
                }

                var model = new RouteViewModel(routes.FirstOrDefault());
                return(Json(JsonConvert.SerializeObject(model), JsonRequestBehavior.AllowGet));
            }
        }
예제 #4
0
        public async Task <IEnumerable <Route> > SearchAsync(SearchRoute criteria)
        {
            var url = ApiUrl + $"search?DeepSearch={criteria.DeepSearch}";

            if (criteria.CenterNumber.HasValue && criteria.CenterNumber > 0)
            {
                url = url + $"&CenterNumber={criteria.CenterNumber}";
            }
            if (criteria.FilterStartDate.HasValue)
            {
                url = url + $"&FilterStartDate={criteria.FilterStartDate.Value}";
            }
            if (criteria.FilterEndDate.HasValue)
            {
                url = url + $"&FilterEndDate={criteria.FilterEndDate.Value}";
            }
            if (!string.IsNullOrEmpty(criteria.RouteName))
            {
                url = url + $"&RouteName={criteria.RouteName}";
            }
            if (!string.IsNullOrEmpty(criteria.RouteNumber))
            {
                url = url + $"&RouteNumber={criteria.RouteNumber}";
            }
            if (criteria.NearRouteId != 0)
            {
                url = url + $"&NearRouteId={criteria.NearRouteId}";
            }
            if (criteria.NearRoutePlanId != 0)
            {
                url = url + $"&NearRoutePlanId={criteria.NearRoutePlanId}";
            }
            if (criteria.BillTo != 0)
            {
                url = url + $"&BillTo={criteria.BillTo}";
            }
            if (criteria.ShipTo != 0)
            {
                url = url + $"&ShipTo={criteria.ShipTo}";
            }

            using (MiniProfiler.Current.Step("SearchAsync"))
            {
                var response = await _client.GetAsync(url);

                response.EnsureSuccessStatusCode();
                MiniProfiler.Current.TryAddMiniProfilerResultsFromHeader(response);
                var result = response.Content.ReadAsStringAsync().Result;
                return(JsonConvert.DeserializeObject <IEnumerable <Route> >(result));
            }
        }
예제 #5
0
        public static async Task <IEnumerable <Route> > SearchAsync(SearchRoute criteria)
        {
            var url = ApiUrl + $"Routes/search?DeepSearch={criteria.DeepSearch}";

            if (criteria.CenterNumber.HasValue && criteria.CenterNumber > 0)
            {
                url = url + $"&CenterNumber={criteria.CenterNumber}";
            }
            if (criteria.FilterStartDate.HasValue)
            {
                url = url + $"&FilterStartDate={criteria.FilterStartDate.Value}";
            }
            if (criteria.FilterEndDate.HasValue)
            {
                url = url + $"&FilterEndDate={criteria.FilterEndDate.Value}";
            }
            if (!string.IsNullOrEmpty(criteria.RouteName))
            {
                url = url + $"&RouteName={criteria.RouteName}";
            }
            if (!string.IsNullOrEmpty(criteria.RouteNumber))
            {
                url = url + $"&RouteNumber={criteria.RouteNumber}";
            }
            if (criteria.NearRouteId != 0)
            {
                url = url + $"&NearRouteId={criteria.NearRouteId}";
            }
            if (criteria.NearRoutePlanId != 0)
            {
                url = url + $"&NearRoutePlanId={criteria.NearRoutePlanId}";
            }
            if (criteria.BillTo != 0)
            {
                url = url + $"&BillTo={criteria.BillTo}";
            }
            if (criteria.ShipTo != 0)
            {
                url = url + $"&ShipTo={criteria.ShipTo}";
            }

            using (var client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                response.EnsureSuccessStatusCode();
                return(JsonConvert.DeserializeObject <IEnumerable <Route> >(response.Content.ReadAsStringAsync().Result));
            }
        }
예제 #6
0
        public static List <string> GetExpectedRoutesWithGivenBillToAndShipTo(int centerNumber, DateTime filterStartDate, DateTime filterEndDate, int billTo, int shipTo)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                BillTo          = billTo,
                ShipTo          = shipTo,
                DeepSearch      = false
            };
            var routes = SearchAsync(searchCriteria).Result;

            return(routes.Select(route => route.RouteNumber).ToList());
        }
예제 #7
0
        public static void FindValidBillToShipToValues(int centerNumber, DateTime filterStartDate, DateTime filterEndDate)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                DeepSearch      = true
            };
            var routes      = SearchAsync(searchCriteria).Result;
            var targetRoute = routes.Where(route => route.RouteStops.Count() > 4).First(); //get routes with at least 4 stops
            var targetStop  = targetRoute.RouteStops.ElementAt(3);                         //get stop at position 3

            ScenarioContext.Current["ExpectedRouteNumber"] = targetRoute.RouteNumber;      //Save off the route number for use later
            ScenarioContext.Current["ValidBillTo"]         = Convert.ToInt32(targetStop.BillTo);
            ScenarioContext.Current["ValidShipTo"]         = Convert.ToInt32(targetStop.ShipTo);
        }
예제 #8
0
        public static Tuple <int, string> FindRandomRouteWithOrdersAndIsDispatched(int centerNumber, DateTime filterStartDate, DateTime filterEndDate)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                DeepSearch      = true
            };
            var routes            = SearchAsync(searchCriteria).Result;
            var routes_WithOrders = routes.Where(route => route.NumberOfOrders > 1); //Returns routes where more than 1 order exists

            routes_WithOrders.Count().Should().BeGreaterOrEqualTo(1, $"should have found at least 1 route which contained at 1+ orders for center number {centerNumber}. Please try changing centers and rerunning test.");
            var route_WithOrders_AndDispatched = routes_WithOrders.Where(route => (route.RouteStops.OrderBy(s => s.StopNumber).FirstOrDefault().TelogisArrivalDeliveryDateTime.HasValue) || (route.RouteStops.Any(s => s.TelogisArrivalDeliveryDateTime.HasValue)));
            var selectedRoute = route_WithOrders_AndDispatched.ElementAt(rand.Next(route_WithOrders_AndDispatched.Count() - 1)); //Randomly selects one of the routes

            return(Tuple.Create(selectedRoute.RouteId, selectedRoute.RouteNumber));
        }
예제 #9
0
        public static void FindAnEligibleTargetRouteNumber(int centerNumber, DateTime filterStartDate, DateTime filterEndDate, int sourceRouteId)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate, //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate,   //Setting time to noon to match UI behavior
                DeepSearch      = false
            };
            var routes = SearchAsync(searchCriteria).Result;
            //Finds all routes excluding the given source route id
            var routes_ExcludingSourceRoute            = routes.Where(r => r.RouteId != sourceRouteId);                                                                      // give you all routes not including the source route id
            var routes_ExcludingSourceRoute_WithOrders = routes.Where(r => r.HasOrders.ToString() == "RouteHasSomeOrders" || r.HasOrders.ToString() == "RouteHasAllOrders"); // give you routes with orders
            //Gets routes that have not been dispatched
            var routes_ExcludingSourceRoute_WithOrders_AndNonDispatched = routes_ExcludingSourceRoute_WithOrders.Where(r => r.HasDispatched == false);                       // give you routes with at least 1 stop

            routes_ExcludingSourceRoute_WithOrders_AndNonDispatched.Count().Should().BeGreaterOrEqualTo(1, "should have found at least 1 eligible source route");
            var sourceRoute = routes_ExcludingSourceRoute_WithOrders_AndNonDispatched.ElementAt(rand.Next(routes_ExcludingSourceRoute_WithOrders_AndNonDispatched.Count() - 1));

            ScenarioContext.Current["TargetRouteId"]     = sourceRoute.RouteId;
            ScenarioContext.Current["TargetRouteNumber"] = sourceRoute.RouteNumber;
        }
예제 #10
0
        public static Tuple <int, string> FindRandomRouteWhichHasOrders(int centerNumber, DateTime filterStartDate, DateTime filterEndDate, int?routeIdToExclude = null)
        {
            var searchCriteria = new SearchRoute()
            {
                CenterNumber    = centerNumber,
                FilterStartDate = filterStartDate.AddHours(12.0), //Setting time to noon to match UI behavior
                FilterEndDate   = filterEndDate.AddHours(12.0),   //Setting time to noon to match UI behavior
                DeepSearch      = false
            };
            var routes = SearchAsync(searchCriteria).Result;

            if (routeIdToExclude != null)
            {
                //Remove the route we want to exclude from the possible list of routes
                routes = routes.Where(route => route.RouteId != routeIdToExclude);
            }
            var routes_WithOrders = routes.Where(route => route.NumberOfOrders > 1); //Returns routes where more than 1 order exists

            routes_WithOrders.Count().Should().BeGreaterOrEqualTo(1, $"should have found at least 1 route which contained at 1+ orders for center number {centerNumber}. Please try changing centers and rerunning test.");
            var selectedRoute = routes_WithOrders.ElementAt(rand.Next(routes_WithOrders.Count() - 1)); //Randomly selects one of the routes with orders

            return(Tuple.Create(selectedRoute.RouteId, selectedRoute.RouteNumber));
        }