public async Task MakePayment_SendsCommand_WhenModelStateIsValid() { // Arrange var commandList = new List <ProcessPayment>(); var sendEndPoint = new Mock <ISendEndpoint>(); sendEndPoint.Setup(x => x.Send(It.IsAny <ProcessPayment>(), new CancellationToken())) .Callback <ProcessPayment, CancellationToken>((c, ct) => commandList.Add(c)); var logger = new Mock <ILogger <PaymentGatewayController> >(); var sut = new PaymentGatewayController(sendEndPoint.Object, mapper, logger.Object); var input = new PaymentRequest() { CardNumber = "1234-1234-1234-1234", Cvv = "123", Amount = 1, Currency = "£", ExpiryDate = "01/2022", OrderId = "1234", MerchantId = "merchant1" }; // Act await sut.MakePayment(input); // Assert sendEndPoint.Verify(foo => foo.Send(It.IsAny <ICommand>(), new CancellationToken()), Times.Once); var cmd = commandList.FirstOrDefault(); cmd.Amount.Should().Be(input.Amount); cmd.Currency.Should().Be(input.Currency); cmd.Cvv.Should().Be(input.Cvv); cmd.CardNumber.Should().Be(input.CardNumber); cmd.OrderId.Should().Be(input.OrderId); cmd.MerchantId.Should().Be(input.MerchantId); }
public PaymentGatewayControllerTests() { _mockAcquiringBank = new Mock <IAcquiringBank>(); _sut = new PaymentGatewayController(Mock.Of <ILogger <PaymentGatewayController> >(), _mockAcquiringBank.Object); }
public PaymentGatewayControllerTests() { _fixture = new Fixture(); _mockOrchestator = new Mock <IPaymentOrchestrator>(); _mockLogger = new Mock <ILogger <PaymentGatewayController> >(); _sut = new PaymentGatewayController(_mockOrchestator.Object, _mockLogger.Object); }
public void GetPricingPackage_ReturnsNOK() { var controller = new PaymentGatewayController(pgm); // Act var result = controller.GetPaymentGateway(7); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void GetPaymentGateway_ReturnsOK() { var controller = new PaymentGatewayController(pgm); // Act var result = controller.GetPaymentGateway(1); // Assert Assert.IsType <OkObjectResult>(result); }
public void GetPaymentGateways_ReturnsOK() { var controller = new PaymentGatewayController(pgm); // Act var result = controller.GetPaymentGateways(); // Assert Assert.NotEmpty(result); }
public void GetPaymentGateways_ReturnsNOK() { var mockSub = new Mock <IPaymentGatewayManipulation>(); var controller = new PaymentGatewayController(mockSub.Object); // Act var result = controller.GetPaymentGateways(); // Assert Assert.Empty(result); }
public PaymentGatewayControllerShould() { _fakeLogger = new Mock <ILogger <PaymentGatewayController> >(); _fakeProcessor = new Mock <IPaymentProcessor>(); _fakeRepository = new Mock <IPaymentRepository>(); _fakeBankService = new Mock <IBankService>(); _sut = new PaymentGatewayController( _fakeRepository.Object, _fakeProcessor.Object, _fakeBankService.Object, _fakeLogger.Object); }
public void Post_ReturnsNOK() { var controller = new PaymentGatewayController(pgm); // Act PaymentGatewayDto pgdo = new PaymentGatewayDto(); var result = controller.Post(pgdo); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task Call_PaymentGatewayService_To_Process_Payment_When_Handling_Request() { // Arrange var paymentGatewayController = new PaymentGatewayController(paymentGatewayServiceMock.Object); var paymentRequest = CreatePaymentRequest(); // Act await paymentGatewayController.Post(paymentRequest); // Assert paymentGatewayServiceMock.Verify(service => service.SendPayment(paymentRequest), Times.Once); }
public async Task Return_BadRequest_When_PaymentRequest_Is_Invalid() { // Arrange var paymentGatewayController = new PaymentGatewayController(paymentGatewayServiceMock.Object); // Act PaymentRequest invalidPaymentRequest = new PaymentRequest("", "", 0m, "", 0); var response = await paymentGatewayController.Post(invalidPaymentRequest) as BadRequestObjectResult; // Assert Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)response.StatusCode); Assert.Equal("Invalid payment request", response.Value); }
public void Create_ReturnsBadRequest_GivenInvalidModel() { // Arrange & Act var mockSub = new Mock <IPaymentGatewayManipulation>(); var controller = new PaymentGatewayController(mockSub.Object); controller.ModelState.AddModelError("error", "some error"); // Act var result = controller.Post(paymentGateway: null); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void RetrievePayments_ShouldReturnSuccessfullPayment_WhenGivenValidIdentifier() { var Identifier = new Guid(); BankPreviousPaymentDetailDTO paymentDetail = new BankPreviousPaymentDetailDTO() { Amount = 100, Currency = "Euro", CardNumber = "1234567891234567", PaymentStatusCode = 200 }; mockPaymentGateService.Setup(x => x.RetrievePreviousPayment(Identifier)).Returns(paymentDetail); _paymentGatewayController = new PaymentGatewayController(mockPaymentGateService.Object); JsonResult paymentInfo = _paymentGatewayController.RetreivePayments(Identifier); }
public async Task MakePayment_ReturnsAcceptedResult_WhenModelStateIsValid() { // Arrange var sendEndPoint = new Mock <ISendEndpoint>(); var logger = new Mock <ILogger <PaymentGatewayController> >(); var sut = new PaymentGatewayController(sendEndPoint.Object, mapper, logger.Object); var input = new PaymentRequest() { CardNumber = "1234-1234-1234-1234", Cvv = "123", Amount = 1, Currency = "£", ExpiryDate = "01/2022", OrderId = "1234" }; // Act var result = await sut.MakePayment(input); // Assert result.Should().BeOfType <AcceptedResult>(); }
public async Task MakePayment_DoesNotSendCommand_WhenModelStateIsInvalid() { // Arrange var sendEndPoint = new Mock <ISendEndpoint>(); var logger = new Mock <ILogger <PaymentGatewayController> >(); var sut = new PaymentGatewayController(sendEndPoint.Object, mapper, logger.Object); sut.ModelState.AddModelError("CardNumber", "Required"); var input = new PaymentRequest() { Cvv = "123", Amount = 1, Currency = "£", ExpiryDate = "01/2022", OrderId = "1234" }; // Act await sut.MakePayment(input); // Assert sendEndPoint.Verify(foo => foo.Send(It.IsAny <ICommand>(), new CancellationToken()), Times.Never); }
public void ProcessPayments_ShouldReturnSucessfull_WhenWithProperCardDetail() { //ExpiryDate expiryDate = new ExpiryDate() { Month = 07, Year = 2022 }; CardDetailDTO card = new CardDetailDTO() { Amount = 100, CardNumber = "1234567891234567", Currency = "Euro", Cvv = 123, ExpiryDate = "12/2020" }; JsonResultDTO result = new JsonResultDTO() { IsSuccess = true, TransactionId = new Guid(), }; mockPaymentGateService.Setup(x => x.MakePayment(card)).Returns(result); _paymentGatewayController = new PaymentGatewayController(mockPaymentGateService.Object); JsonResult paymentInfo = _paymentGatewayController.ProcessPayments(card); Assert.AreEqual(result, paymentInfo.Data); }
public void Initialize() { this.paymentGatewayMock = new Mock <IPaymentGateway>(); this.controller = new PaymentGatewayController(this.paymentGatewayMock.Object); }
public void Setup() { _paymentServiceMock = new Mock <IPaymentService>(); _paymentGatewayController = new PaymentGatewayController(_paymentServiceMock.Object); }