Esempio n. 1
0
        public void IndexTest()
        {
            var controller = new CategoriaController();
            var result     = controller.Index();

            Assert.IsNotNull(result);
        }
        public void TestIndexNotNullAndView()
        {
            CategoriaController controller = new CategoriaController();
            ViewResult          result     = controller.Index() as ViewResult;

            Assert.IsNotNull(result, "Null");
            Assert.AreEqual("Index", result.ViewName, "ViewName");
        }
Esempio n. 3
0
        public void Delete()
        {
            CategoriaController categoriaController = new CategoriaController();

            var result = categoriaController.Index() as ViewResult;

            Assert.IsNotNull(result.ViewName);
        }
        public void TestIndexViewDataMock()
        {
            // Arrange
            var categorias = new List <Categoria>
            {
                new Categoria()
                {
                    NombreCategoria = "Profesor"
                },
                new Categoria()
                {
                    NombreCategoria = "Estudiante"
                },
                new Categoria()
                {
                    NombreCategoria = "Asistente"
                },
                new Categoria()
                {
                    NombreCategoria = "Curso"
                }
            }.AsQueryable();

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

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

            var mockDb = new Mock <Opiniometro_DatosEntities>();

            mockDb.Setup(m => m.Categoria).Returns(mockDbSet.Object);
            CategoriaController controller = new CategoriaController(mockDb.Object);

            // Act
            ViewResult       result    = controller.Index() as ViewResult;
            List <Categoria> categoria = (List <Categoria>)result.ViewData.Model;

            // Assert
            Assert.AreEqual(4, categoria.Count);
        }
        public void Testar_Listagem_Categorias_E_Retornar_Tela_Index()
        {
            // arrange
            var categorias = new List <CategoriaModel>();

            categorias.Add(new CategoriaModel()
            {
                nome = "Supermercado"
            });
            categorias.Add(new CategoriaModel()
            {
                nome = "Restaurante"
            });
            categorias.Add(new CategoriaModel()
            {
                nome = "Borracharia"
            });
            categorias.Add(new CategoriaModel()
            {
                nome = "Posto"
            });
            categorias.Add(new CategoriaModel()
            {
                nome = "Oficina"
            });

            repositoryMock.Setup(x => x.GetAll()).Returns(categorias);

            // act
            var result = controller.Index() as ViewResult;

            // assert
            var model = result.ViewData.Model as List <CategoriaModel>;

            Assert.AreEqual(5, model.Count);

            Assert.AreEqual("Index", result.ViewName);
        }