示例#1
0
        protected void gvCategorias_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // Detectando a linha que foi clicada
            int linha = Convert.ToInt32(e.CommandArgument);

            // Recuperando o id do Objeto (lembrando que 2, do Cells[2], é a coluna onde esta o id)
            int idObjeto  = Convert.ToInt32(gridCategorias.Rows[linha].Cells[2].Text);
            var categoria = _controller.GetById(idObjeto);

            // Nome do comando para saber a acao
            string command = e.CommandName;

            // Proximos passos

            // adicionar id na Session

            if (command.Equals("Delete"))
            {
                _controller.Delete(categoria);
                Response.Redirect("Index.aspx");
                // Redirecionando para tela de exclusao
                //Response.Redirect("Excluir.aspx");
            }
            else
            {
                if (command.Equals("Edit"))
                {
                    var categoriaId = categoria.Id;
                    Convert.ToString(categoriaId);
                    // Redirecionando para tela de edicao
                    Response.Redirect("Editar.aspx?Id=" + categoriaId);
                }
            }
        }
        public void RemoverCategoria()
        {
            var controller = new CategoriaController(CategoriaRepositoryFake.Create());

            controller.Delete(3);

            var categoria = controller.Get(3);

            Assert.IsTrue(categoria == null);
        }
        public void Delete_Categoria_Return_BadRequestResult()
        {
            //Arrange
            var controller = new CategoriaController(repositorio, mapper);
            int?catId      = null;

            //Act
            var data = controller.Delete(catId);

            //Assert
            Assert.IsType <BadRequestResult>(data.Result);
        }
        public void Delete_Categoria_Return_NotFoundResult()
        {
            //Arrange
            var controller = new CategoriaController(repositorio, mapper);
            var catId      = 999999;

            //Act
            var data = controller.Delete(catId);

            //Assert
            Assert.IsType <NotFoundResult>(data.Result);
        }
        public void Delete_Categoria_Return_OkResult()
        {
            //Arrange
            var controller = new CategoriaController(repositorio, mapper);
            var catId      = 14;

            //Act
            var data = controller.Delete(catId);

            //Assert
            Assert.IsType <CategoriaDTO>(data.Value);
        }
        public async Task Delete_ShouldSetActiveEqualFalse()
        {
            // Arrange
            await CreateAndCommit("categorias/TestDelete", true, null, null, "Delete Test");

            // Act
            await categoriaController.Delete("TestDelete");

            var result = await serviceBase.FindAsync("categorias/TestDelete");

            // Assert
            Assert.False(result.Active);
        }
        public void TestDeleteViewDataMock()
        {
            // Arrange
            var       mockDb          = new Mock <Opiniometro_DatosEntities>();
            string    nombreCategoria = "Profesor";
            Categoria categoria       = new Categoria()
            {
                NombreCategoria = "Profesor"
            };

            mockDb.Setup(m => m.Categoria.Find(nombreCategoria)).Returns(categoria);
            CategoriaController controller = new CategoriaController(mockDb.Object);

            // Act
            ViewResult result = controller.Delete(nombreCategoria) as ViewResult;

            // Assert
            Assert.AreEqual(result.Model, categoria);
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show(
                "Quiere borrar esta categoría?",
                "Confirme acción",
                MessageBoxButtons.YesNo
                );

            if (confirmResult == DialogResult.Yes)
            {
                if (controller.Delete(categoria.CategoriaId))
                {
                    MessageBox.Show("Categoría borrada correctamente.");
                    controller.Dispose();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error al borrar la categoría.");
                }
            }
        }