Exemplo n.º 1
0
        public void Category_Delete_NoIdentifierFound()
        {
            //Arrange
            var controller = new CategoryController(new CategoryBLL(new CategoryRepoStub())
                , new AccountBLL(new AccountRepoStub()));

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

            string categoryId = "2";

            //Act
            var viewResult = controller.Delete(categoryId) as ViewResult;

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Cannot perform admin tasks without a valid email", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Exemplo n.º 2
0
        public void Category_Delete_NotAdmin()
        {
            //Arrange
            var controller = new CategoryController(new CategoryBLL(new CategoryRepoStub())
                , new AccountBLL(new AccountRepoStub()));

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

            string categoryId = "2";

            //Act
            var viewResult = controller.Delete(categoryId) as ViewResult;

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Only administrators can delete categories", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Exemplo n.º 3
0
        public void Category_Delete_InvalidInput()
        {
            //Arrange
            var controller = new CategoryController(new CategoryBLL(new CategoryRepoStub())
                , new AccountBLL(new AccountRepoStub()));

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

            string categoryId = "-1";

            //Act
            var viewResult = controller.Delete(categoryId) as ViewResult;

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Could not delete the category", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }