public async Task Payment_Book_Works(string expectedResult) { var response = await controller.ProcessPayment(new Payment { Selection = "book" }); var result = response as OkObjectResult; Assert.NotNull(result); Assert.Equal(expectedResult, result.Value); }
public async Task Payment__For_Book_OK() { var expectedResult = "Duplicate packing slip for the royalty department is generated. Commission payment to the agent is generated."; var response = await controller.ProcessPayment(new Payment { Selection = "book" }); var result = response as OkObjectResult; Assert.NotNull(result); Assert.AreEqual(expectedResult, result.Value); }
public async Task Apikey_is_populated_in_command() { var request = new ProcessPaymentRequest(); var requestPaymentCommand = new RequestPaymentCommand(); _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); await _controller.ProcessPayment(request); requestPaymentCommand.ApiKey.Should().Be(_apiKey); }
public async void ProcessPayment_WithValidPaymentRequest_ReturnsOkResponseWithCorrectContent() { const bool success = true; const string id = "10"; _paymentProcessorMock.Setup(x => x.ProcessAsync(It.IsAny <PaymentRequest>())).ReturnsAsync( new ProcessPaymentResult { Payment = new ProcessedPayment { Success = success, Id = id } }); var result = await _paymentsController.ProcessPayment(new ProcessPaymentRequestDto { Currency = Currency.USD, CardNumber = "1234", CardExpiryMonth = 12, CardExpiryYear = 2020, Cvv = 123, Amount = 12 }); var actionResult = Assert.IsType <ActionResult <ProcessPaymentResponseDto> >(result); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var returnValue = Assert.IsType <ProcessPaymentResponseDto>(okResult.Value); Assert.Equal(success, returnValue.Success); Assert.Equal(id, returnValue.PaymentId); }
public void Valid50() { var paymentServiceMock = new Mock <Application.Services.PaymentService>(); var controller = new PaymentsController(paymentServiceMock.Object); var result = controller.ProcessPayment(PaymentStub.Valid50); Assert.IsInstanceOfType(result, typeof(OkResult)); }
public void InvalidDate() { var paymentServiceMock = new Mock <Application.Services.PaymentService>(); var controller = new PaymentsController(paymentServiceMock.Object); var result = controller.ProcessPayment(PaymentStub.InvalidDate); Assert.IsTrue(((List <string>)((BadRequestObjectResult)result).Value).Any(e => e == "Invalid ExpirationDate")); }
public void InvalidSecurityCode() { var paymentServiceMock = new Mock <Application.Services.PaymentService>(); var controller = new PaymentsController(paymentServiceMock.Object); var result = controller.ProcessPayment(PaymentStub.InvalidSecurityCode); Assert.IsTrue(((List <string>)((BadRequestObjectResult)result).Value).Any(e => e == "SecurityCode maximum length is 3.")); }
public void InvalidAmountNegative() { var paymentServiceMock = new Mock <Application.Services.PaymentService>(); var controller = new PaymentsController(paymentServiceMock.Object); var result = controller.ProcessPayment(PaymentStub.InvalidAmountNegative); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); Assert.IsTrue(((List <string>)((BadRequestObjectResult)result).Value).Any(e => e == "Invalid Amount")); }
public async Task Payment_InternalServerError() { mockPaymentsService.Setup(x => x.ProcessPayment(It.IsAny <string>())) .ThrowsAsync(new Exception()); controller = new PaymentsController(mockPaymentsService.Object); var response = await controller.ProcessPayment(new Payment { Selection = "book" }); var result = response as ObjectResult; Assert.Equal((int)HttpStatusCode.InternalServerError, result.StatusCode); }
public void Add_InvalidObjectPassed_ReturnsBadRequest() { // Arrange var Request = new PaymentModel() { Amount = 1, CardHolder = "46576879", CreditCardNumber = "yfughjhlk" }; _controller.ModelState.AddModelError("ExpirationDate", "Required"); // Act var badRequest = _controller.ProcessPayment(Request); var badResult = badRequest.Result as BadRequestObjectResult; // assert Assert.NotNull(badResult); Assert.Equal(400, badResult.StatusCode); // Assert // Assert.IsType<Task<IActionResult>>(badResponse); }
public void Invalid801() { var paymentServiceMock = new Mock <Application.Services.PaymentService>(); var controller = new PaymentsController(paymentServiceMock.Object); var result = controller.ProcessPayment(PaymentStub.Invalid801); var objResult = (ObjectResult)result; Assert.AreEqual(objResult.StatusCode, 500); Assert.AreEqual(objResult.Value, "Internal server error. Retried: 3 times."); }
public async Task When_Payment_Is_Process_Then_Return_NoContentResult() { _mockPaymentsService.Setup(x => x.ProcessPayment(It.IsAny <PaymentRequest>())) .ReturnsAsync(true); var controller = new PaymentsController(_logger, _mockPaymentsService.Object, _mockBankService.Object); var paymentRequest = new PaymentRequest { CardNumber = "4242424242424242", Amount = 32.56m, Currency = "USD", Cvv = "123", ExpiryMonth = DateTime.Now.Month, ExpiryYear = DateTime.Now.Year }; var expected = new NoContentResult(); var actual = await controller.ProcessPayment(paymentRequest); actual.Should().BeEquivalentTo(expected); }
public async Task ProcessPayment_When_Payload_Is_Invalid_Then_Return_BadRequestResult() { _mockPaymentsService.Setup(x => x.ProcessPayment(It.IsAny <PaymentRequest>())) .ReturnsAsync(false); var controller = new PaymentsController(_logger, _mockPaymentsService.Object, _mockBankService.Object); var paymentRequest = new PaymentRequest { ExpiryMonth = DateTime.Now.Month, ExpiryYear = DateTime.Now.Year }; var validator = new PaymentRequestValidator(); var validationResult = await validator.ValidateAsync(paymentRequest); validationResult.AddToModelState(controller.ModelState, null); var expected = new BadRequestResult(); var actual = await controller.ProcessPayment(paymentRequest); actual.Should().BeEquivalentTo(expected); }