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))); } }
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))); } }
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))); } }
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))); } }
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))); } }
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))); } }
public ClosedState On(Closed e, OpenState state) { return(new ClosedState(state.AccountId, state.Owner)); }
public OpenState On(Withdrawn e, OpenState state) { return(new OpenState(state.AccountId, state.Owner, state.Balance - e.Amount)); }
public OpenState On(Deposited e, OpenState state) { return(new OpenState(state.AccountId, state.Owner, state.Balance + e.Amount)); }
public IEnumerable <object> When(Closed command, OpenState state) { yield return(new Closed(command.AccountId)); }
public IEnumerable <object> When(Withdraw command, OpenState state) { yield return(new Withdrawn(command.AccountId, command.Amount)); }
public IEnumerable <object> When(Deposit command, OpenState state) { yield return(new Deposited(command.AccountId, command.Amount)); }