Example #1
0
        public void ConfirmBorrowTestWithException()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = true
            };
            var controller = new BorrowController(new MockBorrowDal(), mediaDal, new MockMemberDal());
            var result     = (RedirectToActionResult)controller.ConfirmBorrow(1);

            Assert.AreEqual("Browse", result.ActionName);
        }
Example #2
0
        public void LibrariansChoiceValid()
        {
            var mockMediaDal = new MockMediaDal
            {
                ThrowError = false
            };
            var controller = new BorrowController(new MockBorrowDal(), mockMediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.LibrariansChoice();

            Assert.AreEqual("Browse", result.ViewName);
        }
Example #3
0
        public void LibrariansChoiceWithException()
        {
            var mockMediaDal = new MockMediaDal
            {
                ThrowError = true
            };
            var controller = new BorrowController(new MockBorrowDal(), mockMediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.LibrariansChoice();

            Assert.AreEqual("Browse", result.ViewName);
            Assert.AreEqual("Uh-oh.. something went wrong", result.ViewData["Error"]);
        }
Example #4
0
        public void TypeFilterTestWithExceptionThrown()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = true
            };
            var controller = new BorrowController(new MockBorrowDal(), mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.TypeFilter("Action");

            Assert.AreEqual("Browse", result.ViewName);
            Assert.AreEqual("Uh-oh something went wrong", result.ViewData["Error"]);
        }
Example #5
0
        public void BrowseTest()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = false
            };
            var controller = new BorrowController(new MockBorrowDal(), mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.Browse();

            Assert.AreEqual("Browse", result.ViewName);
            var actualList = (List <Media>)result.Model;

            Assert.AreEqual(1, actualList.Count);
        }
Example #6
0
        public void CategoryFilterTestWithoutAll()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = false
            };
            var controller = new BorrowController(new MockBorrowDal(), mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.CategoryFilter("Action");

            Assert.AreEqual("Browse", result.ViewName);
            var actualList = (List <Media>)result.Model;

            Assert.AreEqual(1, actualList.Count);
        }
Example #7
0
        public void ConfirmedBorrowTestWithValidInput()
        {
            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = false,
                ThrowNullReference = false
            };
            var mockMediaDal = new MockMediaDal();
            var borrowItem   = new ConfirmBorrowObject();
            var controller   = new BorrowController(mockBorrowDal, mockMediaDal, new MockMemberDal());
            var result       = (RedirectToActionResult)controller.ConfirmedBorrow(borrowItem);

            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
            Assert.AreEqual("Browse", result.ActionName);
        }
Example #8
0
        public void BrowseTestWithException()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = true
            };
            var controller = new BorrowController(new MockBorrowDal(), mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.Browse();

            Assert.AreEqual(null, result.ViewName);
            Assert.AreEqual("Uh-oh.. something went wrong", result.ViewData["Error"]);
            var actualList = (List <Media>)result.Model;

            Assert.AreEqual(0, actualList.Count);
        }
Example #9
0
        public void ConfirmedBorrowTestWithException()
        {
            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = true,
                ThrowNullReference = false
            };
            var mockMediaDal = new MockMediaDal();
            var borrowItem   = new ConfirmBorrowObject();
            var controller   = new BorrowController(mockBorrowDal, mockMediaDal, new MockMemberDal());
            var result       = (ViewResult)controller.ConfirmedBorrow(borrowItem);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("ConfirmBorrow", result.ViewName);
            Assert.AreEqual("Exception of type 'System.Exception' was thrown.", result.ViewData["Error"]);
        }
Example #10
0
        public void ConfirmedBorrowTestWithNullReference()
        {
            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = false,
                ThrowNullReference = true
            };
            var mockMediaDal = new MockMediaDal();
            var borrowItem   = new ConfirmBorrowObject();
            var controller   = new BorrowController(mockBorrowDal, mockMediaDal, new MockMemberDal());
            var result       = (ViewResult)controller.ConfirmedBorrow(borrowItem);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("ConfirmBorrow", result.ViewName);
            Assert.AreEqual("Please log in again.", result.ViewData["Error"]);
            Assert.AreEqual("Object reference not set to an instance of an object.", result.ViewData["ErrorMessage"]);
        }
Example #11
0
        public void ConfirmedBorrowTestWithInvalidInput()
        {
            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = false,
                ThrowNullReference = false
            };
            var mockMediaDal = new MockMediaDal();
            var borrowItem   = new ConfirmBorrowObject();
            var controller   = new BorrowController(mockBorrowDal, mockMediaDal, new MockMemberDal());

            controller.ModelState.AddModelError("Error", "Error");
            var result = (ViewResult)controller.ConfirmedBorrow(borrowItem);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("ConfirmBorrow", result.ViewName);
            Assert.AreEqual("Please select a shipping address", result.ViewData["Error"]);
        }
Example #12
0
        public void ConfirmBorrowTestWithMoreThanAllowedRentals()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = false
            };

            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = false,
                ThrowNullReference = false,
                NumberToReturn     = 3
            };

            HomeController.CurrentUser = new Member();
            var controller = new BorrowController(mockBorrowDal, mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.ConfirmBorrow(1);

            Assert.AreEqual("Browse", result.ViewName);
            Assert.AreEqual($"Looks like you have already rented 3 items. Please return something to rent another.", result.ViewData["Error"]);
        }
Example #13
0
        public void ConfirmBorrowTest()
        {
            var mediaDal = new MockMediaDal
            {
                ThrowError = false
            };

            var mockBorrowDal = new MockBorrowDal
            {
                ThrowException     = false,
                ThrowNullReference = false,
                NumberToReturn     = 1
            };

            HomeController.CurrentUser = new Member();
            var controller = new BorrowController(mockBorrowDal, mediaDal, new MockMemberDal());
            var result     = (ViewResult)controller.ConfirmBorrow(1);

            Assert.AreEqual(null, result.ViewName);
            var actualItem = (ConfirmBorrowObject)result.Model;

            Assert.AreEqual(1, BorrowController.SelectedItem.InventoryId);
        }