private void MustContainAccountNumber(AccountNumber accountNumber) { if (IsActive(accountNumber) || IsInactive(accountNumber)) { return; } throw new AccountNotFoundException(accountNumber); }
public Debit(AccountNumber accountNumber, Money amount) { if (amount < Money.Zero) { throw new ArgumentOutOfRangeException(nameof(amount)); } Amount = amount; AccountNumber = accountNumber; }
public Credit(AccountNumber accountNumber, Money amount) { if (amount < Money.Zero) { throw new ArgumentOutOfRangeException(nameof(amount)); } Amount = amount; AccountNumber = accountNumber; _accountType = AccountType.OfAccountNumber(accountNumber); }
public void ReactivateAccount(AccountNumber accountNumber) { MustContainAccountNumber(accountNumber); if (IsActive(accountNumber)) { return; } Apply(new AccountReactivated { AccountNumber = accountNumber.ToInt32() }); }
private ChartOfAccounts() { _accountNumbers = new HashSet <AccountNumber>(); _deactivatedAccountNumbers = new HashSet <AccountNumber>(); Register <AccountDefined>(e => _accountNumbers.Add(new AccountNumber(e.AccountNumber))); Register <AccountDeactivated>(e => { var accountNumber = new AccountNumber(e.AccountNumber); _accountNumbers.Remove(accountNumber); _deactivatedAccountNumbers.Add(accountNumber); }); Register <AccountReactivated>(e => { var accountNumber = new AccountNumber(e.AccountNumber); _accountNumbers.Add(accountNumber); _deactivatedAccountNumbers.Remove(accountNumber); }); }
public void BeginClosingPeriod(AccountNumber retainedEarningsAccountNumber, GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier, GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers, DateTimeOffset closingOn) { if (_periodClosing) { throw new PeriodClosingInProcessException(_period); } _period.MustNotBeAfter(closingOn); Apply(new AccountingPeriodClosing { Period = _period.ToString(), GeneralLedgerEntryIds = Array.ConvertAll(generalLedgerEntryIdentifiers, id => id.ToGuid()), ClosingOn = closingOn, RetainedEarningsAccountNumber = retainedEarningsAccountNumber.ToInt32(), ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid() }); }
public Debit(AccountNumber accountNumber) : this(accountNumber, Money.Zero) { }
public void Equality(AccountNumber accountNumber) { Assert.Equal(AccountType.OfAccountNumber(accountNumber), AccountType.OfAccountNumber(accountNumber)); }
public void InequalityOperator(AccountNumber sut, AccountNumber other) { Assert.False(sut == other); }
public void Equality(AccountNumber sut) { var copy = new AccountNumber(sut.ToInt32()); Assert.Equal(sut, copy); }
public bool Equals(Credit other) => Amount.Equals(other.Amount) && AccountNumber.Equals(other.AccountNumber);
public void EqualityOperator(AccountNumber sut) { var copy = new AccountNumber(sut.ToInt32()); Assert.True(sut == copy); }
public Account this[AccountNumber accountNumber] => _state.Accounts.TryGetValue(accountNumber, out var account) ? Account.For(accountNumber, account.AccountName) : throw new AccountNotFoundException(accountNumber);
private bool IsInactive(AccountNumber accountNumber) => _deactivatedAccountNumbers.Contains(accountNumber);
public AccountDeactivatedException(AccountNumber accountNumber) : base( $"Account {accountNumber} was deactivated.") { AccountNumber = accountNumber; }
public void AddOrUpdate(AccountNumber accountNumber, Func <Account> add, Func <Account, Account> update) => _items = _items.SetItem(accountNumber, _items.TryGetValue(accountNumber, out var account) ? update(account) : update(add()));
public void MoneyLessThanZeroThrows(AccountNumber accountNumber, decimal value) { var amount = new Money(-Math.Abs(value)); Assert.Throws <ArgumentOutOfRangeException>(() => new Debit(accountNumber, amount)); }
public void InequalityOperator(AccountNumber accountNumber) { Assert.False(AccountType.OfAccountNumber(accountNumber) != AccountType.OfAccountNumber(accountNumber)); }
public void EqualityOperator(AccountNumber accountNumber) { Assert.True(AccountType.OfAccountNumber(accountNumber) == AccountType.OfAccountNumber(accountNumber)); }
public static AccountType OfAccountNumber(AccountNumber value) => value switch {
private bool IsActive(AccountNumber accountNumber) => _accountNumbers.Contains(accountNumber);
public void ZeroMoney(AccountNumber accountNumber) { var sut = new Debit(accountNumber); Assert.Equal(new Debit(accountNumber, Money.Zero), sut); }
public AccountNotFoundException(AccountNumber accountNumber) : base($"Account {accountNumber} was not found.") { AccountNumber = accountNumber; }
private static bool IgnoreInactiveAccount(AccountNumber _) => false;
public AccountExistsException(AccountNumber accountNumber) : base($"Account {accountNumber} already exists.") { AccountNumber = accountNumber; }