public void CheckDueDate(Invoice invoiceContainingTheBill, Bill billToCheck, DateTime todayDate)
 {
     bool itWasToCollect = billToCheck.PaymentResult == Bill.BillPaymentResult.ToCollect;
     billToCheck.CheckDueDate(todayDate);
     bool itIsUnpaid = billToCheck.PaymentResult == Bill.BillPaymentResult.Unpaid;
     if (itWasToCollect && itIsUnpaid) invoiceContainingTheBill.SetInvoiceAsUnpaid();
 }
 private PaymentAgreement GetActiveAgreementFromBill(Bill bill)
 {
     if (bill.PaymentAgreements.Count == 0) return null;
     PaymentAgreement activePaymentAgreement =
         bill.PaymentAgreements.First(keyValuePair => keyValuePair.Value.PaymentAgreementActualStatus == PaymentAgreement.PaymentAgreementStatus.Active).Value;
     return activePaymentAgreement;
 }
 public void ABillPastDueDateIsMarkedAsUnpaid()
 {
     Bill bill = new Bill("MMM201300015/001", "This bill is past due date", 1, new DateTime(2013, 11, 11), new DateTime(2013, 11, 15));
     Assert.AreEqual(Bill.BillPaymentResult.ToCollect, bill.PaymentResult);
     bill.CheckDueDate(new DateTime(2013,11,30));
     Assert.AreEqual(Bill.BillPaymentResult.Unpaid, bill.PaymentResult);
 }
 public void ABillIsCorrectlyCreated()
 {
     DateTime issueDate = new DateTime(2013, 11, 11);
     DateTime dueDate = issueDate.AddYears(10);
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, issueDate, dueDate);
     Assert.AreEqual("MMM201300015/001", bill.BillID);
     Assert.AreEqual("An easy to pay bill", bill.Description);
     Assert.AreEqual((decimal)1, bill.Amount);
     Assert.AreEqual(issueDate, bill.IssueDate);
     Assert.AreEqual(dueDate, bill.DueDate);
 }
 private void CheckIfAgreementIsAccomplished(Invoice invoiceContainingTheBill, Bill paidBill)
 {
     PaymentAgreement activeAgreement = GetActiveAgreementFromBill(paidBill);
     if (activeAgreement!=null)
     {
         DateTime agreementDate = activeAgreement.AgreementDate;
         var billsIncludedInTheAgreement = invoiceContainingTheBill.Bills.Values.Where(bill => bill.PaymentAgreements.ContainsKey(agreementDate));
         var unpaidBillsFromAgreement = billsIncludedInTheAgreement.Where(bill => bill.PaymentResult == Bill.BillPaymentResult.ToCollect);
         if (unpaidBillsFromAgreement.Count() == 0)
         {
             foreach (Bill bill in billsIncludedInTheAgreement)
                 bill.PaymentAgreements[agreementDate].PaymentAgreementActualStatus = PaymentAgreement.PaymentAgreementStatus.Accomplished;
             invoiceContainingTheBill.PaymentAgreements[agreementDate].PaymentAgreementActualStatus = PaymentAgreement.PaymentAgreementStatus.Accomplished;
         }
     }
 }
