Ejemplo n.º 1
0
        public void AddingNewCategory()
        {
            var category = new Category()
            {
                Description = "Electrodomésticos"
            };

            //Setup

            dataServiceMock.Setup(m => m.Insert <Category>(category))
            .Returns(new Category()
            {
                CategoryId = 6, Description = category.Description
            })
            .Verifiable();


            //Act

            var categoryManager  = new CategoriesManager(dataServiceMock.Object);
            var categoryExpected = categoryManager.Add(category);

            //Assert

            dataServiceMock.Verify();
            Assert.AreEqual(6, categoryExpected.CategoryId);
            Assert.AreEqual(categoryExpected.Description, category.Description);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Add_Category add_Category = new Add_Category();

            if (add_Category.ShowDialog() == DialogResult.OK)
            {
                string categoryName = add_Category.Name;
                CategoriesManager.Add(categoryName);
                LoadCategory();
            }
        }
Ejemplo n.º 3
0
        public void AddingExistCategory()
        {
            var category = new Category()
            {
                Description = "Lacteos"
            };

            //Act

            var categoryManager = new CategoriesManager(dataServiceMock.Object);

            Assert.ThrowsException <Exception>(() => categoryManager.Add(category));
        }
Ejemplo n.º 4
0
        protected void AddButton_Click1(object sender, EventArgs e)
        {
            try
            {
                Category _Category = new Category();
                _Category.Code = (txtCategoryCode.Text);
                _Category.Name = txtCategoryName.Text;

                if (IdHiddenField.Value == "")
                {
                    int success = _CategoriesManager.Add(_Category);
                    if (success > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successefully Saved Category');", true);

                        txtCategoryName.Text = "";
                        IdHiddenField.Value  = "";
                        //Response.Redirect(Request.Url.AbsoluteUri);
                        AutoCodeGenerate();
                        LoadCategories();
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed Saved Category');", true);
                    }
                }
                else
                {
                    int UpdateSuccess = _CategoriesManager.Update(_Category);
                    if (UpdateSuccess > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successefully Update Category');", true);

                        txtCategoryName.Text = "";
                        IdHiddenField.Value  = "";
                        AutoCodeGenerate();
                        LoadCategories();
                        AddButton.Text       = "Add";
                        DeleteButton.Visible = false;
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed Update Category');", true);
                    }
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "');", true);
            }
        }