public async Task Should_return_400_when_validation_failed() { _paymentController.ModelState.AddModelError("ExpiryMonth", "something went wrong"); _paymentController.ModelState.AddModelError("CardNumber", "something went wrong"); var request = new CreatePaymentRequest(); var response = await _paymentController.Create(request); var result = (ObjectResult)response.Result; result.StatusCode.ShouldBe(400); var gatewayResponse = (PaymentGatewayResponse <PaymentCreated>)result.Value; gatewayResponse.Success.ShouldBe(false); gatewayResponse.ResponseCode.ShouldBe(ResponseCodes.ValidationFailed); gatewayResponse.Entity.ShouldBeNull(); gatewayResponse.Errors.ShouldContainKey("CardNumber"); gatewayResponse.Errors.ShouldContainKey("ExpiryMonth"); }
public async Task Should_Be_Able_To_Preform_A_Payment_And_Recieve_A_Successful_Transaction() { var mockedIdentifier = new DateTimeOffset().ToUnixTimeMilliseconds().ToString(); var createPaymentDto = new CreatePaymentDto { Issuer = "amazon-issuer-id", CardHolder = "John Cage", Value = 199.99m, Currency = "Euro", CardNumber = "1234-1234-1234-1235", ExpiryMonth = 13, ExpiryYear = 2099, CCV = "12e2", }; var bankResponse = new BankResponse { id = mockedIdentifier, successful = true, message = "very nice", statusCode = 1 }; var paymentResponse = new PaymentResponse { paymentRequest = new PaymentModel { Id = "mocked-id", Issuer = "amazon-issuer-id", CardHolder = "John Cage", Value = 199.99m, Currency = "Euro", CardNumber = "1234-1234-1234-1235", ExpiryMonth = 13, ExpiryYear = 2099, CCV = "12e2", response = bankResponse, }, paymentResponse = bankResponse, }; var mockPaymentService = new Mock <IPaymentService>(); var mockLogger = new Mock <ILoggerService>(); mockPaymentService.Setup <PaymentResponse>(paymentService => paymentService.Create(createPaymentDto)).Returns(paymentResponse); var controller = new PaymentController(mockLogger.Object, mockPaymentService.Object); var result = controller.Create(createPaymentDto); Assert.IsType <ActionResult <PaymentResponse> >(result); Assert.IsType <PaymentResponse>(result.Value); Assert.IsAssignableFrom <PaymentModel>(result.Value.paymentRequest); Assert.IsAssignableFrom <BankResponse>(result.Value.paymentResponse); Assert.Equal(result.Value.paymentRequest.response.id, result.Value.paymentResponse.id); }
public void Create__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.AddPayment(payment)); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); //Act ViewResult result = controller.Create() as ViewResult; Assert.IsNotNull(result); }
public void Create_Success_ReturnsARedirectToActionResut() { // Arrange var testPayment = new PaymentViewModel(); var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.AddPayment(It.IsAny <PaymentViewModel>())); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); // Act var result = controller.Create(testPayment); // Assert var redirectToActionResult = result as RedirectToActionResult; Assert.AreEqual("Index", redirectToActionResult.ActionName); }
public void Create_Error_ReturnsAViewResut() { // Arrange var testPayment = new PaymentViewModel(); var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.AddPayment(It.IsAny <PaymentViewModel>())); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); controller.ModelState.AddModelError("", ""); // Act var result = controller.Create(testPayment); // Assert Assert.That(result, Is.InstanceOf <ViewResult>()); }
public void CreatePaymentSuccessReturn200WithPaymentObject() { var payment = new PaymentModel() { BankName = "CommonWealth", Amount = 500.21, AccountName = "Yequan Zhang", BSB = "123324", AccountNum = "12344233" }; var mockPaymentBAL = new Mock <IPaymentBAL>(); mockPaymentBAL.Setup(x => x.CreatePayment(payment)).Returns(payment); var mockLog = new Mock <ILogger <PaymentController> >(); var paymentController = new PaymentController(mockPaymentBAL.Object, mockLog.Object); var response = paymentController.Create(payment) as ObjectResult; Assert.AreEqual(response.StatusCode, 200); }