public void Can_create_SetOverdraftLimit_Command() { var id = Guid.NewGuid(); var limit = 250; var @command = new SetOverdraftLimit(id, limit); Assert.NotNull(@command); Assert.Equal(id, @command.AccountId); Assert.Equal(limit, @command.Limit); }
public CommandResponse Handle(SetOverdraftLimit command) { if (!_repository.TryGetById <AccountAggregate.BankAccount>(command.AccountId, out var account)) { throw new InvalidOperationException("No account with such ID"); } account.SetOverdraftLimit(command.Limit, new SettedOverdraftLimit(command.AccountId, command.Limit)); _repository.Save(account); return(command.Succeed()); }
public async Task CannotSetOverdraftLimitIfAccountDoesNotExist() { var cmd = new SetOverdraftLimit { AccountId = _accountId, OverdraftLimit = 1000 }; await _runner.Run( def => def .Given() .When(cmd) .Throws(new SystemException("The overdraft limit cannot be set on inexistent account.")) ); }
public async Task CannotSetOverdraftLimit(decimal limit) { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var cmd = new SetOverdraftLimit { AccountId = _accountId, OverdraftLimit = limit }; await _runner.Run( def => def .Given(accCreatedEv) .When(cmd) .Throws(new SystemException("The overdraft limit cannot be negative.")) ); }
public async Task CanSetOverdraftLimit(decimal limit) { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var cmd = new SetOverdraftLimit { AccountId = _accountId, OverdraftLimit = limit }; var limitSetEv = new OverdraftLimitSet(CorrelatedMessage.NewRoot()) { AccountId = cmd.AccountId, OverdraftLimit = cmd.OverdraftLimit }; await _runner.Run( def => def.Given(accCreatedEv).When(cmd).Then(limitSetEv) ); }