Пример #1
0
        public void Add_should_not_invoke_service_when_ModelState_is_Invalid()
        {
            service.Setup(x => x.TryAdd(It.IsAny <Category>())).Verifiable();

            controller.ModelState.AddModelError("fake error", "fake error");
            var action = controller.Add(new EditCategory());

            Assert.That(action, Is.Not.Null);
            service.Verify(x => x.TryAdd(It.IsAny <Category>()), Times.Never());
        }
Пример #2
0
        public void AddValidDataTest()
        {
            _categoryServiceMock.Setup(c => c.AddAsync(It.IsAny <Category>())).Returns(Task.CompletedTask);
            var addAction = _categoryController.Add(_category);

            addAction.Wait();

            var result = addAction.Result as OkResult;

            result.StatusCode.Should().Be(200);
        }
        public async Task Add_ValidCategory_ReturnsOk()
        {
            Category category = new Category
            {
                CategoryId = 5,
                Name       = "Comedy",
                UserId     = 1
            };

            categoryRepositoryMock.Setup(cr => cr.AddCategory(category)).ReturnsAsync(5);

            var response = await categoryController.Add(category) as OkObjectResult;

            Assert.Equal(200, response.StatusCode);
        }
        public void Add_ReturnsCorrectView_True()
        {
            CategoryController controller = new CategoryController();
            ActionResult       addView    = controller.Add("apple", 1);

            Assert.IsInstanceOfType(addView, typeof(RedirectToActionResult));
        }
Пример #5
0
        private void saveCategoryEvent(object sender, RoutedEventArgs e)
        {
            categoryController.Add(categoryNameInput.Text);
            categoryNameInput.Clear();

            RefreshCategoryTable();
        }
        public async Task Cannot_Add_Invalid_Category()
        {
            Category category = new Category()
            {
                CategoryID = 1, Name = "Cat1"
            };

            _tofService.Setup(m => m.GetList()).Returns(new List <TypeOfFlow>()
            {
                new TypeOfFlow()
                {
                    TypeID = 1, TypeName = "Type1"
                },
                new TypeOfFlow()
                {
                    TypeID = 2, TypeName = "Type2"
                }
            });
            var target = new CategoryController(_tofService.Object, _planningHelper.Object, null, null);

            target.ModelState.AddModelError("error", "error");

            var result = await target.Add(new WebUser()
            {
                Id = "1"
            }, category);

            _catService.Verify(m => m.SaveAsync(), Times.Never);
            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
        }
Пример #7
0
        public void AddValidation_ConditionFalse()
        {
            CategoryViewModel cvm = new CategoryViewModel();

            CategoryController controller = new CategoryController();
            RedirectResult     result     = controller.Add(cvm) as RedirectResult;

            Assert.IsNull(result);
        }
