Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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());
        }