예제 #1
0
        public async Task Find_AcquiringBankPaymentId_ReturnsPayment()
        {
            // Arrange
            var          logger = Substitute.For <ILogger <PaymentsController> >();
            var          paymentRequestProcessorSub = Substitute.For <IPaymentRequestProcessor>();
            var          paymentFinderSub           = Substitute.For <IPaymentFinder>();
            var          acquiringBankPaymentId     = Guid.NewGuid().ToString();
            var          timestamp        = DateTime.Now;
            const string MaskedCardNumber = "123456******1234";
            var          expiryDate       = DateTime.Now;
            const string cardHolderName   = "John Smith";

            paymentFinderSub
            .Find(100, acquiringBankPaymentId)
            .Returns(new Payment(1,
                                 100,
                                 cardHolderName,
                                 MaskedCardNumber,
                                 expiryDate,
                                 new Money(100, "GBP"),
                                 acquiringBankPaymentId,
                                 PaymentStatus.Denied,
                                 timestamp));
            var controller = new PaymentsController(paymentRequestProcessorSub, paymentFinderSub, logger);

            // Act
            var response = await controller.Find(100, acquiringBankPaymentId);

            // Assert
            Assert.NotNull(response);
            Assert.NotNull(response.Result);
            Assert.IsType <OkObjectResult>(response.Result);
            var result = (OkObjectResult)response.Result;
            var value  = (PaymentDto)result.Value;

            Assert.Equal(1, value.Id);
            Assert.Equal(100, value.MerchantId);
            Assert.Equal(cardHolderName, value.CardHolderName);
            Assert.Equal(MaskedCardNumber, value.MaskedCardNumber);
            Assert.Equal(expiryDate, value.ExpiryDate);
            Assert.Equal(100M, value.Amount);
            Assert.Equal("GBP", value.Currency);
            Assert.Equal(PaymentStatus.Denied.ToString(), value.Status);
            Assert.Equal(timestamp, value.Timestamp);
        }
예제 #2
0
        public async Task Find_AcquiringBankPaymentId_ReturnsNotFound()
        {
            // Arrange
            var logger = Substitute.For <ILogger <PaymentsController> >();
            var paymentRequestProcessorSub = Substitute.For <IPaymentRequestProcessor>();
            var paymentFinderSub           = Substitute.For <IPaymentFinder>();
            var acquiringBankPaymentId     = Guid.NewGuid().ToString();

            paymentFinderSub.Find(100, acquiringBankPaymentId).Returns((Payment)null);
            var controller = new PaymentsController(paymentRequestProcessorSub, paymentFinderSub, logger);

            // Act
            var response = await controller.Find(100, acquiringBankPaymentId);

            // Assert
            Assert.NotNull(response);
            Assert.NotNull(response.Result);
            Assert.IsType <NotFoundResult>(response.Result);
        }