public CommandResponse SetDailyWireTransferLimit(Guid accountId, decimal dailyWireTransferLimit) { var account = _repo.GetById <AccountAggregate>(accountId); var setDailyWireTransferLimitCommand = new SetDailyWireTransferLimitCommand() { AccountId = account.Id, DailyWireTransferLimit = dailyWireTransferLimit }; return(_cmdHandler.Handle(setDailyWireTransferLimitCommand)); }
public void CannotSetLimitOnInvalidAccount() { var cmd = new SetDailyWireTransferLimitCommand { AccountId = AccountId, DailyWireTransferLimit = 100m }; dynamic msg = CmdHandler.Handle(cmd); Assert.IsType <Fail>(msg); Assert.Equal("No account with this ID exists", msg.Exception.Message); }
public void CanSetDailyWireTransferLimit(decimal limit) { CmdHandler.Handle(new CreateAccountCommand { AccountId = AccountId, HolderName = "John Doe" }); var cmd = new SetDailyWireTransferLimitCommand { AccountId = AccountId, DailyWireTransferLimit = limit }; Assert.IsType <Success>(CmdHandler.Handle(cmd)); }
public async Task set_wire_transfer_limit_command_should_thorw_excption_if_set_negativeAsync() { #region Arrange var accountId = Guid.Parse("1805FB93-2A90-4C9C-B286-EE9A62A94212"); Account account = GetAccount(); var repo = new Mock <Myrepo.IRepository>(); repo.Setup(x => x.GetById <Account>(It.IsAny <Guid>())).Returns(Task.FromResult(account)); CommandHandler commandHandler = new CommandHandler(repo.Object); SetDailyWireTransferLimitCommand setDailyWireTransferLimit = new SetDailyWireTransferLimitCommand(accountId, -100); #endregion #region Act and Assert cause call async await Assert.ThrowsAsync <InvalidOperationException>(() => commandHandler.Handle(setDailyWireTransferLimit)); #endregion }
public void CannotSetNegativeLimit(decimal limit) { CmdHandler.Handle(new CreateAccountCommand { AccountId = AccountId, HolderName = "John Doe" }); var cmd = new SetDailyWireTransferLimitCommand { AccountId = AccountId, DailyWireTransferLimit = limit }; dynamic msg = CmdHandler.Handle(cmd); Assert.IsType <Fail>(msg); Assert.Equal("dailyWireTransfer limit cannot be negative", msg.Exception.Message); }
public CommandResponse Handle(SetDailyWireTransferLimitCommand command) { try { if (!_repository.TryGetById <AccountAggregate>(command.AccountId, out var account)) { throw new ValidationException("No account with this ID exists"); } account.SetDailyWireTransferLimit(command.DailyWireTransferLimit, command); _repository.Save(account); return(command.Succeed()); } catch (Exception e) { return(command.Fail(e)); } }
public async Task wire_transfer_limit_command_should_update_debt_amount() { #region Arrange var accountId = Guid.Parse("1805FB93-2A90-4C9C-B286-EE9A62A94212"); Account account = GetAccount(); var repo = new Mock <Myrepo.IRepository>(); repo.Setup(x => x.GetById <Account>(It.IsAny <Guid>())).Returns(Task.FromResult(account)); CommandHandler commandHandler = new CommandHandler(repo.Object); SetDailyWireTransferLimitCommand setDailyWireTransferLimit = new SetDailyWireTransferLimitCommand(accountId, 1500); WireTransferCommand wireTransfer = new WireTransferCommand(accountId, 100); #endregion await commandHandler.Handle(new DepositeCashCommand(accountId, 200)); await commandHandler.Handle(setDailyWireTransferLimit); await commandHandler.Handle(wireTransfer); Assert.Equal(100, account.Debt); }
public void Run() { var cmd = new[] { "" }; AccountAggregate acct; do { cmd = Console.ReadLine().Split(' '); switch (cmd[0].ToLower()) { case "conn": _accountId = Guid.Parse(cmd[1]); acct = repo.GetById <AccountAggregate>(_accountId); _holderName = acct.HolderName; _readModel.redraw(acct); break; case "list": foreach (var account in _readModel.Accounts) { Console.WriteLine(account.Id + "\t" + account.HolderName); } break; case "new": _accountId = Guid.NewGuid(); if (cmd.Length > 1) { _holderName = cmd[1]; } var createCommand = new CreateAccountCommand() { AccountId = _accountId, HolderName = _holderName }; cmdHandler.Handle(createCommand); break; case "deposit": acct = repo.GetById <AccountAggregate>(_accountId); try { if (cmd[1].ToLower() == "cash") { var depositCashCommand = new DepositCashCommand() { AccountId = acct.Id, Amount = decimal.Parse(cmd[2]) }; cmdHandler.Handle(depositCashCommand); } else if (cmd[1].ToLower() == "check") { var depositCheckCommand = new DepositCheckCommand() { AccountId = acct.Id, Amount = decimal.Parse(cmd[2]) }; cmdHandler.Handle(depositCheckCommand); } Console.WriteLine($"Deposit {cmd[2]}"); } catch (Exception e) { Console.WriteLine("Command should be:\n\tdeposit {type} {amount}\n\ttype : 'cash' or 'check'\n\tamount : number"); } break; case "withdraw": try { acct = repo.GetById <AccountAggregate>(_accountId); var withdrawCommand = new WithdrawCashCommand { AccountId = acct.Id, Amount = decimal.Parse(cmd[1]) }; cmdHandler.Handle(withdrawCommand); Console.WriteLine($"Withdraw {cmd[1]}"); } catch (Exception e) { Console.WriteLine(e); } break; case "overdraft": acct = repo.GetById <AccountAggregate>(_accountId); try { var setOverDraftLimit = new SetOverDraftLimitCommand() { AccountId = acct.Id, OverDraftLimit = decimal.Parse(cmd[1]) }; cmdHandler.Handle(setOverDraftLimit); Console.WriteLine($"setting overdraftLimit to {cmd[1]}"); } catch (Exception e) { Console.WriteLine(e.Message); } break; case "daily": acct = repo.GetById <AccountAggregate>(_accountId); try { var setDailyWireTransferLimit = new SetDailyWireTransferLimitCommand() { AccountId = acct.Id, DailyWireTransferLimit = decimal.Parse(cmd[1]) }; cmdHandler.Handle(setDailyWireTransferLimit); Console.WriteLine($"setting dailyWireTransferLimit to {cmd[1]}"); } catch (Exception e) { Console.WriteLine(e.Message); } break; } } while (cmd[0].ToLower() != "exit"); }
public async Task Handle(SetDailyWireTransferLimitCommand cmd) { await Execute(cmd.AccountId, (account) => account.SetDailyWireTransferLimit(cmd.Amount)); }