Esempio n. 1
0
        public void Image_Delete_NotAdmin()
        {
            //Arrange
            var controller = new ImageController(new ImageBLL(new ImageRepoStub())
                , null, new AccountBLL(new AccountRepoStub()));

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

            string imageId = "1";

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

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Only administrators can delete images", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Esempio n. 2
0
        public void Image_Delete_InvalidInput()
        {
            //Arrange
            var controller = new ImageController(new ImageBLL(new ImageRepoStub())
                , null, new AccountBLL(new AccountRepoStub()));

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

            string imageId = "-1";

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

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Could not delete the image", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Esempio n. 3
0
        public void Image_Delete_NoIdentifierFound()
        {
            //Arrange
            var controller = new ImageController(new ImageBLL(new ImageRepoStub())
                , null, new AccountBLL(new AccountRepoStub()));

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

            string imageId = "1";

            //Act
            var viewResult = controller.Delete(imageId) 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);
        }
Esempio n. 4
0
        public void Image_Delete_GoodInput()
        {
            //Arrange
            var controller = new ImageController(new ImageBLL(new ImageRepoStub())
                , null, new AccountBLL(new AccountRepoStub()));

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

            string imageId = "1";

            Image expectedResult = new Image { ImageId = 1, ProductId = 1, ImageUrl = "test" };

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

            //Assert
            Assert.AreEqual("Success", controller.ViewBag.Title);
            Assert.AreEqual("Image was deleted", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }