public async Task SetPayment_ReturnsAOkObjectResult_WithAPaymentResponse() { // Arrange var request = TestFactory.CreateHttpRequest(TestFactory.GetTestPayment()); var mockAcquiringBankService = new Mock <IAcquiringBankService>(); mockAcquiringBankService.Setup(serv => serv.SetPayment(It.IsAny <Payment>())).Returns(TestFactory.GetTestPaymentResponse()); var paymentGatewayService = new PaymentGatewayService(new PaymentGatewayClient(mockAcquiringBankService.Object, new NullLoggerFactory())); var paymentGatewayFunction = new PaymentGatewayFunction(paymentGatewayService, new NullLoggerFactory()); // Act var response = await paymentGatewayFunction.SetPayment(request); // Assert var okResult = Assert.IsType <OkObjectResult>(response); var model = Assert.IsAssignableFrom <PaymentResponse>(okResult.Value); }
public PaymentGatewayServiceTests() { _mocker = new AutoMocker(); _mockRepository = _mocker.GetMock <IPaymentRepository>(); _mockBankClient = _mocker.GetMock <IBankClient>(); _requestGenerator = new Faker <ProcessPaymentRequest>() .RuleFor(t => t.MerchantId, _ => Guid.NewGuid().ToString()) .RuleFor(t => t.CreditCardNumber, f => f.Finance.CreditCardNumber()) .RuleFor(t => t.ExpiryMonth, f => f.Date.Future().Month) .RuleFor(t => t.ExpiryYear, f => f.Date.Future().Year) .RuleFor(t => t.Amount, f => f.Finance.Amount()) .RuleFor(t => t.CurrencyCode, f => f.Finance.Currency().Code) .RuleFor(t => t.Cvv, f => f.Finance.CreditCardCvv()); SUT = _mocker.CreateInstance <PaymentGatewayService>(); }
public PaymentGatewayServiceShould() { paymentReference = Guid.NewGuid(); paymentRequest = CreatePaymentRequest(); bankPaymentRequest = new BankPaymentRequest("4485063526474709", "01/20", 20.00m, "GBP", 123); bankApiMock = new Mock <IBankApiClient>(); var bankPaymentDetail = new BankPaymentDetail(paymentReference, "Accepted", "4485063526474709", "01/20", 20.00m, "GBP", 123); var bankPaymentResponse = new BankPaymentResponse(paymentReference, "Accepted"); var paymentResponse = new PaymentResponse(paymentReference, "Accepted"); var paymentDetail = new PaymentDetail(paymentReference, "Accepted", "4***********4709", "01/20", 20.00m, "GBP", 123); bankApiMock.Setup(service => service.Process(It.IsAny <BankPaymentRequest>())) .Returns(Task.FromResult(bankPaymentResponse)); bankApiMock.Setup(service => service.GetPaymentDetail(paymentReference)).Returns(Task.FromResult(bankPaymentDetail)); bankPaymentMapperMock = new Mock <IBankPaymentMapper>(); bankPaymentMapperMock.Setup(mapper => mapper.MapRequest(It.IsAny <PaymentRequest>())).Returns(bankPaymentRequest); bankPaymentMapperMock.Setup(mapper => mapper.MapResponse(It.IsAny <BankPaymentResponse>())) .Returns(paymentResponse); bankPaymentMapperMock.Setup(mapper => mapper.MapDetail(It.IsAny <BankPaymentDetail>())) .Returns(paymentDetail); applicationLoggerMock = new Mock <IApplicationLogger>(); paymentGatewayService = new PaymentGatewayService(bankApiMock.Object, bankPaymentMapperMock.Object, applicationLoggerMock.Object); }
public async Task GetPayment_ReturnsAOkObjectResult_WithAPaymentEntityMasked() { // Arrange var paymentId = Guid.NewGuid().ToString(); var request = TestFactory.CreateHttpRequest(); var mockAcquiringBankService = new Mock <IAcquiringBankService>(); mockAcquiringBankService.Setup(serv => serv.GetPayment(It.IsAny <Guid>())).Returns(TestFactory.GetTestPaymentEntityResponse(paymentId)); var paymentGatewayService = new PaymentGatewayService(new PaymentGatewayClient(mockAcquiringBankService.Object, new NullLoggerFactory())); var paymentGatewayFunction = new PaymentGatewayFunction(paymentGatewayService, new NullLoggerFactory()); // Act var response = await paymentGatewayFunction.GetPayment(request, paymentId); // Assert var okResult = Assert.IsType <OkObjectResult>(response); var model = Assert.IsAssignableFrom <PaymentEntityMasked>(okResult.Value); Assert.Equal(paymentId, model.Id.ToString()); Assert.Equal("XXXXXXXXXXXX4567", model.CardNumber); Assert.Equal("XXXX", model.ExpiryYear); Assert.Equal("XX", model.ExpiryMonth); Assert.Equal("XXX", model.CVV); }
public void SetUp() { paymentDB = new PaymentDBContext(); paymentRepository = new PaymentRepository(paymentDB); paymentGatewayService = new PaymentGatewayService(); }
public PaymentGatewayServiceShould() { _acquiringBankMock = new Mock <IBank>(); _repositoryMock = new Mock <IRepository>(); paymentGatewayService = new PaymentGatewayService(_acquiringBankMock.Object, _repositoryMock.Object); }
public void TestInitialize() { this.mockPaymentGatewayFactory = new Mock <IPaymentGatewayFactory>(MockBehavior.Strict); this.paymentGatewayService = new PaymentGatewayService(this.mockPaymentGatewayFactory.Object); }