public async Task CannotWithdrawCashIfNotEnoughFunds() { var deposit = 500m; var withdraw = 1000m; var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var cmd = new WithdrawCash() { AccountId = _accountId, Amount = withdraw }; await _runner.Run( def => def .Given(accCreatedEv, depositSetEv) .When(cmd) .Throws(new SystemException("The account does not have enough funds for requested wire transfer."))); }
public async Task CanWithdrawCash() { Clock.SetCurrent(new LocalDateTime(2018, 1, 1, 9, 0)); var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = AccountId, AccountHolderName = "NNN" }; var cashDeposited = new CashDeposited(accountCreated) { AccountId = AccountId, Amount = 350, DepositedAt = Clock.Current }; var cmd = new WithdrawCash() { AccountId = AccountId, Amount = 200 }; var ev = new CashWithdrawn(cmd) { AccountId = AccountId, Amount = 200, WithdrawnAt = Clock.Current }; await Runner.Run( def => def.Given(accountCreated, cashDeposited).When(cmd).Then(ev) ); }
public async Task CanWithdrawCash(decimal deposit, decimal withdraw) { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var depositedEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var cmd = new WithdrawCash() { AccountId = _accountId, Amount = withdraw }; var withdrawnEv = new CashWithdrawn(cmd) { AccountId = _accountId, Amount = cmd.Amount }; await _runner.Run( def => def .Given(accCreatedEv, depositedEv) .When(cmd) .Then(withdrawnEv)); }
public async Task CashWithdrawalGreaterThanAllowedLimit() { decimal withdrawAmount = 10000; decimal depositeAmount = 5000; var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Tushar" }; var evtCashDeposited = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, DepositAmount = depositeAmount }; var cmdWithdrawCash = new WithdrawCash() { AccountId = _accountId, WithdrawAmount = withdrawAmount }; var evAccountBlocked = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = withdrawAmount }; await _runner.Run( def => def.Given(accountCreated, evtCashDeposited).When(cmdWithdrawCash).Then(evAccountBlocked) ); }
public async Task CannotWithdrawCashIntoInvalidAccount() { var cmd = new WithdrawCash { AccountId = _accountId, Amount = Convert.ToDecimal(500) }; await _runner.Run( def => def.Given().When(cmd).Throws(new ValidationException("No account with this ID exists")) ); }
public async Task CanWithdrawCashWithOverdraftLimitFromValidAccount() { decimal depositeAmount = 5000; decimal overdraftLimit = 2000; decimal withdrawAmount = 7000; var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Tushar" }; var cmdDepositCash = new DepositCash { AccountId = _accountId, DepositAmount = depositeAmount }; var evtCashDeposited = new CashDeposited(cmdDepositCash) { AccountId = _accountId, DepositAmount = depositeAmount }; var cmdConfigureOverdraftLimit = new ConfigureOverdraftLimit { AccountId = _accountId, OverdraftLimit = overdraftLimit }; var evOverdraftLimitConfigured = new OverdraftLimitConfigured(cmdConfigureOverdraftLimit) { AccountId = cmdConfigureOverdraftLimit.AccountId, OverdraftLimit = cmdConfigureOverdraftLimit.OverdraftLimit }; var cmd = new WithdrawCash() { AccountId = _accountId, WithdrawAmount = withdrawAmount }; var ev = new CashWithdrawn(cmd) { AccountId = _accountId, WithdrawAmount = withdrawAmount }; await _runner.Run( def => def.Given(accountCreated, evtCashDeposited, evOverdraftLimitConfigured).When(cmd).Then(ev) ); }
public async Task CashWithdrawShouldThrowExceptionWhenAccountIsNotPresent() { decimal withdrawAmount = 5000; var cmd = new WithdrawCash() { AccountId = _accountId, WithdrawAmount = withdrawAmount }; await _runner.Run( def => def.Given().When(cmd).Throws(new ValidationException("No account with this ID exists")) ); }
public async Task CannotWithdrawCashIfAccountDoesNotExist() { var cmd = new WithdrawCash() { AccountId = _accountId, Amount = 1000 }; await _runner.Run( def => def .Given() .When(cmd) .Throws(new SystemException("Cash cannot be withdrawn from the inexistent accont."))); }
public async Task CannotWithdrawCashOutsideBalanceAndWithOverdraftLimit() { decimal depositeAmount = 5000; decimal overdraftLimit = 1000; decimal withdrawAmount = 7000; var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Tushar" }; var cmdDepositCash = new DepositCash { AccountId = _accountId, DepositAmount = depositeAmount }; var evtCashDeposited = new CashDeposited(cmdDepositCash) { AccountId = _accountId, DepositAmount = depositeAmount }; var evOverdraftLimitConfigured = new OverdraftLimitConfigured(CorrelatedMessage.NewRoot()) { AccountId = _accountId, OverdraftLimit = overdraftLimit }; var cmd = new WithdrawCash() { AccountId = _accountId, WithdrawAmount = withdrawAmount }; var evAccountBlocked = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = withdrawAmount }; await _runner.Run( def => def.Given(accountCreated, evtCashDeposited, evOverdraftLimitConfigured).When(cmd).Then(evAccountBlocked) ); }
public async Task CannotWithdrawCashWithNonPositiveAmount(double amount) { var created = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Parth Sheth" }; var cmd = new WithdrawCash { AccountId = _accountId, Amount = Convert.ToDecimal(amount) }; await _runner.Run( def => def.Given(created).When(cmd).Throws(new ValidationException("Cash withdrawn must be a positive amount")) ); }
public CommandResponse Handle(WithdrawCash command) { try { if (!_repository.TryGetById <Account>(command.AccountId, out var account)) { throw new InvalidOperationException("Account not exisit"); } account.WithdrawCash(command.AccountId, command.Amount, _clock, command); _repository.Save(account); return(command.Succeed()); } catch (Exception e) { return(command.Fail(e)); } }
public async Task CannnotWithdrawCashIfOverdrafdIsExceeded(decimal deposit, decimal overdraft, decimal withdraw) { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var overdraftSetEv = new OverdraftLimitSet(CorrelatedMessage.NewRoot()) { AccountId = _accountId, OverdraftLimit = overdraft }; var cmd = new WithdrawCash() { AccountId = _accountId, Amount = withdraw }; var withdrawalFailedEv = new WithdrawalFailed(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = cmd.Amount }; var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; await _runner.Run( def => def .Given(accCreatedEv, depositSetEv, overdraftSetEv) .When(cmd) .Then(withdrawalFailedEv, accBlockedEv)); }
public async Task CashWithdrawAmountCannotBeNegative() { decimal withdrawAmount = -5000; var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Tushar" }; var cmd = new WithdrawCash() { AccountId = _accountId, WithdrawAmount = withdrawAmount }; await _runner.Run( def => def.Given(accountCreated).When(cmd).Throws(new ValidationException("Cash withdrawal amount cannot be negative")) ); }
public async Task CannotWithrawNonPoitiveCashTests(decimal amount) { var accCreateEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var cmd = new WithdrawCash() { AccountId = _accountId, Amount = amount }; await _runner.Run( def => def .Given(accCreateEv) .When(cmd) .Throws(new SystemException("Withdrawn Cash amount should be greater than 0."))); }
public async Task CannnotWithdrawCashFromBlockedAccount() { var deposit = 1000m; var withdraw = 500m; var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; var cmd = new WithdrawCash() { AccountId = _accountId, Amount = withdraw }; var transferFailedEv = new WithdrawalFailed(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = cmd.Amount }; await _runner.Run( def => def .Given(accCreatedEv, depositSetEv, accBlockedEv) .When(cmd) .Then(transferFailedEv)); }
public async Task CanWithdrawCash(double amount) { var created = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, AccountHolderName = "Parth Sheth" }; var cmd = new WithdrawCash { AccountId = _accountId, Amount = Convert.ToDecimal(amount) }; var limitSet = new CashWithdrawn(cmd) { AccountId = _accountId, Amount = cmd.Amount }; await _runner.Run( def => def.Given(created).When(cmd).Then(limitSet) ); }
public void ProcessRequest(HttpContext context) { int score = Convert.ToInt32(context.Request["score"]); string moduleName = "积分"; if (!string.IsNullOrWhiteSpace(context.Request["module_name"])) { moduleName = context.Request["module_name"]; } string websiteOwner = bllKeyValueData.WebsiteOwner; if (score <= 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = moduleName + "不能为0"; bllKeyValueData.ContextResponse(context, apiResp); return; } string rechargeValue = bllKeyValueData.GetDataVaule("Recharge", "100", websiteOwner); string minScore = bllKeyValueData.GetDataVaule("MinScore", "1", websiteOwner); string minWithdrawCashScore = bllKeyValueData.GetDataVaule("MinWithdrawCashScore", "1", websiteOwner); if (score < Convert.ToDecimal(minWithdrawCashScore)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提现数额不能少于" + minWithdrawCashScore + moduleName; bllKeyValueData.ContextResponse(context, apiResp); return; } double curTotalScore = CurrentUserInfo.TotalScore; double sTotalScore = curTotalScore - score; double nScore = Convert.ToDouble(minScore) + score; if (sTotalScore < Convert.ToDouble(minScore)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = moduleName + "不足"; bllKeyValueData.ContextResponse(context, apiResp); return; } decimal rechargeFee = Convert.ToDecimal(rechargeValue); decimal money = rechargeFee / 100 * score; WithdrawCash model = new WithdrawCash(); model.Amount = money; model.UserId = CurrentUserInfo.UserID; model.TrueName = CurrentUserInfo.TrueName; model.WebSiteOwner = websiteOwner; model.WithdrawCashType = "ScoreOnLine"; model.TransfersType = 1; model.Status = 0; model.Score = score; model.RealAmount = money; model.ServerFee = 0; model.Phone = CurrentUserInfo.Phone; model.LastUpdateDate = DateTime.Now; model.InsertDate = DateTime.Now; model.IsPublic = 2; //积分明细 UserScoreDetailsInfo scoreModel = new UserScoreDetailsInfo(); scoreModel.AddNote = string.Format("申请提现消耗{0}{1}", score, moduleName); scoreModel.AddTime = DateTime.Now; scoreModel.Score = 0 - score; scoreModel.UserID = CurrentUserInfo.UserID; scoreModel.ScoreType = "WithdrawCash"; scoreModel.TotalScore = sTotalScore; scoreModel.WebSiteOwner = websiteOwner; //通知 BLLJIMP.Model.SystemNotice notice = new BLLJIMP.Model.SystemNotice(); notice.Ncontent = scoreModel.AddNote; notice.UserId = CurrentUserInfo.UserID; notice.Receivers = CurrentUserInfo.UserID; notice.SendType = 2; notice.SerialNum = bllKeyValueData.GetGUID(TransacType.SendSystemNotice); notice.Title = "申请提现消耗淘股币"; notice.NoticeType = 1; notice.WebsiteOwner = websiteOwner; notice.InsertTime = DateTime.Now; BLLTransaction tran = new BLLTransaction(); if (bllUser.Update(CurrentUserInfo, string.Format("TotalScore=TotalScore-{0}", score), string.Format("AutoID={0} AND WebsiteOwner='{1}' AND TotalScore>{2}", CurrentUserInfo.AutoID, websiteOwner, nScore), tran) > 0 && bllUser.Add(scoreModel, tran) && bllUser.Add(notice, tran) && bllUser.Add(model, tran)) { tran.Commit(); apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "申请成功"; apiResp.status = true; } else { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "申请失败"; } bllKeyValueData.ContextResponse(context, apiResp); }
/// <summary> /// 审核通过打款 /// </summary> /// <param name="autoId">记录Id</param> /// <param name="userId">操作人账号</param> /// <param name="msg">提示信息</param> /// <returns></returns> public bool Pass(int autoId, string userId, out string msg) { msg = ""; var record = Get(autoId); if (record.Status == 1) { msg = "该记录已打款"; return(false); } switch (record.Type) { #region 分销提现 case "DistributionWithdraw": //分销提现 BLLDistribution bllDis = new BLLDistribution(); List <WithdrawCash> list = new List <WithdrawCash>(); WithdrawCash model = Get <WithdrawCash>(string.Format("TranId='{0}'", record.TranId)); if (model == null) { msg = "该记录已标记为失败"; return(false); } list.Add(model); if (!bllDis.UpdateWithrawCashStatus(list, 2, out msg)) { return(false); } break; #endregion #region 商城退款 case "MallRefund": //退款 BLLMall bllMall = new BLLMall(); WXMallRefund refund = bllMall.Get <WXMallRefund>(string.Format("RefundId='{0}'", record.TranId)); switch (refund.Status) { case 2: msg = "未同意退款"; return(false); case 5: msg = "未收到货拒绝退款"; return(false); case 7: msg = "退款申请关闭"; return(false); default: break; } if (!bllMall.Refund(refund.OrderDetailId, out msg)) { return(false); } break; #endregion default: msg = "未定义的类型"; return(false); } record.UpdateTime = DateTime.Now; record.Status = 1; record.OperaUserId = userId; if (Update(record)) { return(true); } return(false); }