public async Task add_negative_amount_debt_to_account_should_update_account_debt_amount(decimal 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); DepositeCashCommand depositeCash = new DepositeCashCommand(accountId, amount); #endregion #region Act and Assert cause call async await Assert.ThrowsAnyAsync <InvalidOperationException>(() => commandHandler.Handle(depositeCash)); #endregion }
public async void TestMyDomain() { try { var accountName = "Mohamed Zghal Linedata 123569"; var accountId = Guid.Parse("1805FB93-2A90-4C9C-B286-EE9A62A94212"); CreateAccountCommand createAccount = new CreateAccountCommand(accountId, accountName); IEventStore eventStore = new EventStore(); IRepository repository = new Repository(eventStore); CommandHandler commandHandler = new CommandHandler(repository); DepositeCashCommand depositeCash = new DepositeCashCommand(accountId, 500); await commandHandler.Handle(depositeCash); var account = await repository.GetById <Account>(accountId); System.Console.WriteLine(String.Format("Your Account Name is : {0} with Debt {1}", account.AccountName, account.Debt)); }catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task Handle(DepositeCashCommand cmd) { await Execute(cmd.AccountId, (account) => account.DepositeCash(cmd.Amount)); }