public void WhenExistsFromAndToDestinyThenFindByDijkstraImplementation() { var listRouteValue = new List <RouteValue>(); routeRepository.GetAll().Returns(listRouteValue); var listNode = new List <Node>(); var nodeFrom = new Node(FROM); var nodeTo = new Node(TO); listNode.Add(nodeFrom); listNode.Add(nodeTo); graphCreator.CreateNodes(listRouteValue).Returns(listNode); var bestRoute = new BestRoute(); dijkstraImplementation.FindBestRoute(nodeFrom, nodeTo).Returns(bestRoute); var route = new Route(FROM, TO); var result = dijkstraLowestPriceFinder.Find(route); Assert.AreEqual(bestRoute, result); routeRepository.Received().GetAll(); graphCreator.Received().CreateNodes(listRouteValue); dijkstraImplementation.Received().FindBestRoute(nodeFrom, nodeTo); }
public BestRoute Find(Route route) { var routes = routeRepository.GetAll(); List <Node> nodes = graphCreator.CreateNodes(routes); var nodeFrom = nodes.FirstOrDefault(node => node.Label == route.From); var nodeTo = nodes.FirstOrDefault(node => node.Label == route.To); if (nodeFrom == null) { throw new DestinyException(route.From); } if (nodeTo == null) { throw new DestinyException(route.To); } return(dijkstraImplementation.FindBestRoute(nodeFrom, nodeTo)); }