コード例 #1
0
 public async void ShouldNotMakePaymentForInactiveSession(Card paymentCard)
 {
     using (var context = new PaymentContext(optionsFactory))
     {
         DbPaymentRepository repository = new DbPaymentRepository(context);
         await Assert.ThrowsAsync <PaymentException>(() => repository.MakePaymentAsync(Guid.Empty, paymentCard));
     }
 }
コード例 #2
0
 public async void ShouldNotAcceptAnyGuidAsActiveSessionId()
 {
     using (var context = new PaymentContext(optionsFactory))
     {
         DbPaymentRepository repository = new DbPaymentRepository(context);
         await Assert.ThrowsAsync <SessionException>(() => repository.SessionIsActiveAsync(Guid.Empty));
     }
 }
コード例 #3
0
 public async void ShouldRememberSession(PaymentRequest payment)
 {
     using (var context = new PaymentContext(optionsFactory))
     {
         DbPaymentRepository repository = new DbPaymentRepository(context);
         await repository.SessionIsActiveAsync(await repository.RecordPaymentAsync(payment));
     }
 }
コード例 #4
0
        public async void ShouldSuccessfullyMakePaymentForActiveSession(
            PaymentRequest payment, Card paymentCard
            )
        {
            using (var context = new PaymentContext(optionsFactory))
            {
                DbPaymentRepository repository = new DbPaymentRepository(context);
                Guid sessionId = await repository.RecordPaymentAsync(payment);

                await repository.MakePaymentAsync(sessionId, paymentCard);
            }
        }
コード例 #5
0
        public async void ShouldNotConsiderExpiredSessionActive(PaymentRequest payment)
        {
            using (var context = new PaymentContext(optionsFactory))
            {
                DbPaymentRepository repository = new DbPaymentRepository(context);
                repository.SessionExpirationTimeSpan = TimeSpan.FromSeconds(1);
                Guid sessionId = await repository.RecordPaymentAsync(payment);

                Thread.Sleep(2 * 1000);
                await Assert.ThrowsAsync <SessionException>(() => repository.SessionIsActiveAsync(sessionId));
            }
        }
コード例 #6
0
        public async void ShouldNotRepeatPayment(
            PaymentRequest payment, Card paymentCard
            )
        {
            using (var context = new PaymentContext(optionsFactory))
            {
                DbPaymentRepository repository = new DbPaymentRepository(context);
                Guid sessionId = await repository.RecordPaymentAsync(payment);

                await repository.MakePaymentAsync(sessionId, paymentCard);

                await Assert.ThrowsAsync <PaymentException>(() => repository.MakePaymentAsync(sessionId, paymentCard));
            }
        }
コード例 #7
0
        public async void ShouldNotListPaymentOutOfDatePeriod(PaymentRequest payment)
        {
            using (var context = new PaymentContext(optionsFactory))
            {
                DbPaymentRepository         repository = new DbPaymentRepository(context);
                IEnumerable <PaymentRecord> payments   = repository.GetPaymentHistoryAsync(
                    DateTime.Today, DateTime.Today
                    ).ToEnumerable();
                Assert.Empty(payments);
                Guid id = await repository.RecordPaymentAsync(payment);

                payments = repository.GetPaymentHistoryAsync(
                    DateTime.Today.AddDays(2), DateTime.Today.AddDays(3)
                    ).ToEnumerable();
                Assert.Empty(payments);
            }
        }
コード例 #8
0
        public async void ShouldListPaymentsRequestedInDatePeriod(PaymentRequest payment)
        {
            using (var context = new PaymentContext(optionsFactory))
            {
                DbPaymentRepository         repository = new DbPaymentRepository(context);
                IEnumerable <PaymentRecord> payments   = repository
                                                         .GetPaymentHistoryAsync(DateTime.Today, DateTime.Today)
                                                         .ToEnumerable();
                Assert.Empty(payments);
                Guid id = await repository.RecordPaymentAsync(payment);

                payments = repository
                           .GetPaymentHistoryAsync(DateTime.Today, DateTime.Today)
                           .ToEnumerable();
                Assert.Collection(payments, item => {
                    Assert.Equal(payment.Sum, item.PaymentSum);
                    Assert.Equal(payment.Purpose, item.Purpose);
                });
            }
        }