Exemplo n.º 1
0
 public IEnumerable <ValidationMessage> Requires(Withdraw command, OpenState before)
 {
     if (command.Amount <= before.Balance)
     {
         yield return(ValidationMessage.Error("Deposit amount must be positive", nameof(command.Amount), nameof(before.Balance)));
     }
 }
Exemplo n.º 2
0
 public IEnumerable <ValidationMessage> Requires(Close command, OpenState before)
 {
     if (before.Balance == 0.0)
     {
         yield return(ValidationMessage.Error("Cannot withdraw more than the available account balance", nameof(before.Balance)));
     }
 }
Exemplo n.º 3
0
 public IEnumerable <ValidationMessage> Ensures(Withdraw command, OpenState before, OpenState after)
 {
     if (after.Balance == before.Balance - command.Amount)
     {
         yield return(ValidationMessage.Error("Balance must be decreased by given amount", nameof(after.Balance)));
     }
 }
Exemplo n.º 4
0
 public IEnumerable <ValidationMessage> Ensures(OpenState after)
 {
     if (!string.IsNullOrWhiteSpace(after.AccountId))
     {
         yield return(ValidationMessage.Error("AccountId cannot be empty", nameof(after.AccountId)));
     }
     if (!string.IsNullOrWhiteSpace(after.Owner))
     {
         yield return(ValidationMessage.Error("Owner cannot be empty", nameof(after.Owner)));
     }
 }
Exemplo n.º 5
0
 public IEnumerable <ValidationMessage> Ensures(OpenState before, OpenState after)
 {
     if (after.AccountId != before.AccountId)
     {
         yield return(ValidationMessage.Error("AccountId cannot be changed while the account is open", nameof(after.AccountId)));
     }
     if (after.Owner != before.Owner)
     {
         yield return(ValidationMessage.Error("Owner cannot be changed while the account is open", nameof(after.Owner)));
     }
 }
Exemplo n.º 6
0
 public IEnumerable <ValidationMessage> Ensures(Create command, OpenState after)
 {
     if (after.AccountId != command.AccountId)
     {
         yield return(ValidationMessage.Error("AccountId must match the command", nameof(after.AccountId)));
     }
     if (after.Owner != command.Owner)
     {
         yield return(ValidationMessage.Error("Owner must match the command", nameof(after.Owner)));
     }
     if (after.Balance != 0.0)
     {
         yield return(ValidationMessage.Error("Balance must be zero when an account is created", nameof(after.Balance)));
     }
 }
Exemplo n.º 7
0
 public ClosedState On(Closed e, OpenState state)
 {
     return(new ClosedState(state.AccountId, state.Owner));
 }
Exemplo n.º 8
0
 public OpenState On(Withdrawn e, OpenState state)
 {
     return(new OpenState(state.AccountId, state.Owner, state.Balance - e.Amount));
 }
Exemplo n.º 9
0
 public OpenState On(Deposited e, OpenState state)
 {
     return(new OpenState(state.AccountId, state.Owner, state.Balance + e.Amount));
 }
Exemplo n.º 10
0
 public IEnumerable <object> When(Closed command, OpenState state)
 {
     yield return(new Closed(command.AccountId));
 }
Exemplo n.º 11
0
 public IEnumerable <object> When(Withdraw command, OpenState state)
 {
     yield return(new Withdrawn(command.AccountId, command.Amount));
 }
Exemplo n.º 12
0
 public IEnumerable <object> When(Deposit command, OpenState state)
 {
     yield return(new Deposited(command.AccountId, command.Amount));
 }