Пример #1
0
        private void MustContainAccountNumber(AccountNumber accountNumber)
        {
            if (IsActive(accountNumber) || IsInactive(accountNumber))
            {
                return;
            }

            throw new AccountNotFoundException(accountNumber);
        }
Пример #2
0
        public Debit(AccountNumber accountNumber, Money amount)
        {
            if (amount < Money.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            Amount        = amount;
            AccountNumber = accountNumber;
        }
Пример #3
0
        public Credit(AccountNumber accountNumber, Money amount)
        {
            if (amount < Money.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            Amount        = amount;
            AccountNumber = accountNumber;
            _accountType  = AccountType.OfAccountNumber(accountNumber);
        }
Пример #4
0
        public void ReactivateAccount(AccountNumber accountNumber)
        {
            MustContainAccountNumber(accountNumber);

            if (IsActive(accountNumber))
            {
                return;
            }

            Apply(new AccountReactivated {
                AccountNumber = accountNumber.ToInt32()
            });
        }
Пример #5
0
 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);
     });
 }
Пример #6
0
        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()
            });
        }
Пример #7
0
 public Debit(AccountNumber accountNumber) : this(accountNumber, Money.Zero)
 {
 }
Пример #8
0
 public void Equality(AccountNumber accountNumber)
 {
     Assert.Equal(AccountType.OfAccountNumber(accountNumber), AccountType.OfAccountNumber(accountNumber));
 }
Пример #9
0
 public void InequalityOperator(AccountNumber sut, AccountNumber other)
 {
     Assert.False(sut == other);
 }
Пример #10
0
        public void Equality(AccountNumber sut)
        {
            var copy = new AccountNumber(sut.ToInt32());

            Assert.Equal(sut, copy);
        }
Пример #11
0
 public bool Equals(Credit other) => Amount.Equals(other.Amount) && AccountNumber.Equals(other.AccountNumber);
Пример #12
0
        public void EqualityOperator(AccountNumber sut)
        {
            var copy = new AccountNumber(sut.ToInt32());

            Assert.True(sut == copy);
        }
Пример #13
0
 public Account this[AccountNumber accountNumber] =>
 _state.Accounts.TryGetValue(accountNumber, out var account)
                         ? Account.For(accountNumber, account.AccountName)
                         : throw new AccountNotFoundException(accountNumber);
Пример #14
0
 private bool IsInactive(AccountNumber accountNumber) => _deactivatedAccountNumbers.Contains(accountNumber);
 public AccountDeactivatedException(AccountNumber accountNumber) : base(
         $"Account {accountNumber} was deactivated.")
 {
     AccountNumber = accountNumber;
 }
Пример #16
0
 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()));
Пример #17
0
        public void MoneyLessThanZeroThrows(AccountNumber accountNumber, decimal value)
        {
            var amount = new Money(-Math.Abs(value));

            Assert.Throws <ArgumentOutOfRangeException>(() => new Debit(accountNumber, amount));
        }
Пример #18
0
 public void InequalityOperator(AccountNumber accountNumber)
 {
     Assert.False(AccountType.OfAccountNumber(accountNumber) != AccountType.OfAccountNumber(accountNumber));
 }
Пример #19
0
 public void EqualityOperator(AccountNumber accountNumber)
 {
     Assert.True(AccountType.OfAccountNumber(accountNumber) == AccountType.OfAccountNumber(accountNumber));
 }
Пример #20
0
 public static AccountType OfAccountNumber(AccountNumber value) => value switch
 {
Пример #21
0
 private bool IsActive(AccountNumber accountNumber) => _accountNumbers.Contains(accountNumber);
Пример #22
0
        public void ZeroMoney(AccountNumber accountNumber)
        {
            var sut = new Debit(accountNumber);

            Assert.Equal(new Debit(accountNumber, Money.Zero), sut);
        }
Пример #23
0
 public AccountNotFoundException(AccountNumber accountNumber) : base($"Account {accountNumber} was not found.")
 {
     AccountNumber = accountNumber;
 }
Пример #24
0
 private static bool IgnoreInactiveAccount(AccountNumber _) => false;
Пример #25
0
 public AccountExistsException(AccountNumber accountNumber) : base($"Account {accountNumber} already exists.")
 {
     AccountNumber = accountNumber;
 }