public void TestCreatePayment_NullRequest() { SetUpGatewayComponent(false); var result = paymentController.CreatePayment(null); var objResult = Assert.IsType <BadRequestObjectResult>(result); ApiActionResult apiActionResult = Assert.IsType <ApiActionResult>(objResult.Value); ((bool)apiActionResult.Data).Should().BeFalse(); }
public void CreatePayment_CanCreatePayment_BadRequestObjectResult() { // Arrange var body = new PaymentRequest { Amount = 10, CardExpiryDate = DateTime.Now, CardNumber = "5425233430109903", CurrencyCode = "GDP", CVC = 132, FullName = "John Doe", Id = new Guid("bf2887a9-9eaf-4f75-a38a-e2d27b885c88"), RequestDate = DateTime.Now, DateOfBirth = DateTime.Now.AddYears(-22), RecievingBankName = "TestBank" }; // Act var result = PaymentController.CreatePayment(body).Result as BadRequestObjectResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Value); Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse"); }
public void CreatePayment_CanCreatePayment_StatusCode500() { // Arrange var body = new PaymentRequest { Amount = 10, CardExpiryDate = DateTime.Now, CardNumber = "5425233430109903", CurrencyCode = "GDP", CVC = 132, FullName = "John Doe", Id = new Guid("5cf9b529-5c88-4b35-accd-dfcafe96e180"), RequestDate = DateTime.Now, DateOfBirth = DateTime.Now.AddYears(-22), RecievingBankName = "TestBank" }; // Act var result = PaymentController.CreatePayment(body).Result as ObjectResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(500, result.StatusCode); Assert.IsNotNull(result.Value); Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse"); }
public void CreatePayment_CanCreatePayment_ConflictObjectResult() { // Arrange var body = new PaymentRequest { Amount = 10, CardExpiryDate = DateTime.Now, CardNumber = "5425233430109903", CurrencyCode = "GDP", CVC = 132, FullName = "John Doe", Id = new Guid("ff58f525-5528-46e2-8b68-aacec43cd4c1"), RequestDate = DateTime.Now, DateOfBirth = DateTime.Now.AddYears(-22), RecievingBankName = "TestBank" }; // Act var result = PaymentController.CreatePayment(body).Result as ConflictObjectResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Value); Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse"); }
public void CreatePayment_CanCreatePayment_OkObjectResult() { // Arrange var body = new PaymentRequest { Amount = 10, CardExpiryDate = DateTime.Now, CardNumber = "5425233430109903", CurrencyCode = "GDP", CVC = 132, FullName = "John Doe", Id = new Guid("af188a89-0d2a-4863-a596-f7844364ac09"), RequestDate = DateTime.Now, DateOfBirth = DateTime.Now.AddYears(-22), RecievingBankName = "TestBank" }; // Act var result = PaymentController.CreatePayment(body).Result as OkObjectResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Value); Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse"); }
internal void CreatePayments(Booking booking, PaymentController paymentController) { Supplier supplier = (Supplier)booking.Supplier; Customer customer = (Customer)booking.Customer; BookingType bookingType = booking.Type; List <IPaymentRule> paymentRules = findMatchingPaymentRules(supplier, customer, bookingType); foreach (IPaymentRule paymentRule in paymentRules) { DateTime dueDate; if (paymentRule.BaseDate == BaseDate.StartDate) { dueDate = booking.StartDate.AddDays(paymentRule.DaysOffset); } else { dueDate = booking.EndDate.AddDays(paymentRule.DaysOffset); } booking.CalculateAmounts(); decimal dueAmount = booking.TransferAmount * paymentRule.Percentage / 100; Customer lonelyTree = customerController.findLonelyTree(); IPayment payment = paymentController.CreatePayment(dueDate, dueAmount, lonelyTree, booking.Supplier, paymentRule.PaymentType, booking.Sale, booking.BookingNumber); paymentController.UpdatePayment(payment); } }
public void CreateAndExecutePayment() { AppSettingsReader appSettingsReader = new AppSettingsReader(); string clientId = (string)appSettingsReader.GetValue("clientId", typeof(string)); string clientSecret = (string)appSettingsReader.GetValue("clientSecret", typeof(string)); var apicontext = PayPalConfiguration.GetAPIContext(clientId, clientSecret); PaymentController controller = new PaymentController(); var guid = Convert.ToString((new Random()).Next(100000)); string baseURI = "http://localhost:37256/Paypal/PayWithPayPal?guid=" + guid; BouquetOrder bouquet = new BouquetOrder(1, 1, new Bouquet(6, "gardenia", 2.00, 0)); var payment = controller.CreatePayment(apicontext, baseURI, bouquet); var context = new Mock.MockHttpContext(); context.m_request.m_queryString.Add("PayerID", guid); context.m_request.m_queryString.Add("guid", guid); context.Session.Add(guid, payment.id); controller.ControllerContext = new ControllerContext { HttpContext = context, RouteData = new RouteData() }; var result = controller.ExecutePayment(apicontext, guid, payment.id); Assert.IsNotNull(apicontext, "PayPal API context is null"); Assert.IsNotNull(payment.id, "Fail to create payment"); //must be failed because the data are fake. Assert.IsTrue(result.state.ToLower() != "approved", result.state.ToLower()); }
public void CreatePayment() { // Arrange paymentRepository.Setup(p => p.Insert(It.IsAny <Debt>())).Returns(true); var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { { "controller", "payment" } }); var controller = new PaymentController(paymentRepository.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:1175/api/Payment/CreatePayment?debtId={debtId}") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.CreatePayment(1); // Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }
public async Task CallPaymentServiceWithNewPayment_GivenValidPaymentRequest_WhenCallingCreatePayment() { // Arrange var createPaymentRequest = new CreatePaymentRequestV1() { CardNumber = "4658582263620043", ExpiryDate = "0824", Amount = 10m, CurrencyCode = "GBP", Ccv = "001" }; var expectedPaymentResponse = new CreatePaymentResponseV1() { PaymentId = "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE", IsSuccessful = true }; // Act var actualResponse = await _sut.CreatePayment(createPaymentRequest, CancellationToken.None); // Assert actualResponse.Result.Should().BeOfType <CreatedAtRouteResult>(); ((ObjectResult)actualResponse.Result).Value.Should().BeEquivalentTo(expectedPaymentResponse); }