public void GetCypherByIdNotFound(int id) { // Given Mock <ICypherRepository> mockRepo = new Mock <ICypherRepository>(); mockRepo.Setup(repo => repo.Get(It.IsAny <int>())).Returns <int>((i) => { return(Task.FromResult(cyphers.FirstOrDefault(c => c.Id == i))); }); CyphersController controller = new CyphersController(mockRepo.Object); // When IActionResult result = controller.GetById(id); // Then Assert.NotNull(result); var objectResult = Assert.IsType <NotFoundResult>(result); }
public void GetCyphers() { // Given Mock <ICypherRepository> mockRepo = new Mock <ICypherRepository>(); mockRepo.Setup(repo => repo.Get()).ReturnsAsync(cyphers.ToList()); CyphersController controller = new CyphersController(mockRepo.Object); // When IEnumerable <Cypher> results = controller.GetAll(); List <Cypher> listResults = results.ToList(); // Then Assert.Equal(3, results.Count()); Assert.Equal(1, listResults[0].Id); Assert.Equal("Cypher 1", listResults[0].Name); Assert.Equal(2, listResults[1].Id); Assert.Equal("Cypher 2", listResults[1].Name); Assert.Equal(3, listResults[2].Id); Assert.Equal("Cypher 3", listResults[2].Name); }