Ejemplo n.º 1
0
        public async Task Return_Success_Response_When_Request_Is_Successful()
        {
            BankPaymentResponse bankPaymentResponse = (new BankPaymentResponse {
                PaymentIdentifier = Guid.NewGuid().ToString(), PaymentStatus = PaymentStatus.Success
            });

            _server
            .Given(Request.Create()
                   .WithPath($"/api/payment").UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody(bankPaymentResponse.ToJson()));
            _mockAcquiryBankOptions.SetupGet(x => x.CurrentValue)
            .Returns(new AcquiringBankSettings {
                ApiUrl = _server.Urls.First()
            });
            var sut = new AcquiringBankClient(new HttpClient(), _mockAcquiryBankOptions.Object, _mockLogger.Object);


            var response = await sut.ProcessPayment(new BankPaymentRequest
            {
                Amount          = 100,
                Currency        = "EUR",
                CardExpiryYear  = "24",
                CardExpiryMonth = "4",
                CardNumber      = "5564876598743467",
                CVV             = "782",
                MerchantId      = Guid.NewGuid().ToString()
            });

            response.Should().BeEquivalentTo(bankPaymentResponse);
        }
Ejemplo n.º 2
0
        public AcquiringBankClientTests()
        {
            var httpMessageHandlerMock = new Mock <HttpMessageHandler>();

            httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{'transactionId':'65a83e69-6741-4970-ab7c-433beb3837cb','transactionStatus':'ok'}"),
            });

            var httpClient = new HttpClient(httpMessageHandlerMock.Object);

            httpClient.BaseAddress = new Uri("https://localhost");

            this.httpClientFactoryMock = new Mock <IHttpClientFactory>();
            this.httpClientFactoryMock
            .Setup(s => s.CreateClient(It.IsAny <string>()))
            .Returns(httpClient);

            this.loggerMock = new Mock <ILogger <AcquiringBankClient> >();

            this.bankConfiguration = new BankConfiguration
            {
                BaseAddress = "https://localhost",
                Endpoint    = "/api/endpoint",
                ServiceName = "serviceName",
                Timeout     = 1000
            };

            this.target = new AcquiringBankClient(this.httpClientFactoryMock.Object, this.loggerMock.Object, this.bankConfiguration);
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            IHttpClientFactory httpClientFactory = new HttpClientFactory();
            var appSettings         = new ConfigurationBuilder().AddJsonFile(AppSettingsFileName).Build();
            var clientConfiguration = new AcquiringBankClientConfiguration(appSettings);
            var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(new AcquiringBankProviderProfile())));

            _sut = new AcquiringBankClient(httpClientFactory, clientConfiguration, mapper);
        }
Ejemplo n.º 4
0
        public AcquiringBankClientShould()
        {
            _fixture = new Fixture();
            _httpMessageHandlerProxy = new HttpMessageHandlerProxy();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerProxy);
            var        config     = new AcquiringBankConfig
            {
                BaseAddress = "http://tempuri.org/api/"
            };

            _acquiringBankClient = new AcquiringBankClient(httpClient, config);
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            _fakeHttpMessageHandler = new FakeHttpMessageHandler {
                ResponseMessage = SampleHttpResponseMessage
            };
            var fakeHttpClientFactory   = new FakeHttpClientFactory(new HttpClient(_fakeHttpMessageHandler));
            var fakeClientConfiguration = A.Fake <IAcquiringBankClientConfiguration>();

            A.CallTo(() => fakeClientConfiguration.BaseUri).Returns(SampleBaseUri);
            var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(new AcquiringBankProviderProfile())));

            _sut = new AcquiringBankClient(fakeHttpClientFactory, fakeClientConfiguration, mapper);
        }
Ejemplo n.º 6
0
        public async Task SubmitPaymentToBank_ValidPaymentRequest_ReturnsCorrectDetails()
        {
            // Arrange
            var expectedBankId = new Guid("7b6bf96c-0231-41e3-9014-393ff87ed4e1");

            PaymentRequest paymentRequest = new PaymentRequest
            {
                Amount            = 100,
                CardholderName    = "Testy McTester",
                CardNumber        = "1111 2222 3333 4444",
                CurrencyIsoAlpha3 = "GBP",
                Cvv        = "123",
                MerchantId = new Guid("aa9f4ef9-35ab-4a10-8cf5-f5535582fd01")
            };

            var submissionDateTimeMock = new DateTimeOffset(2020, 01, 01, 0, 0, 0, new TimeSpan(0, 0, 0));

            AcquiringBankResponse responseMock = new AcquiringBankResponse
            {
                BankId         = expectedBankId,
                PaymentStatus  = "Submitted",
                StatusDateTime = submissionDateTimeMock
            };

            var data        = JsonSerializer.Serialize(responseMock);
            var contentMock = new StringContent(data.ToString(), Encoding.UTF8, "application/json");

            _httpMessageHandlerMock.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = contentMock
            });

            var client = new HttpClient(_httpMessageHandlerMock.Object);

            var sut = new AcquiringBankClient(_acquiringBankSettingsMock.Object, client, _loggerMock.Object);

            // Act
            var result = await sut.SubmitPaymentToBank(paymentRequest);

            // Assert
            Assert.AreEqual(expectedBankId, result.BankId);
            Assert.AreEqual(PaymentStatuses.Submitted, result.PaymentStatus);
            Assert.AreEqual(submissionDateTimeMock, result.StatusDateTime);
        }
Ejemplo n.º 7
0
        public async Task SubmitPaymentToBank_NullPaymentRequest_Throws()
        {
            // Arrange
            PaymentRequest paymentRequest = null;

            _httpMessageHandlerMock.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK
            });

            var client = new HttpClient(_httpMessageHandlerMock.Object);

            var sut = new AcquiringBankClient(_acquiringBankSettingsMock.Object, client, _loggerMock.Object);

            // Act and Assert
            Assert.ThrowsAsync <ArgumentNullException>(() => sut.SubmitPaymentToBank(paymentRequest));
        }
Ejemplo n.º 8
0
        public async Task Return_Failed_Response_When_Request_Is_Not_SuccessFul()
        {
            _server
            .Given(Request.Create()
                   .WithPath($"/api/payment").UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(500));
            _mockAcquiryBankOptions.SetupGet(x => x.CurrentValue)
            .Returns(new AcquiringBankSettings {
                ApiUrl = _server.Urls.First()
            });
            var sut = new AcquiringBankClient(new HttpClient(), _mockAcquiryBankOptions.Object, _mockLogger.Object);


            var response = await sut.ProcessPayment(new BankPaymentRequest
            {
                Amount   = 100,
                Currency = "EUR",
            });

            response.PaymentStatus.Should().Be(PaymentStatus.Failed);
            response.PaymentIdentifier.Should().BeNull();
        }