public void Get_ReturnsNotFoundResult_NoRuns() { var mapper = MapperService.DefaultMapper(); IEnumerable <Run> runs = null; var mockRepo = new Mock <IRunRepository>(); mockRepo.Setup(repo => repo.GetAllRuns()) .ReturnsAsync(runs); var controller = new RunController(mockRepo.Object, mapper); var result = controller.Get(); var NotFoundResult = Assert.IsType <NotFoundResult>(result.Result.Result); Assert.Equal(404, NotFoundResult.StatusCode); }
public void GetById_ReturnNotFoundResult_NoRun() { var mapper = MapperService.DefaultMapper(); Run run = null; var mockRepo = new Mock <IRunRepository>(); mockRepo.Setup(repo => repo.GetRun(It.IsAny <int>())) .ReturnsAsync(run); var controller = new RunController(mockRepo.Object, mapper); var result = controller.Get(1); var notFoundResult = Assert.IsType <NotFoundResult>(result.Result.Result); Assert.Equal(404, notFoundResult.StatusCode); }
public void Get_ReturnsOkResult_WithAllRuns() { var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IRunRepository>(); mockRepo.Setup(repo => repo.GetAllRuns()) .ReturnsAsync(GetRuns()); var controller = new RunController(mockRepo.Object, mapper); var result = controller.Get(); var okResult = Assert.IsType <OkObjectResult>(result.Result.Result); Assert.Equal(200, okResult.StatusCode); var items = Assert.IsAssignableFrom <IEnumerable <RunViewModel> >(okResult.Value); Assert.Equal(2, items.Count()); }
public void GetById_ReturnOkResult_WithRun() { var mapper = MapperService.DefaultMapper(); var run = GetRuns()[0]; var mockRepo = new Mock <IRunRepository>(); mockRepo.Setup(repo => repo.GetRun(It.IsAny <int>())) .ReturnsAsync(run); var controller = new RunController(mockRepo.Object, mapper); var result = controller.Get(1); var okResult = Assert.IsType <OkObjectResult>(result.Result.Result); Assert.Equal(200, okResult.StatusCode); var item = Assert.IsAssignableFrom <RunViewModel>(okResult.Value); Assert.Equal(1, item.RunId); }