public async Task FindPathsBetweenNodes_ReturnsAnEmptyList() { // Arrange var mockPointsRepo = new Mock <IPointsRepository>(); mockPointsRepo.Setup(repo => repo.GetPointByName("A")).Returns(Task.FromResult(GetTestPoints("A"))); mockPointsRepo.Setup(repo => repo.GetPointByName("B")).Returns(Task.FromResult(GetTestPoints("B"))); mockPointsRepo.Setup(repo => repo.GetPointByName("C")).Returns(Task.FromResult(GetTestPoints("C"))); mockPointsRepo.Setup(repo => repo.GetPointByName("D")).Returns(Task.FromResult(GetTestPoints("D"))); var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(1)).Returns(Task.FromResult(GetTestRoutes(1))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(2)).Returns(Task.FromResult(GetTestRoutes(2))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(3)).Returns(Task.FromResult(GetTestRoutes(3))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(4)).Returns(Task.FromResult(GetTestRoutes(4))); var service = new PathsService(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await service.FindPathsBetweenNodes("A", "A"); // Assert var model = Assert.IsAssignableFrom <List <Path> >(result); Assert.Empty(result); }
public async Task FindPathsBetweenNodes_ReturnsAListOfPaths() { // Arrange var mockPointsRepo = new Mock <IPointsRepository>(); mockPointsRepo.Setup(repo => repo.GetPointByName("A")).Returns(Task.FromResult(GetTestPoints("A"))); mockPointsRepo.Setup(repo => repo.GetPointByName("B")).Returns(Task.FromResult(GetTestPoints("B"))); mockPointsRepo.Setup(repo => repo.GetPointByName("C")).Returns(Task.FromResult(GetTestPoints("C"))); mockPointsRepo.Setup(repo => repo.GetPointByName("D")).Returns(Task.FromResult(GetTestPoints("D"))); mockPointsRepo.Setup(repo => repo.GetPointByName("E")).Returns(Task.FromResult(GetTestPoints("E"))); mockPointsRepo.Setup(repo => repo.GetPointByName("F")).Returns(Task.FromResult(GetTestPoints("F"))); mockPointsRepo.Setup(repo => repo.GetPointByName("G")).Returns(Task.FromResult(GetTestPoints("G"))); mockPointsRepo.Setup(repo => repo.GetPointByName("H")).Returns(Task.FromResult(GetTestPoints("H"))); mockPointsRepo.Setup(repo => repo.GetPointByName("I")).Returns(Task.FromResult(GetTestPoints("I"))); var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(1)).Returns(Task.FromResult(GetExerciseTestRoutes(1))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(2)).Returns(Task.FromResult(GetExerciseTestRoutes(2))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(3)).Returns(Task.FromResult(GetExerciseTestRoutes(3))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(4)).Returns(Task.FromResult(GetExerciseTestRoutes(4))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(5)).Returns(Task.FromResult(GetExerciseTestRoutes(5))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(6)).Returns(Task.FromResult(GetExerciseTestRoutes(6))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(7)).Returns(Task.FromResult(GetExerciseTestRoutes(7))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(8)).Returns(Task.FromResult(GetExerciseTestRoutes(8))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(9)).Returns(Task.FromResult(GetExerciseTestRoutes(9))); var service = new PathsService(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await service.FindPathsBetweenNodes("A", "B"); // Assert var model = Assert.IsAssignableFrom <List <Path> >(result); Assert.Equal(5, result.Count); }
public async Task FindPathsBetweenNodes_ReturnsAnList_WithoutDirectPaths() { // Arrange var mockPointsRepo = new Mock <IPointsRepository>(); mockPointsRepo.Setup(repo => repo.GetPointByName("A")).Returns(Task.FromResult(GetTestPoints("A"))); mockPointsRepo.Setup(repo => repo.GetPointByName("B")).Returns(Task.FromResult(GetTestPoints("B"))); mockPointsRepo.Setup(repo => repo.GetPointByName("C")).Returns(Task.FromResult(GetTestPoints("C"))); mockPointsRepo.Setup(repo => repo.GetPointByName("D")).Returns(Task.FromResult(GetTestPoints("D"))); var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(1)).Returns(Task.FromResult(GetTestRoutes(1))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(2)).Returns(Task.FromResult(GetTestRoutes(2))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(3)).Returns(Task.FromResult(GetTestRoutes(3))); mockRoutesRepo.Setup(repo => repo.GetRoutesByOrigin(4)).Returns(Task.FromResult(GetTestRoutes(4))); var service = new PathsService(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await service.FindPathsBetweenNodes("A", "D"); // Assert var model = Assert.IsAssignableFrom <List <Path> >(result); Assert.Equal(2, result.Count); foreach (Path p in result) { Assert.NotEqual(2, p.Points.Count); } }
public PathsController(PathsService PathsService) { _PathsService = PathsService; }