public void GetAll_Calls_Repository() { // Arrange var mockRepo = new Mock <IColourRepository>(); mockRepo.Setup(repo => repo.GetAll()).Returns(GetTestColours().AsEnumerable()); var controller = new ColoursController(mockRepo.Object); // Act controller.GetAll(); // Assert mockRepo.Verify(mock => mock.GetAll(), Times.Once()); }
public void GetAll_Returns_Ok() { // Arrange var mockRepo = new Mock <IColourRepository>(); mockRepo.Setup(repo => repo.GetAll()).Returns(GetTestColours().AsEnumerable()); var controller = new ColoursController(mockRepo.Object); // Act var result = controller.GetAll(); // Assert Assert.IsInstanceOfType(result, typeof(OkObjectResult)); }
public void GetAll_Returns_Empty_List() { // Arrange var mockRepo = new Mock <IColourRepository>(); mockRepo.Setup(repo => repo.GetAll()).Returns(EmptyList); var controller = new ColoursController(mockRepo.Object); // Act var result = controller.GetAll(); var objectResult = result as OkObjectResult; var value = objectResult?.Value as IEnumerable <Colour>; // Assert Assert.IsInstanceOfType(value, typeof(IEnumerable <Colour>)); Assert.AreEqual(0, value?.Count()); }
public void GetAll_Returns_Colours() { // Arrange var mockRepo = new Mock <IUnitofWork>(); var colours = GetTestColours(); mockRepo.Setup(repo => repo.Colors.GetAll()).Returns(colours.AsEnumerable()); var controller = new ColoursController(mockRepo.Object); // Act var result = controller.GetAll(); var objectResult = result as OkObjectResult; var value = objectResult?.Value as IEnumerable <Colour>; // Assert Assert.IsInstanceOfType(value, typeof(IEnumerable <Colour>)); Assert.AreEqual(colours.Count, value?.Count()); }