Пример #1
0
        public async Task AddCategory_ModelIsValid_ReturnObjectResult()
        {
            _repository.Setup(x => x.AddCategory(It.IsAny <CategoryInformation>()));

            var result = await _controller.AddCategory(new CategoryInformation()
            {
                Name = "Example Name"
            });

            result.Should().BeOfType <OkResult>();
        }
        public void AddCategory_ReturnCreatedItem_WhenModelStateIsValid()
        {
            //Arrange
            var dbContext = new DocumentDbContext();

            dbContext.Categories = GetQueryableMockDbSetCategory();

            var categoryRepo = new CategoryRepo(string.Empty, dbContext);
            var controller   = new CategoryController(categoryRepo);

            AddCategoryModel addCategoryModel = new AddCategoryModel()
            {
                Title = "Tình Cảm"
            };

            //Act
            var result = controller.AddCategory(addCategoryModel);

            //Assert
            Assert.IsType <OkObjectResult>(result);

            var okObjectResult = result as OkObjectResult;

            Assert.IsType <Category>(okObjectResult.Value);

            var categoryObject = okObjectResult.Value as Category;

            Assert.Equal(categoryObject.Title, addCategoryModel.Title);
        }
Пример #3
0
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                CategoryInfo category = new CategoryInfo
                {
                    CategoryID       = _categoryId,
                    PortalID         = PortalId,
                    Name             = txtCategoryName.Text,
                    Description      = txtDescription.Text,
                    OrderID          = Convert.ToInt32(txtOrder.Text),
                    ParentCategoryID = Convert.ToInt32(ddlParentCategory.SelectedItem.Value),
                    Archived         = chkArchived.Checked,
                    Message          = txtMessage.Text,
                    CreatedByUser    = UserId.ToString(),
                    CreatedDate      = DateTime.Now
                };

                if (StoreSettings.SEOFeature)
                {
                    category.SEOName  = txtSEOName.Text;
                    category.Keywords = txtCategoryKeywords.Text;
                }

                if (_categoryId == Null.NullInteger)
                {
                    _controller.AddCategory(category);
                }
                else
                {
                    _controller.UpdateCategory(category);
                }
                InvokeEditComplete();
            }
        }
Пример #4
0
        private void btnAddCategory_Click(object sender, EventArgs e)
        {
            Categories category = new Categories();

            category.CategoryName = txtCategoryName.Text;
            category.Description  = txtCategoryDescription.Text;
            categoryController.AddCategory(category);
        }
Пример #5
0
 private void btnCategoryAdd_Click(object sender, EventArgs e)
 {
     Category category = new Category
     {
         CategoryName = txtCategoryName.Text,
         Description  = txtCategoryDescription.Text
     };
     bool isAdded = categoryController.AddCategory(category);
 }
        public void TestAddCategoryWithoutToken()
        {
            var mockCategoryService = new Mock <ICategoryService>();

            mockCategoryService.Setup(x => x.AddCategory(new CategoryRequest()));
            var controller             = new CategoryController(mockCategoryService.Object);
            IHttpActionResult response = controller.AddCategory(new CategoryRequest());
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsNotNull(contentResult.Content.Message);
        }
Пример #7
0
        public void AddCategoryShould_ReturnsView()
        {
            //Arrange
            var categoryServiceMock       = new Mock <ICategoryService>();
            CategoryController controller = new CategoryController(categoryServiceMock.Object);

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

            // Assert
            Assert.IsNotNull(result);
        }
