public void SetUp() { visitor = new RouteVisitor(); route = MockRepository.GenerateMock<IRouteDefinition>(); chain = new BehaviorChain(); processor = MockRepository.GenerateMock<RouteProcessor>(); visitor.Actions += (x, y) => processor.Got(x, y); }
public IEnumerable <PlaceDto> GetBestRoute(string originName, string destinationName, string criteria) { if (string.IsNullOrEmpty(originName) && string.IsNullOrEmpty(destinationName)) { throw new ArgumentException("The Origin and Destination are required fields."); } var origin = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(originName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); var destination = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(destinationName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (origin == null) { throw new InvalidOperationException("The Origin provided does not exist."); } if (destination == null) { throw new InvalidOperationException("The Destination provided does not exist."); } //Retrieve filter criteria //if the passed criteria is null, the default value is Cost //if find a match will return a RouteCriteria type //if the passed value doesn't exist, will throw an exception RouteCriteria criteriaRoute = string.IsNullOrEmpty(criteria) ? RouteCriteria.Cost : RouteCriteria.FromDisplayName <RouteCriteria>(criteria); //retrieve routes and places from DB var routes = _readRepository.GetAllIncluding(x => x.Origin, x => x.Destination).ToList(); var places = _readUnit.ReadRepository <Place>().GetAll().ToList(); //create the graph network RoutingGraph <Place> graph = new RoutingGraph <Place>(); places.ForEach(x => graph.AddNode(x)); routes.ForEach(r => { int cost = RouteCriteria.Equals(criteriaRoute, RouteCriteria.Time) ? r.Time : r.Cost; graph.Connect(r.Origin, r.Destination, cost); }); //processa o resultado var processor = new RouteProcessor <Place>(graph); IPathResult result = processor.Process(origin, destination); //build the result List <Place> resultados = new List <Place>(); result.GetPath().ToList().ForEach(x => resultados.Add(graph[x].Item)); return(resultados.EnumerableTo <PlaceDto>()); }
public override string ToString() { return($"{nameof(RouteProcessor)}: {RouteProcessor.GetType().Name}, {nameof(Options)}: {Options}"); }