public void AccountSubscribeToCommissionFail() { //Arrange CommissionAccount acc = new CommissionAccount("123", 10, Currency.AUD); //Assert AccountManager nothing = null; var ex = Assert.Throws <ArgumentNullException>(() => acc.SubscribeToCommission(nothing)); Assert.AreEqual($"{ExceptionMessages.AccountSubscribeNullParam() + Environment.NewLine}Parameter name: accountManager", ex.Message); }
public void AccountContextOK() { IAccountManager manager = new AccountManager10percent(); AccountContext context = new AccountContext(manager); Account accFrom = new Account("from", 200m, Currency.USD); Account accTo = new Account("to", 50m, Currency.USD); CommissionAccount accCommission = new CommissionAccount("commission", 0m, Currency.USD); accCommission.SubscribeToCommission(context.Manager); context.Transaction(accFrom, accTo, 100m, Currency.USD); Assert.AreEqual(90m, accFrom.Money.Amount); Assert.AreEqual(150m, accTo.Money.Amount); Assert.AreEqual(10m, accCommission.Money.Amount); }
public void AccountCheckComission() { //Arrange AccountManager accountManager = new AccountManager(0.01m, Currency.CHF); Account accFrom = new Account("from", 547.345m, Currency.USD); Account accTo = new Account("to", 56.234m, Currency.EUR); CommissionAccount commissionAccount = new CommissionAccount("our money", Currency.CHF); commissionAccount.SubscribeToCommission(accountManager); //Act accountManager.Transaction(accFrom, accTo, 78.12m); //Assert Assert.AreEqual(0.771934968m, commissionAccount.Money.Amount); }
public void AccountManagerConversionOK() { //Arrange AccountManager accM = new AccountManager(0.01m, Currency.USD); Account acc1 = new Account("1", 10, Currency.USD); Account acc2 = new Account("2", 20, Currency.GBP); Account acc3 = new Account("3", 5000, Currency.JPY); CommissionAccount commissionAccount = new CommissionAccount("ourMoney", Currency.USD); commissionAccount.SubscribeToCommission(accM); //Act accM.Conversion(acc1, Currency.EUR); accM.Conversion(acc2, Currency.AUD); accM.Conversion(acc3, Currency.USD); //Assert Assert.AreEqual(0.808618m, commissionAccount.Money.Amount); }
public async Task <TransactionCheckResult> TransactionAsync(string accFromName, string userFromName, string accToName, string userToName, decimal amount) { TransactionCheckResult result = new TransactionCheckResult(); if (accFromName == accToName && userFromName == userToName) { result.IsSameAccs = true; return(result); } AccountEntity accEntityFrom = await GetAccountEntityAsync(accFromName, userFromName); AccountEntity accEntityTo = await GetAccountEntityAsync(accToName, userToName); Account accFrom = new Account(accEntityFrom, AccountCreationOptions.EmptyName); Account accTo = new Account(accEntityTo, AccountCreationOptions.EmptyName); decimal coefficient = await _globalRates.GetRateAsync(accFrom.Money.Curr, accTo.Money.Curr); accFrom.Money.AdjustExchangeRate(accFrom.Money.Curr, accTo.Money.Curr, coefficient); accTo.Money.AdjustExchangeRate(accFrom.Money.Curr, accTo.Money.Curr, coefficient); AccountManager accManager = await GetAccountManagerAsync(accEntityFrom, userFromName); AccountEntity commissionAccEntity = await GetCommissionAccount(); CommissionAccount commissionAcc = new CommissionAccount(commissionAccEntity, AccountCreationOptions.CurrencyOnly); commissionAcc.SubscribeToCommission(accManager); try { accManager.Transaction(accFrom, accTo, amount); } catch (Exception ex) { if (ex.Message == ExceptionMessages.TransactionInsufficientFunds()) { result.IsEnough = false; return(result); } else { throw new Exception(ex.Message); } } commissionAcc.UnsubscribeFromCommission(accManager); result.IsEnough = true; result.SendAmount = accEntityFrom.Amount - accFrom.Money.Amount; result.Commission = result.SendAmount - amount; result.Receive = accTo.Money.Amount - accEntityTo.Amount; result.CommissionOwner = commissionAccEntity.User.UserName; result.CommissionAccName = commissionAccEntity.AccountName; result.CurrFrom = accEntityFrom.Currency; result.CurrTo = accEntityTo.Currency; accEntityFrom.Amount = accFrom.Money.Amount; accEntityTo.Amount = accTo.Money.Amount; commissionAccEntity.Amount += commissionAcc.Money.Amount; DBContext.Accounts.Update(accEntityFrom); DBContext.Accounts.Update(accEntityTo); DBContext.Accounts.Update(commissionAccEntity); await DBContext.SaveChangesAsync(); return(result); }
public void Subscribe(AccountManager accManager) { commissionAcc.SubscribeToCommission(accManager); }