public void EditNoIdLoadsError()
        {
            //arrange
            int?id = null;
            //act
            ViewResult result = (ViewResult)controller.Edit(id);

            //assert
            Assert.AreEqual("Error", result.ViewName);
        }
Beispiel #2
0
        public async Task Post_Edit_WrongId_NotFoundResult()
        {
            Mock <IRentalsService>   rentalsRepository   = MockRentalsService();
            Mock <IBooksService>     booksRepository     = MockBooksService();
            Mock <ICustomersService> customersRepository = MockCustomersService();
            var controller = new RentalsController(rentalsRepository.Object, booksRepository.Object, customersRepository.Object);
            int id         = 1;
            var rental     = new Rental {
                Id = 2
            };

            var result = await controller.Edit(id, rental);

            Assert.That(result is NotFoundResult);
        }
Beispiel #3
0
        public async Task Post_Edit_ModelValid_Redirected()
        {
            Mock <IRentalsService>   rentalsRepository   = MockRentalsService();
            Mock <IBooksService>     booksRepository     = MockBooksService();
            Mock <ICustomersService> customersRepository = MockCustomersService();
            var controller = new RentalsController(rentalsRepository.Object, booksRepository.Object, customersRepository.Object);
            int id         = 1;
            var rental     = new Rental {
                Id = id
            };

            var result = await controller.Edit(id, rental) as RedirectToActionResult;

            Assert.AreEqual(result.ActionName, "Index");
        }
Beispiel #4
0
        public async Task Post_Edit_ModelInvalid_ViewResultWithModel()
        {
            Mock <IRentalsService>   rentalsRepository   = MockRentalsService();
            Mock <IBooksService>     booksRepository     = MockBooksService();
            Mock <ICustomersService> customersRepository = MockCustomersService();
            var controller = new RentalsController(rentalsRepository.Object, booksRepository.Object, customersRepository.Object);
            int id         = 1;
            var rental     = new Rental {
                Id = id
            };

            controller.ModelState.AddModelError("test", "test");

            var result = await controller.Edit(id, rental) as ViewResult;

            Assert.AreEqual(result.Model, rental);
        }