Example #1
0
        public void Image_Edit_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";
            string productId = "1";
            string imageUrl = "url";

            //Act
            var viewResult = controller.Edit(imageId, productId, imageUrl) 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);
        }
Example #2
0
        public void Image_Edit_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;
            controller.Session["Email"] = "ole";

            string imageId = "1";
            string productId = "1";
            string imageUrl = "url";

            //Act
            var viewResult = controller.Edit(imageId, productId, imageUrl) as ViewResult;

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Only administrators can edit images", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Example #3
0
        public void Image_Edit_InvalidProductId()
        {
            //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";
            string productId = "-1";
            string imageUrl = "url";

            //Act
            var viewResult = controller.Edit(imageId, productId, imageUrl) as ViewResult;

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