public async Task <IActionResult> ProcessLoan( [FromServices] ILoanRepository repository, [FromRoute] Guid id, [FromServices] LoanProcessor processor, [FromServices] IQueryProcessor queryProcessor, CancellationToken cancellationToken) { var loan = await repository.Get(id, cancellationToken); if (loan == null) { throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.LoanNotFound, $"Loan {id} not found"); } try{ await processor.Process(loan, cancellationToken); await repository.Save(loan, cancellationToken); } catch (InvalidOperationException) { throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.IncorrectOperation, $"Incorrect loan state"); } return(Ok(await queryProcessor.Process <LoanViewQuery, LoanView>(new LoanViewQuery(id), cancellationToken))); }
public LoanOperationCreatedEventHandler( LoanProcessor loanProcessor, ILoanRepository loanRepository, ILogger <LoanOperationCreatedEventHandler> logger ) { _loanProcessor = loanProcessor; _loanRepository = loanRepository; _logger = logger; }
public LoanRecurrentProcessor( IServiceScopeFactory scopeFactory, ILogger <LoanRecurrentProcessor> logger) { _logger = logger; _scopeFactory = scopeFactory; _loanExpireProcessor = scopeFactory.CreateScope().ServiceProvider.GetService <LoanExpireProcessor>(); _loanTaxProcessor = scopeFactory.CreateScope().ServiceProvider.GetService <LoanTaxProcessor>(); _loanProcessor = scopeFactory.CreateScope().ServiceProvider.GetService <LoanProcessor>(); }
[TestMethod] //£1108.10 public void ProcessLoan_WhenRateIs7PercentAndBorrowerAmountIs1000AndTenureIs36Months_Returns1108Pound10PAsTotalRepaymentAmount() { // Arrange var mockRateCalculator = MockRepository.GenerateMock <IMarketDataRateCalculator>(); var mockMarketDataConfig = MockRepository.GenerateMock <IMarketDataConfiguration>(); mockMarketDataConfig.Stub(c => c.LoanTenure).Return(36); mockMarketDataConfig.Stub(c => c.BorrowerLoanAmount).Return(1000); mockRateCalculator.Stub(r => r.CalculateBestRate(1000.0d)).Return(0.070039999999999991); var loanProcessor = new LoanProcessor(mockRateCalculator, mockMarketDataConfig); // Act loanProcessor.ProcessLoan(); // Assert Assert.AreEqual(1108.10, loanProcessor.TotalRepayment); }
static void Main(string[] args) { if (args == null || args.Length != 1) { Console.WriteLine("no base path argument found..."); return; } var basePath = args[0]; if (string.IsNullOrEmpty(basePath)) { Console.WriteLine("no base path found..."); return; } var facilities = new FacilityService().GetFacilities($"{basePath}/facilities.csv"); var banks = new BankService().GetBanks($"{basePath}/banks.csv"); var covenants = new CovenantsService().GetCovenants($"{basePath}/covenants.csv"); var loans = new LoanService().GetLoans($"{basePath}/loans.csv"); var loanProcessor = new LoanProcessor(facilities, banks, covenants); var processOutput = loanProcessor.ProcessLoans(loans); var dateFormat = DateTime.Now.ToString("s"); var assignmentsFilePath = $"{basePath}/assignment__{dateFormat}_.csv"; var yieldsFilePath = $"{basePath}/yields__{dateFormat}_.csv"; YieldsService yieldsService = new YieldsService(); yieldsService.WriteYieldsToCSV(processOutput.Yields, yieldsFilePath); AssignmentService assignmentService = new AssignmentService(); assignmentService.WriteAssignmentsToCSV(processOutput.Assignments, assignmentsFilePath); Console.WriteLine(" end of loan assignment process... "); }