public void PostAndGetPayment_ShouldAcceptAndRetrieve() { CardDto card = GenerateRandomCard(); PaymentRequestDto paymentRequest = new PaymentRequestDto(); paymentRequest.MerchantId = 1; paymentRequest.Amount = 25.99; paymentRequest.Currency = "CAD"; paymentRequest.Card = card; var postResult = _paymentsController.Post(paymentRequest); Assert.IsType <OkObjectResult>(postResult.Result); OkObjectResult objectResult = postResult.Result as OkObjectResult; Assert.IsType <PaymentResponseDto>(objectResult.Value); PaymentResponseDto paymentResponse = objectResult.Value as PaymentResponseDto; Assert.True(paymentResponse.Id > 0); Assert.NotNull(paymentResponse.Status); int paymentId = paymentResponse.Id; var getResult = _paymentsController.Get(paymentId); Assert.IsType <OkObjectResult>(getResult.Result); OkObjectResult getObjectResult = getResult.Result as OkObjectResult; Assert.IsType <PaymentInformationDto>(getObjectResult.Value); PaymentInformationDto paymentInformation = getObjectResult.Value as PaymentInformationDto; Assert.Equal(paymentRequest.Amount, paymentInformation.Amount); Assert.Equal(paymentRequest.Currency, paymentInformation.Currency); }
/// <summary> /// Retrieves details for a payment using a payment identifier. /// </summary> /// <param name="paymentId">The identifier of the payment.</param> /// <returns>A PaymentInformationDto, which contains information about the payment.</returns> public PaymentInformationDto GetPaymentInformation(int paymentId) { _logger.LogInformation("Retrieving information about payment #" + paymentId.ToString()); Payment payment = _paymentRepository.RetrievePayment(paymentId); PaymentInformationDto paymentResponseDto = _mapper.Map <PaymentInformationDto>(payment); return(paymentResponseDto); }
public ActionResult <PaymentInformationDto> Get(int id) { PaymentInformationDto payment = _paymentService.GetPaymentInformation(id); if (payment == null) { _logger.LogInformation("Payment with id #" + id.ToString() + " not found."); return(NotFound()); } return(Ok(payment)); }
public void Setup() { _stubPurchaseStatusDto = new PurchaseStatusDto { Id = Guid.NewGuid(), Name = "Ordered" }; _stubPaymentInformationDto = new PaymentInformationDto { CardCVC = "121", CardExpiry = new DateTime(), CardName = "Oliver Test", CardNumber = "1234567890123456", ID = Guid.NewGuid() }; _stubPurchaseOrderDto = new PurchaseOrderDto { Address = "Test Drive", ExternalID = 1, ID = Guid.Parse("d61a78a9-b6ad-4430-91ea-0c8d5227b6aa"), IsDeleted = false, PaymentInformation = _stubPaymentInformationDto, PaymentInformationID = _stubPaymentInformationDto.ID, Postcode = "T35T DR1", ProductID = Guid.NewGuid(), ProductName = "Testy", ProductPrice = 10.50, PurchasedBy = Guid.NewGuid(), PurchasedOn = new DateTime(), PurchaseStatus = _stubPurchaseStatusDto, Quantity = 1, Source = "Undercutters", StatusID = _stubPurchaseStatusDto.Id }; _stubOrderCreatedDto = new OrderCreatedDto { AccountName = "Testy1", CardNumber = "10490249204920492049", Id = 1, ProductEan = "1 2 4 2 3", ProductId = 1, ProductName = "Product1", PurchasedOn = new DateTime(), Quantity = 5, Success = true, TotalPrice = 10 }; _mockLogger = new Mock <ILogger <OrdersRepository> >(); _ordersRepository = new OrdersRepository(GetInMemoryContextWithSeedData(), _mockLogger.Object); }