public void TestIndexNotNullAndView()
        {
            FormularioController controller = new FormularioController();
            ViewResult           result     = controller.Index(1) as ViewResult;

            Assert.IsNotNull(result, "Null");
            Assert.AreEqual("Index", result.ViewName, "ViewName");
        }
Beispiel #2
0
        public void Index()
        {
            // Arrange
            FormularioController controller = new FormularioController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void TestIndexViewDataMock()
        {
            // Arrange
            var formularios = new List <Formulario>
            {
                new Formulario()
                {
                    CodigoFormulario = "100001", Nombre = "Programación I"
                },
                new Formulario()
                {
                    CodigoFormulario = "100002", Nombre = "Programación II"
                },
                new Formulario()
                {
                    CodigoFormulario = "100003", Nombre = "Bases de Datos"
                },
                new Formulario()
                {
                    CodigoFormulario = "100004", Nombre = "Ingeniería de Software"
                }
            }.AsQueryable();

            var mockDbSet = new Mock <DbSet <Formulario> >();

            mockDbSet.As <IQueryable <Formulario> >().Setup(m => m.Provider).Returns(formularios.Provider);
            mockDbSet.As <IQueryable <Formulario> >().Setup(m => m.Expression).Returns(formularios.Expression);
            mockDbSet.As <IQueryable <Formulario> >().Setup(m => m.ElementType).Returns(formularios.ElementType);
            mockDbSet.As <IQueryable <Formulario> >().Setup(m => m.GetEnumerator()).Returns(formularios.GetEnumerator());

            var mockDb = new Mock <Opiniometro_DatosEntities>();

            mockDb.Setup(m => m.Formulario).Returns(mockDbSet.Object);
            FormularioController controller = new FormularioController(mockDb.Object);

            // Act
            ViewResult result = controller.Index(1) as ViewResult;

            //List<Formulario> formulario = (List<Formulario>)result.ViewData.Model;

            // Assert
            //Assert.AreEqual(4, formulario.Count);
            Assert.AreEqual("Index", result.ViewName, "ViewName");
        }