public void Details_PaymentDoesNotExist_ReturnsNotFoundResults() { // Arrange 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.Details(123); // Assert Assert.That(result, Is.TypeOf <BadRequestResult>()); }
public void Details__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.ReadSingle(payment.Id)); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); //Act ViewResult result = controller.Details(payment.Id) as ViewResult; //Assert Assert.IsNotNull(result); }
public void Details_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.Details(paymentId); // Assert var viewResult = result as ViewResult; var model = viewResult.ViewData.Model as PaymentViewModel; Assert.AreEqual(paymentId, model.Id); }