예제 #1
0
        public void Run()
        {
            try
            {
                List <RouteViewModel> routesViewModel = ReadAndSerializer <RouteViewModel>(GetPathFile("trechos.txt"));
                List <OrderViewModel> ordersViewModel = ReadAndSerializer <OrderViewModel>(GetPathFile("encomendas.txt"));

                var routes = _routeService.CreateListRoutes(routesViewModel);

                var paths = ordersViewModel.Select(order =>
                {
                    var cityOrigin      = _cityService.FindByCode(order.CityOrigin);
                    var cityDestination = _cityService.FindByCode(order.CityDestination);
                    return(_shortestPathFinder.FindShortestPath(cityOrigin, cityDestination, s => GetNeighbors(s, routes)));
                });

                var textPaths = _textSerializer.SerializeList(paths);
                _fileService.WriteAllText(GetPathFile("rotas.txt"), textPaths);

                _logger.LogDebug("{paths}", textPaths);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                _fileService.WriteAllText(GetPathFile("rotas.txt"), "Could not calculate directions. " + e.Message);
            }
        }
예제 #2
0
        public void CreateListRoutes()
        {
            var listRoute = new List <RouteViewModel>
            {
                new RouteViewModel(cityExpected1.Code, cityExpected2.Code, 1),
                new RouteViewModel(cityExpected2.Code, cityExpected1.Code, 2)
            };

            routeService.CreateListRoutes(listRoute);

            mockListRoute.Verify(c => c.Add(It.IsAny <RouteEntity>()), Times.Exactly(listRoute.Count));
        }