示例#1
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);
        }
示例#2
0
        CancelPaymentReservationRethrowsExceptionWhenMobilePayApiHttpClientThrowsAMobilePayExceptionWithUnauthorizedStatusCode()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient = new Mock <IMobilePayApiHttpClient>();
            var requestMessage     = new CancelReservationRequest("merchantID", "1234");

            mobilePayApiClient
            .Setup(m => m.SendRequest <CancelReservationResponse>(
                       requestMessage))
            .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.CancelPaymentReservation("1234"));
        }
示例#3
0
        public async Task CancelPaymentReservationGivenOrderIdCallsMobilePayApiHttpClient()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient = new Mock <IMobilePayApiHttpClient>();
            var requestMessage     = new CancelReservationRequest("merchantID", "1234");

            mobilePayApiClient
            .Setup(m => m.SendRequest <CancelReservationResponse>(
                       requestMessage))
            .ReturnsAsync(
                new CancelReservationResponse
            {
                TransactionId = "transId"
            });

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

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

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

            // Assert
            mobilePayApiClient.Verify(
                m =>
                m.SendRequest <CancelReservationResponse>(requestMessage),
                Times.Once);
        }
示例#4
0
        CancelPaymentReservationRetriesWhenMobilePayApiHttpClientThrowsAMobilePayExceptionWithRequestTimeOutStatusCode()
        {
            // Arrange
            var mobilePaySettings = new MobilePaySettings
            {
                MerchantId = "merchantID"
            };

            var mobilePayApiClient = new Mock <IMobilePayApiHttpClient>();
            var requestMessage     = new CancelReservationRequest("merchantID", "1234");

            mobilePayApiClient
            .SetupSequence(m => m.SendRequest <CancelReservationResponse>(
                               requestMessage))
            // Throw exception first time
            .ThrowsAsync(
                new MobilePayException(new DefaultErrorMessage
            {
                Reason = MobilePayErrorReason.Other
            }, HttpStatusCode.RequestTimeout));

            // Second time returns Response
            var mobilePayApiRequestMessage = new GetPaymentStatusRequest("merchantID", "1234");

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

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

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

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

            // Assert
            mobilePayApiClient.Verify(
                m =>
                m.SendRequest <CancelReservationResponse>(requestMessage),
                Times.Once);
            mobilePayApiClient.Verify(
                m => m.SendRequest <GetPaymentStatusResponse>(mobilePayApiRequestMessage), Times.Once);
        }