public void Index_Returns_View_with_Values()
        {
            var expected_values = new[] { "1", "2", "3" };

            var values_service_mock = new Mock <IValuesServices>();

            values_service_mock
            .Setup(service => service.Get())
            .Returns(expected_values);

            var controller = new WebAPIController(values_service_mock.Object); // "Стаб"

            var result = controller.Index();

            var view_result = Assert.IsType <ViewResult>(result);

            var model = Assert.IsAssignableFrom <IEnumerable <string> >(view_result.Model);

            Assert.Equal(expected_values.Length, model.Count());

            //"Мок"

            values_service_mock.Verify(service => service.Get());
            values_service_mock.VerifyNoOtherCalls();
        }
예제 #2
0
        public void Index_Returns_View_with_Values()
        {
            //Arrange
            Mock <IValuesService> valueServiceMock     = new Mock <IValuesService>();
            IEnumerable <string>  expectedStringValues = new[] { "1", "2", "3" };

            valueServiceMock.Setup((x) => x.Get()).Returns(() => expectedStringValues);

            WebAPIController controller = new WebAPIController(valueServiceMock.Object);

            //Act
            var actionResult = controller.Index();

            //Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(actionResult);

            Assert.Equal(expectedStringValues, (viewResult.Model as IEnumerable <string>));
            valueServiceMock.Verify(service => service.Get(), Times.Exactly(1));
            valueServiceMock.VerifyNoOtherCalls();
        }