public void Testar_Cadastro_Categoria() { // arrange var categoria = new CategoriaModel() { nome = "Supermercado" }; // act var result = controller.Create(categoria) as RedirectToRouteResult; // assert repositoryMock.Verify(x => x.Create(categoria), Times.Once()); Assert.AreEqual("Index", result.RouteValues["action"]); }
protected void btnCadastrar_Click(object sender, EventArgs e) { var model = new Model.Categoria(); try { if (String.IsNullOrEmpty(txtNome.Text)) { var validaNome = "O campo 'Nome' não pode estar em branco, favor verificar!"; ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('" + validaNome + "');", false); return; } model.Nome = txtNome.Text; model.Descricao = txtDescricao.Text; if (!chkAtivo.Checked) { model.Ativo = 0; // Inativo } else { model.Ativo = 1; // Ativo } _controller.Create(model); } catch { throw; } Response.Redirect("Index.aspx"); }
public void TestCreateNotNullAndView() { CategoriaController controller = new CategoriaController(); ViewResult result = controller.Create() as ViewResult; Assert.IsNotNull(result, "Null"); Assert.AreEqual("Create", result.ViewName, "ViewName"); }
public void Create() { CategoriaController categoriaController = new CategoriaController(); var result = categoriaController.Create() as ViewResult; Assert.IsNotNull(result.ViewName); }
public void TestCreateViewDataMock() { // 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 controller.Create(categoria); ViewResult result = controller.Details(nombreCategoria) as ViewResult; // Assert Assert.AreEqual(result.Model, categoria); }