Пример #8
0
        public void AddTest()
        {
            // Arrange
            var mock       = new Mock <ICategoryRepository>();
            var controller = new CategoryController(mock.Object);
            // Act
            var result = controller.Add(new WebApi.ViewModels.Category()
            {
                Name = "Category-Add-Test"
            }).Result as OkResult;

            //Assert
            Assert.AreEqual(StatusCodes.Status200OK, result.StatusCode);
        }
        public async Task Add_InputWebUser_ReturnsPartialView()
        {
            var target = new CategoryController(_tofService.Object, null, null, null);

            var result = await target.Add(new WebUser()
            {
                Id = "1"
            });

            var model = (result as PartialViewResult).ViewBag.TypesOfFlow;

            _tofService.Verify(m => m.GetListAsync(), Times.Exactly(1));
            Assert.IsInstanceOfType(model, typeof(IEnumerable <TypeOfFlow>));
            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
        }
        public async Task Can_Add_Valid_Category_Rerurns_RedirectToAction()
        {
            var target = new CategoryController(null, _planningHelper.Object, _catService.Object, null);

            var result = await target.Add(new WebUser()
            {
                Id = "1"
            }, new Category()
            {
                CategoryID = 1, Name = "Cat1"
            });

            _catService.Verify(m => m.CreateAsync(It.IsAny <Category>()), Times.Exactly(1));
            _planningHelper.Verify(m => m.CreatePlanItemsForCategory(It.IsAny <WebUser>(), It.IsAny <int>()), Times.Exactly(1));
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
Пример #11
0
        public void AddValidation_ConditionTrue()
        {
            CategoryViewModel cvm = new CategoryViewModel
            {
                categoryDTO = new T_M_CATEGORY
                {
                    CAT_ID   = "TINP",
                    CAT_NAME = "TEST INPUT"
                }
            };

            CategoryController    controller = new CategoryController();
            RedirectToRouteResult result     = controller.Add(cvm) as RedirectToRouteResult;

            Assert.AreEqual(result.RouteValues["action"], "Index");
        }
Пример #12
0
        public void Add()
        {
            T_M_CATEGORY categoryTest = new T_M_CATEGORY
            {
                CAT_ID = "TEST", CAT_NAME = "TEST NAME"
            };

            CategoryViewModel cvm = new CategoryViewModel
            {
                categoryDTO = categoryTest
            };

            CategoryController controller = new CategoryController();
            ViewResult         result     = controller.Add(cvm) as ViewResult;

            Index();
        }
Пример #13
0
        public void CreateTest()
        {
            CategoryVM vm = _controller.CreateVM <CategoryVM>();
            Category   v  = new Category();

            v.Name             = "RBJ";
            v.Seq              = 52;
            v.FileAttachmentId = AddFileAttachment();
            vm.Entity          = v;
            var rv = _controller.Add(vm);

            Assert.IsInstanceOfType(rv, typeof(OkObjectResult));

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Category>().FirstOrDefault();

                Assert.AreEqual(data.Name, "RBJ");
                Assert.AreEqual(data.Seq, 52);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
Пример #14
0
 private void ManageCategory_Click(object sender, RoutedEventArgs e)
 {
     if ((bool)ManageCategory.Tag)
     {
         if (!string.IsNullOrWhiteSpace(CategoryName.Text))
         {
             _category = new Category()
             {
                 Name      = CategoryName.Text,
                 IsDeleted = false
             };
             categoryController.Add(_category);
             ManageCategory.Content = LangPages.MBox.Change;
             ManageCategory.Tag     = false;
             MessageBox.Show(LangPages.MBox.AddCatToSystem);
         }
         else
         {
             MessageBox.Show(LangPages.MBox.YouMustSpecifyCategoryName);
             return;
         }
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(CategoryName.Text))
         {
             categoryController.Edit(_category.Id, CategoryName.Text);
             MessageBox.Show(LangPages.MBox.CatChange);
         }
         else
         {
             MessageBox.Show(LangPages.MBox.EmptyFieldNotAll);
             return;
         }
     }
 }
Пример #15
0
        private void dataGridViewCategories_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex == -1) //редактрование с второй строки
                {
                    return;
                }
                if (e.ColumnIndex == 2)
                {
                    string task = dataGridViewCategories.Rows[e.RowIndex].Cells[2].Value.ToString();

                    if (task == "Удалить")
                    {
                        if (MessageBox.Show("Удалить эту строку?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            int id = (int)dataGridViewCategories.CurrentRow.Cells[0].Value;
                            categoryController.Delete(id);
                        }
                    }
                    else if (task == "Добавить")
                    {
                        int      rowIndex    = dataGridViewCategories.Rows.Count - 2;
                        Category newCategory = GetCategoryInfo(rowIndex);
                        if (newCategory == null)
                        {
                            return;
                        }

                        int currentCategoryId = categoryController.GetCategoryIdByName(newCategory.Name);
                        if (currentCategoryId != 0)
                        {
                            MessageBox.Show("Введенная категория уже существует.");
                            return;
                        }

                        categoryController.Add(newCategory);
                        dataGridViewCategories.Rows[e.RowIndex].Cells["Операция"].Value = "Удалить";
                    }
                    else if (task == "Изм.")
                    {
                        int      rowIndex        = e.RowIndex;
                        Category updatedCategory = GetCategoryInfo(rowIndex);
                        if (updatedCategory == null)
                        {
                            return;
                        }

                        int currentCategoryId = categoryController.GetCategoryIdByName(updatedCategory.Name);
                        if (updatedCategory.ID != currentCategoryId && currentCategoryId != 0)
                        {
                            MessageBox.Show("Введенная категория уже существует.");
                            return;
                        }

                        categoryController.Edit(updatedCategory);
                        dataGridViewCategories.Rows[e.RowIndex].Cells["Операция"].Value = "Удалить";
                    }

                    categoryController.GetAllCategories(ref dataGridViewCategories);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #16
0
        public void InitDB()
        {
            if (userController.Get().Count == 0)
            {
                userController.AddAdmin();
                categoryController.Add(new Category()
                {
                    Name = "Техника безопасности"
                });
                categoryController.Add(new Category()
                {
                    Name = "Техника пожарной безопасности"
                });

                Category category = categoryController.Get()[0];

                for (int k = 0; k < 3; k++)
                {
                    List <Question> questions = new List <Question>();

                    for (int i = 0; i < 10; i++)
                    {
                        List <Answer> answers = new List <Answer>();
                        for (int j = 0; j < 3; j++)
                        {
                            if (j == 0)
                            {
                                answers.Add(new Answer()
                                {
                                    Text      = string.Format("{0} {1}", j, RandomString(23)),
                                    IsTrue    = true,
                                    IsDeleted = false
                                });
                            }
                            else
                            {
                                answers.Add(new Answer()
                                {
                                    Text      = string.Format("{0} {1}", j, RandomString(23)),
                                    IsTrue    = false,
                                    IsDeleted = false
                                });
                            }
                        }
                        questions.Add(new Question()
                        {
                            Text      = string.Format("{0} {1} ", i, RandomString(34)),
                            Answer    = answers,
                            IsDeleted = false,
                            Foto      = ConvertPicture.BitmapImageToByteArray(new BitmapImage(new Uri(@"C:\Users\Alex\source\repos\Survey\Survey\Pictures\Hamster.jpg", UriKind.Relative)))
                        });
                    }

                    surveyController.Add(new Survey.Model.Survey()
                    {
                        Name       = string.Format("{0} {1}", k, RandomString(25)),
                        CategoryId = category.Id,
                        Time       = 1,
                        Question   = questions
                    });
                }
            }
        }
 public int AddCategory(Category Category)
 {
     return(CategoryCtrl.Add(Category));
 }