public void Edit_NotNull_ViewResultIsNotNull() { //Arrange var payment = new PaymentViewModel(); var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.UpdatePayment(payment.Id, payment)); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); //Act var result = controller.Edit(payment.Id, payment); //Assert Assert.IsNotNull(result); }
public void Edit_PaymentDoesNotExistPost_ReturnsABadRequestResults() { // Arrange var paymentId = 1; var testPayment = new PaymentViewModel() { Id = paymentId }; var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.ReadSingle(It.IsAny <int>())).Throws(It.IsAny <Exception>()); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); // Act var result = controller.Edit(paymentId); // Assert Assert.That(result, Is.TypeOf <BadRequestResult>()); }
public void Edit_Success_ReturnsARedirectToActionResut() { // Arrange var paymentId = 1; var testPayment = new PaymentViewModel() { Id = paymentId }; var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.UpdatePayment(paymentId, It.IsAny <PaymentViewModel>())); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); // Act var result = controller.Edit(paymentId, testPayment); // Assert var redirectToActionResult = result as RedirectToActionResult; Assert.AreEqual("Index", redirectToActionResult.ActionName); }
public void Edit_PaymentExists_ReturnsAViewResultWithPayment() { // Arrange var paymentId = 1; var testPayment = new PaymentViewModel() { Id = paymentId }; var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.ReadSingle(paymentId)).Returns(testPayment); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); // Act var result = controller.Edit(paymentId); // Assert var viewResult = result as ViewResult; var model = viewResult.ViewData.Model as PaymentViewModel; Assert.AreEqual(paymentId, model.Id); }