public void AddCategory_ModelIsNotValid_ReturnRedirecToActionView()
        {
            var controller = new AdminController(mockService.Object, MockSignInManager.Object, mockUserManager.Object, mockRoleManager.Object);
            //Act
            var viewName = controller.AddCategory(new KategorijaViewModel {
                ImeKategorije = "Cizma"
            });

            //Assert
            Assert.IsInstanceOfType(viewName, typeof(RedirectToActionResult));
        }
        public async Task AddCategory_Test()
        {
            var    catCount = categories.Count;
            string newName  = "new name";

            var result = await controller.AddCategory(newName);

            var viewResult = Xunit.Assert.IsType <RedirectToActionResult>(result);

            Assert.AreEqual("GetItemsCategories", viewResult.ActionName);
            Assert.AreNotEqual(catCount, categories.Count);
        }
Beispiel #3
0
        public void AddCategory_Has_Specified_Id()
        {
            Mock <IMainCategoryByCitiesRepository> repository      = new Mock <IMainCategoryByCitiesRepository>();
            Mock <ITopicRepository> repositoryTopic                = new Mock <ITopicRepository>();
            Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>();

            AdminController controller = new AdminController(repositoryTopic.Object, repositoryInter.Object, repository.Object);

            IntermediateCategory category = (IntermediateCategory)((controller.AddCategory(1) as ViewResult).Model);

            Assert.AreEqual(1, category.MainCategoryByCitiesId);
        }
Beispiel #4
0
        public void AddCategory_Creates_New_Category()
        {
            //arrange
            Mock <IBusinessLogicLayer> mockOfBusinessLogicLayer = new Mock <IBusinessLogicLayer>();
            Mock <IUserLayer>          mockOfUserLayer          = new Mock <IUserLayer>();
            AdminController            target = new AdminController(mockOfBusinessLogicLayer.Object, mockOfUserLayer.Object);
            //act
            Category result = target.AddCategory().ViewData.Model as Category;

            //assert
            Assert.IsTrue(result.CategoryId == 0);
            Assert.IsTrue(result.Name == null);
        }
Beispiel #5
0
        public void Add_Category_Returns_True()
        {
            Mock <IMainCategoryByCitiesRepository> repository = new Mock <IMainCategoryByCitiesRepository>();

            repository.Setup(r => r.AddIntermediateCategory(It.IsAny <IntermediateCategory>())).Returns(true);
            Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>();
            Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>();

            IntermediateCategory category = new IntermediateCategory();

            AdminController controller = new AdminController(repositoryTopic.Object, repositoryInter.Object, repository.Object);

            ViewResult result   = controller.AddCategory(category) as ViewResult;
            string     viewName = result.ViewName;

            Assert.AreEqual("Error", viewName);
        }
Beispiel #6
0
        public void Add_Category_Dont_Save_InValid_Changes()
        {
            Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>();
            Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>();
            Mock <IMainCategoryByCitiesRepository> repositoryMain  = new Mock <IMainCategoryByCitiesRepository>();

            AdminController      controller = new AdminController(repositoryTopic.Object, repositoryInter.Object, repositoryMain.Object);
            IntermediateCategory category   = new IntermediateCategory()
            {
                NameOfMainCategory = null
            };

            controller.ModelState.AddModelError("NameOfMainCategory", "Pole nie może pozostawać puste");

            ActionResult result     = controller.AddCategory(category);
            ViewResult   resultView = (ViewResult)result;

            repositoryMain.Verify(x => x.AddIntermediateCategory(It.IsAny <IntermediateCategory>()), Times.Never);
            Assert.AreEqual(resultView.ViewName, "AddCategory");
        }
Beispiel #7
0
        public void Add_Category_Returns_False()
        {
            Mock <IMainCategoryByCitiesRepository> repository = new Mock <IMainCategoryByCitiesRepository>();

            repository.Setup(r => r.AddIntermediateCategory(It.IsAny <IntermediateCategory>())).Returns(false);
            Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>();
            Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>();

            IntermediateCategory category = new IntermediateCategory();

            category.MainCategoryByCitiesId = 12;

            AdminController controller = new AdminController(repositoryTopic.Object, repositoryInter.Object, repository.Object);

            RedirectToRouteResult result = controller.AddCategory(category) as RedirectToRouteResult;


            Assert.AreEqual(result.RouteValues["action"], "ChangeCategories");
            Assert.AreEqual(result.RouteValues["controller"], "Admin");
            Assert.AreEqual(result.RouteValues["id"], category.MainCategoryByCitiesId);
        }