Пример #1
0
        public void Category_Create_NotAdmin()
        {
            //Arrange
            var controller = new CategoryController(new CategoryBLL(new CategoryRepoStub()));

            var sessionMock = new TestControllerBuilder();
            sessionMock.InitializeController(controller);
            controller.Session["Admin"] = false;
            controller.Session["Email"] = "ole";

            string categoryName = "test name";

            //Act
            var viewResult = controller.Create(categoryName) as ViewResult;

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Only administrators can create categories", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Пример #2
0
        public void Category_Create_GoodInput()
        {
            //Arrange
            var controller = new CategoryController(new CategoryBLL(new CategoryRepoStub()));

            var sessionMock = new TestControllerBuilder();
            sessionMock.InitializeController(controller);
            controller.Session["Admin"] = true;
            controller.Session["Email"] = "admin";

            string categoryName = "test name";

            //Act
            var viewResult = controller.Create(categoryName) as ViewResult;

            //Assert
            Assert.AreEqual("Success", controller.ViewBag.Title);
            Assert.AreEqual("Category was added to the database", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }