コード例 #1
0
        GetPaymentStatusRethrowsExceptionWhenMobilePayApiHttpClientThrowsAMobilePayExceptionWithUnauthorizedStatusCode()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient         = new Mock <IMobilePayApiHttpClient>();
            var mobilePayApiRequestMessage = new GetPaymentStatusRequest("merchantID", "1234");

            mobilePayApiClient
            .Setup(m => m.SendRequest <GetPaymentStatusResponse>(
                       mobilePayApiRequestMessage))
            .ThrowsAsync(
                new MobilePayException(new DefaultErrorMessage
            {
                Reason = MobilePayErrorReason.Other
            }, HttpStatusCode.Unauthorized));

            var log = new Mock <ILogger <MobilePayService> >();

            // Act
            var mobilePayService = new MobilePayService(mobilePayApiClient.Object, mobilePaySettings, log.Object);

            // Assert
            await Assert.ThrowsAsync <MobilePayException>(() => mobilePayService.GetPaymentStatus("1234"));
        }
コード例 #2
0
        public async Task GetPaymentStatusGivenOrderIdCallsMobilePayApiHttpClient()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient         = new Mock <IMobilePayApiHttpClient>();
            var mobilePayApiRequestMessage = new GetPaymentStatusRequest("merchantID", "1234");

            mobilePayApiClient
            .Setup(m => m.SendRequest <GetPaymentStatusResponse>(
                       mobilePayApiRequestMessage))
            .ReturnsAsync(
                new GetPaymentStatusResponse
            {
                LatestPaymentStatus = PaymentStatus.Reserved,
                OriginalAmount      = 80.0,
                TransactionId       = "transId"
            });

            var log = new Mock <ILogger <MobilePayService> >();

            var mobilePayService = new MobilePayService(mobilePayApiClient.Object, mobilePaySettings, log.Object);

            // Act
            await mobilePayService.GetPaymentStatus("1234");

            // Assert
            mobilePayApiClient.Verify(
                m =>
                m.SendRequest <GetPaymentStatusResponse>(mobilePayApiRequestMessage),
                Times.Once);
        }
コード例 #3
0
        GetPaymentStatusRetriesWhenMobilePayApiHttpClientThrowsAMobilePayExceptionWithRequestTimeOutStatusCode()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient         = new Mock <IMobilePayApiHttpClient>();
            var mobilePayApiRequestMessage = new GetPaymentStatusRequest("merchantID", "1234");

            mobilePayApiClient
            .SetupSequence(m => m.SendRequest <GetPaymentStatusResponse>(
                               mobilePayApiRequestMessage))
            // Throw exception first time
            .ThrowsAsync(
                new MobilePayException(new DefaultErrorMessage
            {
                Reason = MobilePayErrorReason.Other
            }, HttpStatusCode.RequestTimeout))
            // Second time returns Response
            .ReturnsAsync(
                new GetPaymentStatusResponse
            {
                LatestPaymentStatus = PaymentStatus.Reserved,
                OriginalAmount      = 80.0,
                TransactionId       = "transId"
            });

            var log = new Mock <ILogger <MobilePayService> >();

            var mobilePayService = new MobilePayService(mobilePayApiClient.Object, mobilePaySettings, log.Object);

            // Act
            await mobilePayService.GetPaymentStatus("1234");

            // Assert
            mobilePayApiClient.Verify(
                m =>
                m.SendRequest <GetPaymentStatusResponse>(mobilePayApiRequestMessage),
                Times.Exactly(2));
        }