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)); } }
public async void ShouldNotAcceptAnyGuidAsActiveSessionId() { using (var context = new PaymentContext(optionsFactory)) { DbPaymentRepository repository = new DbPaymentRepository(context); await Assert.ThrowsAsync <SessionException>(() => repository.SessionIsActiveAsync(Guid.Empty)); } }
public async void ShouldRememberSession(PaymentRequest payment) { using (var context = new PaymentContext(optionsFactory)) { DbPaymentRepository repository = new DbPaymentRepository(context); await repository.SessionIsActiveAsync(await repository.RecordPaymentAsync(payment)); } }
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); } }
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)); } }
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)); } }
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); } }
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); }); } }