/// <inheritdoc /> public string OpenAccount( AccountType accountType, string ownerFirstName, string ownerSecondName, decimal sum, string ownerEmail, IAccountIdService accountIdService) { VerifyInput(ownerFirstName, ownerSecondName, sum, ownerEmail, accountIdService); try { string accountId = this.GetUniqueAccoutId(ownerFirstName, ownerSecondName, accountIdService); string accountIdHash = GetSha256Hash(accountId); int initialBonuses = GetInitialBonuses(accountType); var account = CreateAccount(accountType, accountIdHash, ownerFirstName, ownerSecondName, sum, initialBonuses, ownerEmail); _accountRepository.AddAccount(account.ToDalAccount()); string subject = "Opened account on localhost!"; string message = $"Thank you for choosing our service!<br/>Your account ID: {accountId}"; this.SendMail(ownerEmail, subject, message); _unitOfWork.Commit(); return(accountId); } catch (Exception e) { throw new AccountServiceException("Open account error", e); } }
public void Before() { var accIdServiceMock = new Mock <IAccountIdService>(); accIdServiceMock.SetupProperty(acc => acc.PrimaryNumber, 0); accIdServiceMock.Setup(acc => acc.GenerateAccountId()).Returns(1); _accountIdService = accIdServiceMock.Object; }
/// <summary> /// Initializes account service with the passed parameters. /// </summary> /// <param name="accountRepository">account repository</param> /// <param name="accountIdService">account number generation service</param> /// <exception cref="ArgumentNullException">Exception thrown when /// <paramref name="accountRepository"/> or <paramref name="accountIdService"/> is null.</exception> public AccountService(IAccountRepository accountRepository, IAccountIdService accountIdService) { VerifyNull(accountRepository, nameof(accountRepository)); VerifyNull(accountIdService, nameof(accountIdService)); _accountRepository = accountRepository; _accountIdService = accountIdService; }
/// <inheritdoc /> public string OpenAccount( string ownerFirstName, string ownerSecondName, decimal sum, string ownerEmail, IAccountIdService accountIdService) { return(OpenAccount( AccountType.Base, ownerFirstName, ownerSecondName, sum, ownerEmail, accountIdService)); }
private string GetUniqueAccoutId( string ownerFirstName, string ownerSecondName, IAccountIdService accountIdService, int spinCount = 4000) { string id; int i = 0; var temp = _accountRepository.GetAccounts(); var dalAccounts = temp as DalAccount[] ?? temp.ToArray(); do { id = accountIdService.GenerateAccountId(ownerFirstName, ownerSecondName); if (++i >= spinCount) { throw new AccountServiceException("Failed to get the unique account ID."); } }while (dalAccounts.Any(dalAccount => string.Compare(dalAccount.Id, id, StringComparison.Ordinal) == 0)); return(id); }
private static void VerifyInput( string ownerFirstName, string ownerSecondName, decimal sum, string ownerEmail, IAccountIdService accountIdService) { if (string.IsNullOrWhiteSpace(ownerFirstName)) { throw new ArgumentException($"{nameof(ownerFirstName)} IsNullOrWhiteSpace", nameof(ownerFirstName)); } if (string.IsNullOrWhiteSpace(ownerSecondName)) { throw new ArgumentException($"{nameof(ownerSecondName)} IsNullOrWhiteSpace", nameof(ownerSecondName)); } if (sum < 0) { throw new ArgumentException("sum must be greater than 0", nameof(sum)); } try { var mailAddress = new MailAddress(ownerEmail); } catch (Exception) { throw new ArgumentException($"{nameof(ownerEmail)} is invalid.", nameof(ownerEmail)); } if (ReferenceEquals(accountIdService, null)) { throw new ArgumentNullException(nameof(accountIdService)); } }
public AccountController(IAccountService accountService, IAccountIdService accountIdService) { _accountService = accountService; _accountIdService = accountIdService; }
static Program() { NinjectKernel = new StandardKernel(); NInjectDependencyResolver.Configure(NinjectKernel); AccountIdService = NinjectKernel.Get <IAccountIdService>(); }
public AccountService(IAccountIdService accountIdService, IRepository <DTOAccount> repository) { _accountIdService = accountIdService ?? throw new ArgumentNullException("Account id service must not be null"); _repository = repository ?? throw new ArgumentNullException("Repository must not be null"); InitAccountIdService(); }