public async Task ShouldInsert_LoanAgreementAndLoanPymt_UsingLoanAgreementAggregate() { LoanAgreement agreement = new LoanAgreement ( new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement), FinancierId.Create(new Guid("b49471a0-5c1e-4a4d-97e7-288fb0f6338a")), LoanAmount.Create(175000), InterestRate.Create(.0675), LoanDate.Create(new DateTime(2021, 11, 5)), MaturityDate.Create(new DateTime(2022, 11, 5)), PaymentsPerYear.Create(12), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); LoanPayment loanPayment = new LoanPayment ( new EconomicEvent(Guid.NewGuid(), EventType.CashDisbursementForLoanPayment), agreement, PaymentNumber.Create(1), PaymentDueDate.Create(new DateTime(2021, 12, 5)), LoanPrincipalAmount.Create(14135), LoanInterestAmount.Create(984), LoanPrincipalRemaining.Create(160862), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); agreement.AddLoanPayment(loanPayment); await _loanAgreementRepo.AddAsync(agreement); await _unitOfWork.Commit(); var result = await _loanAgreementRepo.Exists(agreement.Id); Assert.True(result); //TODO Test navigation to LoanPayment }
public static async Task Execute ( CreateLoanAgreementInfo model, ILoanAgreementAggregateRepository loanAgreementRepo, IFinancierAggregateRepository financierRepo, IUnitOfWork unitOfWork ) { if (await loanAgreementRepo.Exists(model.Id)) { throw new InvalidOperationException($"This loan agreement already exists!"); } string errMsg = $"Unable to create loan agreement info, a financier with id {model.FinancierId} could not be found!"; Financier financier = await financierRepo.GetByIdAsync(model.FinancierId) ?? throw new InvalidOperationException(errMsg); LoanAgreement loanAgreement = new LoanAgreement ( new EconomicEvent(model.Id, EventType.CashReceiptFromLoanAgreement), FinancierId.Create(financier.Id), LoanAmount.Create(model.LoanAmount), InterestRate.Create(model.InterestRate), LoanDate.Create(model.LoanDate), MaturityDate.Create(model.MaturityDate), PaymentsPerYear.Create(model.PaymentsPerYear), model.UserId ); await loanAgreementRepo.AddAsync(loanAgreement); await unitOfWork.Commit(); }
public async Task ShouldInsert_StockSubscriptionAndDividendDeclaration_UsingStockSubscriptionAggregate() { StockSubscription stockSubscription = new StockSubscription ( new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromStockSubscription), FinancierId.Create(new Guid("84164388-28ff-4b47-bd63-dd9326d32236")), StockIssueDate.Create(new DateTime(2021, 11, 9)), SharesIssured.Create(33333), PricePerShare.Create(.33M), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); DividendPaymentRate dividendPayment = new DividendPaymentRate ( new EconomicEvent(Guid.NewGuid(), EventType.CashDisbursementForDividentPayment), stockSubscription, DividendDeclarationDate.Create(new DateTime(2021, 11, 22)), DividendPerShare.Create(.02M), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); stockSubscription.AddDividendPaymentRate(dividendPayment); await _stockSubscriptionRepo.AddAsync(stockSubscription); await _unitOfWork.Commit(); var result = await _stockSubscriptionRepo.Exists(stockSubscription.Id); Assert.True(result); }
public StockSubscription ( EconomicEvent economicEvent, FinancierId financierId, StockIssueDate stockIssueDate, SharesIssured sharesIssured, PricePerShare pricePerShare, UserId userId ) { EconomicEvent = economicEvent ?? throw new ArgumentNullException("The economic event is required."); Id = economicEvent.Id; FinancierId = financierId ?? throw new ArgumentNullException("The financier id is required."); StockIssueDate = stockIssueDate ?? throw new ArgumentNullException("The stock issue date is required."); SharesIssured = sharesIssured ?? throw new ArgumentNullException("The shares issued amount is required."); PricePerShare = pricePerShare ?? throw new ArgumentNullException("The price per share is required."); UserId = userId ?? throw new ArgumentNullException("The id of the employee recording this stock subscription is required."); }
public void ShouldReturn_NewLoanAgreement() { var economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement); Financier financier = GetFinancier(); LoanAgreement agreement = new LoanAgreement ( economicEvent, FinancierId.Create(financier.Id), LoanAmount.Create(10000), InterestRate.Create(.006), LoanDate.Create(new DateTime(2020, 12, 31)), MaturityDate.Create(new DateTime(2021, 12, 31)), PaymentsPerYear.Create(12), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); Assert.IsType <LoanAgreement>(agreement); }
public void ShouldRaiseError_DefaultLoanDate() { var economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement); Financier financier = GetFinancier(); Assert.Throws <ArgumentNullException>(() => { new LoanAgreement ( economicEvent, FinancierId.Create(financier.Id), LoanAmount.Create(10000), InterestRate.Create(.006), LoanDate.Create(new DateTime()), MaturityDate.Create(new DateTime(2021, 12, 31)), PaymentsPerYear.Create(12), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); }); }
public async Task ShouldInsert_StockSubscription_UsingStockSubscriptionRepo() { StockSubscription subscription = new StockSubscription ( new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromStockSubscription), FinancierId.Create(new Guid("84164388-28ff-4b47-bd63-dd9326d32236")), StockIssueDate.Create(new DateTime(2021, 11, 9)), SharesIssured.Create(33333), PricePerShare.Create(.33M), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); await _stockSubscriptionRepo.AddAsync(subscription); await _unitOfWork.Commit(); var result = await _stockSubscriptionRepo.Exists(subscription.Id); Assert.True(result); }
public async Task ShouldInsert_LoanAgreement_UsingLoanAgreementRepo() { LoanAgreement agreement = new LoanAgreement ( new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement), FinancierId.Create(new Guid("b49471a0-5c1e-4a4d-97e7-288fb0f6338a")), LoanAmount.Create(175000), InterestRate.Create(.0675), LoanDate.Create(new DateTime(2021, 11, 5)), MaturityDate.Create(new DateTime(2022, 11, 5)), PaymentsPerYear.Create(12), UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744")) ); await _loanAgreementRepo.AddAsync(agreement); await _unitOfWork.Commit(); var result = await _loanAgreementRepo.Exists(agreement.Id); Assert.True(result); }
public LoanAgreement ( EconomicEvent economicEvent, FinancierId financierId, LoanAmount loanAmount, InterestRate interestRate, LoanDate loanDate, MaturityDate maturityDate, PaymentsPerYear paymentsPerYear, UserId userID ) { EconomicEvent = economicEvent ?? throw new ArgumentNullException("The economic event is required."); Id = economicEvent.Id; FinancierId = financierId; LoanAmount = loanAmount ?? throw new ArgumentNullException("The loan amount for this loan agreement is required."); InterestRate = interestRate ?? throw new ArgumentNullException("The interest rate is required; if zero then pass in 0."); LoanDate = loanDate ?? throw new ArgumentNullException("The loan agreement date is required."); MaturityDate = maturityDate ?? throw new ArgumentNullException("The loan maturity date is required."); PaymentsPerYear = paymentsPerYear ?? throw new ArgumentNullException("The number of loan payments per year is required."); UserId = userID ?? throw new ArgumentNullException("The id of the employee recording this loan agreement is required."); CheckValidity(); }