public async Task TestFindShortestRouteBetweenAsync() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new RoutesDijkstra(cities); routes.ReadRoutes(LinksTestFile); // do synchronous execution linksExpected = routes.FindShortestRouteBetween("Basel", "Zürich", TransportModes.Rail); // do asynchronous execution linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportModes.Rail); // not test the results Assert.IsNotNull(linksActual); Assert.AreEqual(linksExpected.Count, linksActual.Count); for (int i = 0; i < linksActual.Count; i++) { Assert.AreEqual(linksExpected[i].FromCity, linksActual[i].FromCity); Assert.AreEqual(linksExpected[i].ToCity, linksActual[i].ToCity); } }
public async Task TestFindShortestRouteBetweenAsyncProgress() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new RoutesDijkstra(cities); routes.ReadRoutes(LinksTestFile); var progress = new Progress<string>(ProgressReport); // do asynchronous execution linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportModes.Rail, progress); await Task.Delay(1000); // the following assert has to be made after the routine routine returns // assert, that in minimum 5 progress calls are made Assert.IsTrue(progCount >= 5, "less than 5 progress calls"); // See comment in ProgressReport method Assert.IsFalse(doneMissing, String.Format("the progress message \"{0}\" does not contain \"done\"", failingMessage)); }