Esempio n. 1
0
        public void Image_Create_BadInput()
        {
            //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 productId = "bad input";
            string imageUrl = "url";

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

            //Assert
            Assert.AreEqual("Error", controller.ViewBag.Title);
            Assert.AreEqual("Invalid product id", controller.ViewBag.Message);
            Assert.AreEqual("~/Views/Shared/Result.cshtml", viewResult.ViewName);
        }
Esempio n. 2
0
        public void Image_Create_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 productId = "1";
            string imageUrl = "url";

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

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

            //Act
            var viewResult = controller.Create(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);
        }