public async Task CreateReferenceNumberWhenMaxValueIsReachedShouldRetrunTrue(string offerType, string realEstateId, string expectedResult) { var referenceNumberGener = new ReferenceNumberGenerator(this.context); var actualResult = await referenceNumberGener.GenerateOfferReferenceNumber(offerType, realEstateId); Assert.That(expectedResult.Equals(actualResult), ExpectedTrueResultMessage, expectedResult, actualResult); }
public SubmissionRepositoryTests() { fileSystem = new MockFileSystem(); referenceNumberGenerator = new ReferenceNumberGenerator(); configuration = new ConfigurationBuilder().AddInMemoryCollection(new[] { new KeyValuePair <string, string>("Submission_Storage_Path", submissionPersistencePath) }).Build(); }
public void Generate_MultipleTimes_UniqueReferenceNumber() { var numberOfIterations = 1000; var referenceNumbers = new string[numberOfIterations]; for (int i = 0; i < numberOfIterations; i++) { referenceNumbers[i] = ReferenceNumberGenerator.CreateNew(); } Assert.Equal(numberOfIterations, referenceNumbers.Distinct().Count()); }
/// <inheritdoc /> public void ApplyBehaviour() { IList <Transaction> wrongAccountPayments = DiscoverWrongAccountPaymentTransactions(); var reference = ReferenceNumberGenerator.IssueTransactionReferenceNumber(); // Remind the user to make a bank transfer to rectify the situation. CreateUserTasks(wrongAccountPayments, reference); CreateLedgerTransactionsShowingTransfer(wrongAccountPayments, reference); }
private List <LedgerTransaction> IncludeBudgetedAmount(BudgetModel currentBudget, LedgerBucket ledgerBucket, DateTime reconciliationDate) { var budgetedExpense = currentBudget.Expenses.FirstOrDefault(e => e.Bucket.Code == ledgerBucket.BudgetBucket.Code); var transactions = new List <LedgerTransaction>(); if (budgetedExpense != null) { BudgetCreditLedgerTransaction budgetedAmount; if (ledgerBucket.StoredInAccount.IsSalaryAccount) { budgetedAmount = new BudgetCreditLedgerTransaction { Amount = budgetedExpense.Bucket.Active ? budgetedExpense.Amount : 0, Narrative = budgetedExpense.Bucket.Active ? "Budgeted Amount" : "Warning! Bucket has been disabled." }; } else { budgetedAmount = new BudgetCreditLedgerTransaction { Amount = budgetedExpense.Bucket.Active ? budgetedExpense.Amount : 0, Narrative = budgetedExpense.Bucket.Active ? "Budget amount must be transferred into this account with a bank transfer, use the reference number for the transfer." : "Warning! Bucket has been disabled.", AutoMatchingReference = ReferenceNumberGenerator.IssueTransactionReferenceNumber() }; // TODO Maybe the budget should know which account the incomes go into, perhaps mapped against each income? var salaryAccount = this.newReconciliationLine.BankBalances.Single(b => b.Account.IsSalaryAccount).Account; this.toDoList.Add( new TransferTask( string.Format( CultureInfo.CurrentCulture, "Budgeted Amount for {0} transfer {1:C} from Salary Account to {2} with auto-matching reference: {3}", budgetedExpense.Bucket.Code, budgetedAmount.Amount, ledgerBucket.StoredInAccount, budgetedAmount.AutoMatchingReference), true) { Amount = budgetedAmount.Amount, SourceAccount = salaryAccount, DestinationAccount = ledgerBucket.StoredInAccount, BucketCode = budgetedExpense.Bucket.Code, Reference = budgetedAmount.AutoMatchingReference }); } budgetedAmount.Date = reconciliationDate; transactions.Add(budgetedAmount); } return(transactions); }
public void DuplicateReferenceNumberTest() { // ReSharper disable once CollectionNeverQueried.Local var duplicateCheck = new Dictionary <string, string>(); for (var i = 0; i < 1000; i++) { var result = ReferenceNumberGenerator.IssueTransactionReferenceNumber(); Console.WriteLine(result); Assert.IsNotNull(result); duplicateCheck.Add(result, result); } }
public async Task <IActionResult> Create(CashTransferCreateBindingModel model) { var userId = this.GetCurrentUserId(); if (!this.ModelState.IsValid) { model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var account = await this.bankAccountService.GetByIdAsync <BankAccountDetailsServiceModel>(model.AccountId); if (account == null || account.UserId != userId) { return(this.Forbid()); } if (account.Balance < model.Amount) { this.ShowErrorMessage(NotificationMessages.InsufficientFunds); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var referenceNumber = ReferenceNumberGenerator.GenerateReferenceNumber(); var sourceServiceModel = Mapper.Map <CashTransferCreateServiceModel>(model); sourceServiceModel.Amount *= -1; sourceServiceModel.ReferenceNumber = referenceNumber; sourceServiceModel.Description = model.Description; sourceServiceModel.SenderName = account.Name; sourceServiceModel.RecipientName = account.UserFullName; sourceServiceModel.Destination = sourceServiceModel.RecipientName; sourceServiceModel.Source = sourceServiceModel.SenderName; if (!await this.moneyTransferService.CreateCashTransferAsync(sourceServiceModel)) { this.ShowErrorMessage(NotificationMessages.TryAgainLaterError); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } this.ShowSuccessMessage(NotificationMessages.SuccessfulMoneyTransfer); return(this.RedirectToPage("/Account/Login")); }
public async Task <GlobalTransactionResult> TransactAsync(GlobalTransactionDto model) { if (!ValidationUtil.IsObjectValid(model)) { return(GlobalTransactionResult.GeneralFailure); } // TODO: Remove this check or the one in PaymentsController var account = await this.bankAccountService .GetByUniqueIdAsync <BankAccountConciseServiceModel>(model.DestinationBankAccountUniqueId); if (account == null) { return(GlobalTransactionResult.GeneralFailure); } if (account.Balance < model.Amount) { return(GlobalTransactionResult.InsufficientFunds); } var serviceModel = new TransactionCreateServiceModel { Amount = -model.Amount, Source = account.UniqueId, Description = model.Description ?? String.Empty, AccountId = account.Id, DestinationBankAccountUniqueId = model.DestinationBankAccountUniqueId, SenderName = account.UserFullName, RecipientName = model.RecipientName, ReferenceNumber = ReferenceNumberGenerator.GenerateReferenceNumber() }; bool success = await this.transactionService.CreateTransactionAsync(serviceModel); return(!success ? GlobalTransactionResult.GeneralFailure : GlobalTransactionResult.Succeeded); }
public void Generate_TemplatedReferenceNumber() { var referenceNumber = ReferenceNumberGenerator.CreateNew(); Assert.StartsWith($"SUP-{DateTime.Today:yyyyMMdd}", referenceNumber); }
public ReferenceNumberGeneratorTests() { referenceNumberGenerator = new ReferenceNumberGenerator(); }
public async Task <IActionResult> Create(InternalMoneyTransferCreateBindingModel model) { var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name); if (!this.ModelState.IsValid) { model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var account = await this.bankAccountService.GetByIdAsync <BankAccountDetailsServiceModel>(model.AccountId); if (account == null || account.UserUserName != this.User.Identity.Name) { return(this.Forbid()); } if (string.Equals(account.UniqueId, model.DestinationBankAccountUniqueId, StringComparison.InvariantCulture)) { this.ShowErrorMessage(NotificationMessages.SameAccountsError); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } if (account.Balance < model.Amount) { this.ShowErrorMessage(NotificationMessages.InsufficientFunds); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var destinationAccount = await this.bankAccountService.GetByUniqueIdAsync <BankAccountConciseServiceModel>( model.DestinationBankAccountUniqueId); if (destinationAccount == null) { this.ShowErrorMessage(NotificationMessages.DestinationBankAccountDoesNotExist); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var referenceNumber = ReferenceNumberGenerator.GenerateReferenceNumber(); var sourceServiceModel = Mapper.Map <MoneyTransferCreateServiceModel>(model); sourceServiceModel.Source = account.UniqueId; sourceServiceModel.Amount *= -1; sourceServiceModel.SenderName = account.UserFullName; sourceServiceModel.RecipientName = destinationAccount.UserFullName; sourceServiceModel.ReferenceNumber = referenceNumber; if (!await this.moneyTransferService.CreateMoneyTransferAsync(sourceServiceModel)) { this.ShowErrorMessage(NotificationMessages.TryAgainLaterError); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var destinationServiceModel = Mapper.Map <MoneyTransferCreateServiceModel>(model); destinationServiceModel.Source = account.UniqueId; destinationServiceModel.AccountId = destinationAccount.Id; destinationServiceModel.SenderName = account.UserFullName; destinationServiceModel.RecipientName = destinationAccount.UserFullName; destinationServiceModel.ReferenceNumber = referenceNumber; if (!await this.moneyTransferService.CreateMoneyTransferAsync(destinationServiceModel)) { this.ShowErrorMessage(NotificationMessages.TryAgainLaterError); model.OwnAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } this.ShowSuccessMessage(NotificationMessages.SuccessfulMoneyTransfer); return(this.RedirectToHome()); }