Пример #6
0
 private decimal GetBillsTotalAmount(Bill.BillPaymentResult paymentResult)
 {
     decimal amount = 0;
     foreach (KeyValuePair<string, Bill> bill in invoiceBills)
     {
         if (bill.Value.PaymentResult == paymentResult) amount += bill.Value.Amount;
     }
     return amount;
 }
 public void ABillShouldHaveABillID()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     Assert.AreEqual("MMM201300015/001", bill.BillID);
 }
 public void AsigningAPaymentMethodToANewlyCreatedBill()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     bill.AssignedPaymentMethod = new CashPaymentMethod();
     Assert.AreEqual(typeof(CashPaymentMethod),bill.AssignedPaymentMethod.GetType());
 }
 public void WhenIRenewTheDueDateOfABillItIsCorrectlyUpdated()
 {
     Bill bill = new Bill("MMM201300015/001", "This bill is past due date", 1, new DateTime(2013, 11, 11), new DateTime(2013, 11, 15));
     DateTime newDueDate = new DateTime(2013, 11, 30);
     DateTime todayDate = new DateTime(2013, 11, 20);
     bill.RenewDueDate(newDueDate, todayDate);
     Assert.AreEqual(newDueDate, bill.DueDate);
 }
 public void WhenABillIsPaidByDirectDebitTheDebtorAccountAndTheDirectDebitTransactionPaymentIdentificartionAreStored()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     int internalReferenceNumber = 2645;
     BankAccount bankAccount = new BankAccount(new ClientAccountCodeCCC("12345678061234567890"));
     DateTime directDebitMandateCreationDate = new DateTime(2013, 11, 11);
     DirectDebitMandate directDebitMandate = new DirectDebitMandate(internalReferenceNumber, directDebitMandateCreationDate, bankAccount, "NoName");
     string directDebitTransactionPaymentIdentification = "201311110000123456";
     DirectDebitPaymentMethod directDebitTransfermethod = new DirectDebitPaymentMethod(directDebitMandate, directDebitTransactionPaymentIdentification);
     DateTime paymentDate = new DateTime(2013, 11, 11);
     Payment payment = new Payment(bill.Amount, paymentDate, directDebitTransfermethod);
     bill.PayBill(payment);
     Assert.AreEqual("12345678061234567890", ((DirectDebitPaymentMethod)bill.Payment.PaymentMethod).DirectDebitMandate.BankAccount.CCC.CCC);
     Assert.AreEqual("201311110000123456", ((DirectDebitPaymentMethod)bill.Payment.PaymentMethod).DDTXPaymentIdentification);
 }
 public void WhenABillIsPaidByBankTransferTheTransferorAndTheTransfereeAccountsAreStored()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     BankAccount transferorAccount = new BankAccount(new ClientAccountCodeCCC("20381111401111111111"));
     BankAccount transfereeAccount = new BankAccount(new ClientAccountCodeCCC("21001111301111111111"));
     BankTransferPaymentMethod bankTransferPaymentMethod = new BankTransferPaymentMethod(transferorAccount, transfereeAccount);
     DateTime paymentDate = new DateTime(2013, 11, 11);
     Payment payment = new Payment(bill.Amount, paymentDate, bankTransferPaymentMethod);
     bill.PayBill(payment);
     Assert.AreEqual(transferorAccount, ((BankTransferPaymentMethod)bill.Payment.PaymentMethod).TransferorAccount);
     Assert.AreEqual(transfereeAccount, ((BankTransferPaymentMethod)bill.Payment.PaymentMethod).TransfereeAccount);
 }
 public void OnlyPaymentsForTheTotalBillAmoutAreAccepted()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     CashPaymentMethod cashPaymentMethod = new CashPaymentMethod();
     DateTime paymentDate = new DateTime(2013, 11, 11);
     Payment payment = new Payment((decimal)2, paymentDate, cashPaymentMethod);
     try
     {
         bill.PayBill(payment);
     }
     catch (ArgumentException exception)
     {
         Assert.AreEqual("Only payments for the bill total amount are accepted", exception.GetMessageWithoutParamName());
         throw exception;
     }
 }
 public void IfTheBillIsNotPastDueDateItKeepsToCollect()
 {
     Bill bill = new Bill("MMM201300015/001", "This bill is not past due date", 1, new DateTime(2013, 11, 01), new DateTime(2013, 12, 01));
     Assert.AreEqual(Bill.BillPaymentResult.ToCollect, bill.PaymentResult);
     bill.CheckDueDate(new DateTime(2013, 11, 30));
     Assert.AreEqual(Bill.BillPaymentResult.ToCollect, bill.PaymentResult);
 }
 public void ByDefaultABillIsGeneratedWithoutAPaymentMethod()
 {
     Bill bill = new Bill("MMM201300015/001","An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     Assert.IsNull(bill.AssignedPaymentMethod);
 }
 public void BillIDCanBeNullForLaterInitializationWhenAssignedToInvoices()
 {
     Bill bill = new Bill("An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     Assert.IsNull(bill.BillID);
 }
 public void PayBill(Invoice invoiceContainingTheBill, Bill billToPay, Payment payment)
 {
     billToPay.PayBill(payment);
     CheckIfAgreementIsAccomplished(invoiceContainingTheBill, billToPay);
     invoiceContainingTheBill.CheckIfInvoiceIsFullPaid();
 }
 public void RenewBillDueDate(Invoice invoiceContainingTheBill, Bill billToRenew, DateTime newDueDate, DateTime todayDate)
 {
     billToRenew.RenewDueDate(newDueDate, todayDate);
     invoiceContainingTheBill.SetInvoiceToBePaidIfHasNoUnpaidBills();
 }
 public void WhenIRenewTheDueDateOfAPastDueDateBillTheBillIsSetAgainToToCollect()
 {
     Bill bill = new Bill("MMM201300015/001", "This bill is past due date", 1, new DateTime(2013, 11, 11), new DateTime(2013, 11, 15));
     DateTime newDueDate = new DateTime(2013, 11, 30);
     DateTime todayDate = new DateTime(2013, 11, 20);
     bill.CheckDueDate(todayDate);
     Assert.AreEqual(Bill.BillPaymentResult.Unpaid, bill.PaymentResult);
     bill.RenewDueDate(newDueDate, todayDate);
     Assert.AreEqual(Bill.BillPaymentResult.ToCollect, bill.PaymentResult);
 }
 public void WhenPayingABillTheBillPaymentDateIsStored()
 {
     Bill bill = new Bill("MMM201300015/001", "An easy to pay bill", 1, DateTime.Now, DateTime.Now.AddYears(10));
     CashPaymentMethod cashPayment = new CashPaymentMethod();
     DateTime paymentDate = new DateTime(2013, 11, 11);
     Payment payment = new Payment(bill.Amount, paymentDate, cashPayment);
     bill.PayBill(payment);
     Assert.AreEqual(paymentDate, bill.Payment.PaymentDate);
 }
 public void AddBilllToExistingDirectDebitTransaction(DirectDebitTransaction directDebitTransaction, Bill bill)
 {
     directDebitTransaction.AddBill(bill);
 }