public string Withdraw(AccountWithdrawDto withdrawdto) { using (var db = base.NewDB()) { if (withdrawdto.Amount < ConfigHelper.GetConfigInt("MinWithDrawAmount")) { return("未达到提现标准"); } var dbitem = db.UserAccounts.FirstOrDefault(t => t.User.AuthID == withdrawdto.AuthID); if (dbitem == null) { return("账户异常"); } if (withdrawdto.Amount > dbitem.Balance || withdrawdto.Amount < 0) { return("金额异常"); } if (!withdrawdto.BankCard.IsEmpty() && !withdrawdto.BankName.IsEmpty() && !withdrawdto.BranchBankName.IsEmpty()) { dbitem.BankCard = withdrawdto.BankCard; dbitem.BankName = withdrawdto.BankName; dbitem.BranchBankName = withdrawdto.BranchBankName; dbitem.MobilePhone = withdrawdto.MobilePhone; } else { return("请填写完整信息"); } AccountWithdraw aw = new AccountWithdraw { Amount = withdrawdto.Amount, UserAccount = dbitem, Name = withdrawdto.Name, BankCard = withdrawdto.BankCard, BankName = withdrawdto.BankName, BranchBankName = withdrawdto.BranchBankName, MobilePhone = withdrawdto.MobilePhone }; db.AccountWithdraws.Add(aw); dbitem.Balance = dbitem.Balance - withdrawdto.Amount; dbitem.LockBalance = dbitem.LockBalance + withdrawdto.Amount; db.SaveChanges(); return(string.Empty); } }
public void CalculeBalance_Should_Throw_BusinessException() { #region Arrenge ICalculator withdraw = new AccountWithdraw(_account); #endregion #region Assert Assert.Throws <BusinessException>(() => withdraw.CalculeBalance(0)); #endregion }
public void CalculeBalance_Should_Throw_BusinessException_When_Balance_Negative() { #region Arrenge _account.Balance = 200; ICalculator withdraw = new AccountWithdraw(_account); #endregion #region Assert Assert.Throws <BusinessException>(() => withdraw.CalculeBalance(300)); #endregion }
internal void InvokeAccountWithdraw(BankAccount bankAccount, ref decimal newBalance, ref decimal previousBalance) { if (AccountWithdraw != null || scriptOnAccountWithdraw != null) { var args = new BalanceChangedEventArgs(bankAccount, ref newBalance, ref previousBalance); AccountWithdraw?.Invoke(this, args); try { scriptOnAccountWithdraw?.Invoke(this, args); } catch (Exception ex) { BankingPlugin.Instance.LogPrint(ex.ToString(), TraceLevel.Error); } } }
public void CalculeBalance_Should_Works() { #region Arrenge _account.Balance = 100M; ICalculator withdraw = new AccountWithdraw(_account); #endregion #region Act var act = withdraw.CalculeBalance(50); #endregion #region Assert act.Should().Be(50); #endregion }