Пример #1
0
        public async Task Save_PaymentFullyReceived_SetsReceivedDate()
        {
            var notificationTransaction = CreateNotificationTransaction(1000, new DateTime(2017, 1, 1));

            // Set payment to be the same amount of the transaction
            A.CallTo(() => notificationTransactionCalculator.Balance(notificationId))
            .Returns(1000);
            A.CallTo(() => notificationTransactionRepository.GetTransactions(notificationId))
            .Returns(new List <NotificationTransaction>()
            {
                notificationTransaction
            });

            await transaction.Save(notificationTransaction);

            Assert.Equal(assessment.Dates.PaymentReceivedDate, new DateTime(2017, 1, 1));
        }
Пример #2
0
        public async Task Save(NotificationTransaction transaction)
        {
            if (transaction.Debit > await transactionCalculator.RefundLimit(transaction.NotificationId))
            {
                throw new InvalidOperationException("Transaction cannot refund more than has already been paid");
            }

            var balance = await transactionCalculator.Balance(transaction.NotificationId)
                          - transaction.Credit.GetValueOrDefault()
                          + transaction.Debit.GetValueOrDefault();

            var transactions = (await transactionRepository.GetTransactions(transaction.NotificationId)).ToList();

            transactions.Add(transaction);

            var paymentDate = CalculatePaymentReceivedDate(transactions, balance);

            await UpdatePaymentReceivedDate(paymentDate, transaction.NotificationId);

            transactionRepository.Add(transaction);
        }
Пример #3
0
        public TransactionTests()
        {
            notificationAssessmentRepository  = A.Fake <INotificationAssessmentRepository>();
            notificationTransactionRepository = A.Fake <INotificationTransactionRepository>();
            notificationTransactionCalculator = A.Fake <INotificationTransactionCalculator>();

            assessment = new TestableNotificationAssessment();
            assessment.NotificationApplicationId = notificationId;
            assessment.Dates = new NotificationDates();

            A.CallTo(() => notificationAssessmentRepository.GetByNotificationId(notificationId))
            .Returns(assessment);

            A.CallTo(() => notificationTransactionCalculator.Balance(notificationId))
            .Returns(1000);

            transaction = new Transaction(
                notificationAssessmentRepository,
                notificationTransactionRepository,
                notificationTransactionCalculator);
        }
Пример #4
0
 public async Task <decimal> HandleAsync(GetChargeDue message)
 {
     return(await transactionCalculator.Balance(message.NotificationId));
 }