Пример #8
0
        public void CategoryController_AddCategory_ReturnsNonNullViewResult()
        {
            //Arrange
            var mockCategoryRepository = new MockCategoryRepository();

            var controller = new CategoryController(mockCategoryRepository);
            //Act
            var result = controller.AddCategory() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
Пример #9
0
        public void AddCategoryShould_CallAddCategory()
        {
            //Arrange
            var categoryServiceMock       = new Mock <ICategoryService>();
            CategoryController controller = new CategoryController(categoryServiceMock.Object);
            Category           category   = new Category();
            CategoryViewModel  viewModel  = new CategoryViewModel(category);

            // Act
            controller.AddCategory(viewModel);

            // Assert
            categoryServiceMock.Setup(p => p.AddCategory(category)).Verifiable();
        }
Пример #10
0
 private void Add_Click(object sender, RoutedEventArgs e)
 {
     if (controller.AddCategory(category) > 0)
     {
         lbCategories.ItemsSource = null;
         lbCategories.ItemsSource = controller.GetCategories();
         lbCategories.ScrollIntoView(lbCategories.Items[lbCategories.Items.Count - 1]);
         MessageBox.Show("成功");
     }
     else
     {
         MessageBox.Show("失败");
     }
 }
Пример #11
0
        public void CategoryController_AddCategory_ChecksForInvalidModel()
        {
            //Arrange
            var mockCategoryRepository = new MockCategoryRepository();

            var controller = new CategoryController(mockCategoryRepository);
            var model      = new Category();
            //Act
            var result = controller.AddCategory(model) as ViewResult;
            //Assert


            //result.ViewName = "ErrorView";
        }
        public void Test_AddCategory()
        {
            var category = new Category
            {
                Id   = 103,
                Name = "save"
            };

            _mockService.Setup(x => x.AddCategory(category)).Returns(category);

            var actual = _sut.AddCategory(category.Name);

            Assert.IsNull(actual);
        }
        public void AddCategory_ReturnBadRequestResult_WhenModelStateIsInvalid()
        {
            //Arrange
            var mockRepo   = new Mock <ICategoryRepo>();
            var controller = new CategoryController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            //Act
            var result = controller.AddCategory(addCategoryModel: null);

            //Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        private void AddDataCategory_Click(object sender, RoutedEventArgs e)
        {
            CategoryController CallCategory = new CategoryController();

            if (CategoryTextBox.Text.Length == 0)
            {
                CategoryNameErrorMessage.Text = "You Must Enter Category Name!";
                CategoryTextBox.Focus();
            }
            else
            {
                string Cname = CategoryTextBox.Text;

                CallCategory.AddCategory(Cname);
            }
        }
        public void TestAddCategoryWithoutLogin()
        {
            var mockCategoryService = new Mock <ICategoryService>();

            mockCategoryService.Setup(x => x.AddCategory(new CategoryRequest()));
            var controller        = new CategoryController(mockCategoryService.Object);
            var controllerContext = new HttpControllerContext();
            var request           = new HttpRequestMessage();

            request.Headers.Add(ControllerHelper.TOKEN_NAME, new Guid().ToString());
            controllerContext.Request    = request;
            controller.ControllerContext = controllerContext;
            IHttpActionResult response = controller.AddCategory(new CategoryRequest());
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsNotNull(contentResult.Content.Message);
        }
Пример #16
0
        protected void btnAddCategory_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Session["categoryID"]);

            if (id != null && id != 0)
            {
                categoryController.ModifyCategory(categoryController.GetById(id).Id,
                                                  this.tbCategoryName.Text,
                                                  this.tbCategoryDescription.Text);
            }
            else
            {
                categoryController.AddCategory(categoryController.GetAllCategories().Count(),
                                               this.tbCategoryName.Text,
                                               this.tbCategoryDescription.Text);
            }

            Session["categoryID"] = null;
        }
        public void TestAddCategoryWithLogin()
        {
            string         token          = LoginContext.GetInstance().GenerateNewToken("1");
            UserContextDTO userContextDTO = GetUserContextDTO(token);

            LoginContext.GetInstance().SaveContext(userContextDTO);
            var mockCategoryService = new Mock <ICategoryService>();

            mockCategoryService.Setup(x => x.AddCategory(categoryRequest));
            var controller        = new CategoryController(mockCategoryService.Object);
            var controllerContext = new HttpControllerContext();
            var request           = new HttpRequestMessage();

            request.Headers.Add(ControllerHelper.TOKEN_NAME, token);
            controllerContext.Request    = request;
            controller.ControllerContext = controllerContext;
            IHttpActionResult response = controller.AddCategory(categoryRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsTrue(contentResult.Content.Success);
        }
Пример #18
0
        private void btnAddCategory_Click(object sender, EventArgs e)
        {
            Category category = new Category
            {
                CategoryName = txtCategoryName.Text,
                Description  = txtCategoryDescription.Text
            };

            ReturnMessage message = categoryController.AddCategory(category);

            MessageBox.Show(message.Value);
            if (message.isSuccessful)
            {
                foreach (Control control in grpControls.Controls)
                {
                    if (control is TextBox)
                    {
                        TextBox textBox = control as TextBox;
                        textBox.Text = string.Empty;
                    }
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Handles the RowInserting event of the gvCategorySettings control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DevExpress.Web.Data.ASPxDataInsertingEventArgs"/> instance containing the event data.</param>
        protected void gvCategorySettings_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            if (UserId == AnonymousUserId && !AllowAnonymousEdits)
            {
                ShowError("Login required to save categories.");
                e.Cancel = true;
                return;
            }
            else
            {
                CategoryController objCategories = new CategoryController();
                CategoryInfo       category      = ReadCategory(e.NewValues);
                category.UserId = UserId;

                objCategories.AddCategory(category);

                ASPxGridView gv = (ASPxGridView)sender;
                gv.DataSource = GetCategories(UserId, NoCategoryId, null);
                gv.DataBind();
                gv.CancelEdit();
                e.Cancel = true;
            }
        }
        public void AddCategoryTest()
        {
            var result = _CategoryController.AddCategory() as ViewResult;

            Assert.AreEqual("AddCategory", result.ViewName);
        }
Пример #21
0
        //if add category is clicked this event is triggered

        private void AddCategory_click(object sender, RoutedEventArgs e)
        {
            string title = txt_category_title.Text;

            categoryController.AddCategory(title);
        }