示例#1
0
 public Task reactivating_an_active_account(AccountName accountName, AccountNumber accountNumber) =>
 new Scenario()
 .Given(ChartOfAccounts.Identifier, new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new ReactivateAccount {
     AccountNumber = accountNumber.ToInt32()
 })
 .ThenNone()
 .Assert(_handler, _facts);
示例#2
0
 public Task defining_an_account(AccountName accountName, AccountNumber accountNumber) =>
 new Scenario()
 .GivenNone()
 .When(new DefineAccount {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .Then("chartOfAccounts", new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .Assert(_handler, _facts);
示例#3
0
 public Task defining_the_same_account_throws(AccountName accountName, AccountNumber accountNumber) =>
 new Scenario()
 .Given(ChartOfAccounts.Identifier, new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new DefineAccount {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .Throws(new AccountExistsException(accountNumber))
 .Assert(_handler, _facts);
示例#4
0
 public Task defining_the_same_account_throws(AccountName accountName, AccountNumber accountNumber) =>
 new Scenario()
 .Given("chartOfAccounts", new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new DefineAccount {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .Throws(new InvalidOperationException())
 .Assert(_handler, _facts);
示例#5
0
 public Task reactivating_a_deactivated_account(AccountName accountName, AccountNumber accountNumber) =>
 new Scenario()
 .Given("chartOfAccounts", new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 }, new AccountDeactivated {
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new ReactivateAccount {
     AccountNumber = accountNumber.ToInt32()
 })
 .Then("chartOfAccounts", new AccountReactivated {
     AccountNumber = accountNumber.ToInt32()
 })
 .Assert(_handler, _facts);
        public Task entry_not_in_balance_throws(GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier,
                                                int sequenceNumber, LocalDate openedOn, AccountName accountName, AccountNumber accountNumber)
        {
            var scenario = new Scenario()
                           .Given(GeneralLedger.Identifier,
                                  new GeneralLedgerOpened {
                OpenedOn = Time.Format.LocalDate(openedOn)
            })
                           .Given(ChartOfAccounts.Identifier,
                                  new AccountDefined {
                AccountName   = accountName.ToString(),
                AccountNumber = accountNumber.ToInt32()
            })
                           .When(new PostGeneralLedgerEntry {
                Period = AccountingPeriod.Open(openedOn).ToString(),
                BusinessTransaction = new BadTransaction {
                    Account         = accountNumber,
                    ReferenceNumber = sequenceNumber
                },
                CreatedOn            = openedOn.ToDateTimeUnspecified(),
                GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid()
            })
                           .Throws(new GeneralLedgerEntryNotInBalanceException(generalLedgerEntryIdentifier));

            _writer.Write(scenario.Build());
            return(scenario.Assert(new GeneralLedgerEntryHandlers(new GeneralLedgerTestRepository(_facts),
                                                                  new GeneralLedgerEntryTestRepository(_facts),
                                                                  _ => false), _facts));
        }
示例#7
0
        public Task entry_not_in_balance_throws(GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier,
                                                int sequenceNumber, DateTimeOffset openedOn, AccountName accountName, AccountNumber accountNumber)
        {
            var scenario = new Scenario()
                           .Given("generalLedger",
                                  new GeneralLedgerOpened {
                OpenedOn = openedOn
            })
                           .Given("chartOfAccounts",
                                  new AccountDefined {
                AccountName   = accountName.ToString(),
                AccountNumber = accountNumber.ToInt32()
            })
                           .When(new PostGeneralLedgerEntry {
                Period = Period.Open(openedOn).ToString(),
                BusinessTransaction = new BadTransaction {
                    Account         = accountNumber,
                    ReferenceNumber = sequenceNumber
                },
                CreatedOn            = openedOn,
                GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid()
            })

                           .Throws(new GeneralLedgerEntryNotInBalanceException(generalLedgerEntryIdentifier));

            _writer.Write(scenario.Build());
            return(scenario.Assert(_handler, _facts));
        }
示例#8
0
 public Task renaming_an_account(AccountName accountName, AccountNumber accountNumber,
                                 AccountName secondAccountName) =>
 new Scenario()
 .Given(ChartOfAccounts.Identifier, new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new RenameAccount {
     NewAccountName = secondAccountName.ToString(),
     AccountNumber  = accountNumber.ToInt32()
 })
 .Then(ChartOfAccounts.Identifier, new AccountRenamed {
     NewAccountName = secondAccountName.ToString(),
     AccountNumber  = accountNumber.ToInt32()
 })
 .Assert(_handler, _facts);
示例#9
0
 public Task deactivating_an_account_when_no_account_defined_throws(AccountNumber accountNumber) =>
 new Scenario()
 .GivenNone()
 .When(new DeactivateAccount {
     AccountNumber = accountNumber.ToInt32()
 })
 .Throws(new InvalidOperationException())
 .Assert(_handler, _facts);
示例#10
0
 public Task reactivating_an_account_when_no_account_defined_throws(AccountNumber accountNumber) =>
 new Scenario()
 .GivenNone()
 .When(new ReactivateAccount {
     AccountNumber = accountNumber.ToInt32()
 })
 .Throws(new ChartOfAccountsNotFoundException())
 .Assert(_handler, _facts);
示例#11
0
 public Task renaming_an_account_when_no_account_defined_throws(AccountName accountName,
                                                                AccountNumber accountNumber) =>
 new Scenario()
 .GivenNone()
 .When(new RenameAccount {
     NewAccountName = accountName.ToString(),
     AccountNumber  = accountNumber.ToInt32()
 })
 .Throws(new ChartOfAccountsNotFoundException())
 .Assert(_handler, _facts);
 public Task when_the_general_ledger_entry_was_posted(
     GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier,
     Period period,
     AccountNumber credit,
     AccountNumber debit,
     Money amount,
     int iterations) => new NpgsqlProjectionScenario(new BalanceSheetReportProjection())
 .Given(new CreateSchema())
 .Given(new GeneralLedgerEntryCreated {
     GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid(),
     Period = period.ToString()
 })
 .Given(Enumerable.Range(0, iterations).Select(_ => new DebitApplied {
     Amount               = amount.ToDecimal(),
     AccountNumber        = debit.ToInt32(),
     GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid()
 }))
 .Given(Enumerable.Range(0, iterations).Select(_ => new CreditApplied {
     Amount               = amount.ToDecimal(),
     AccountNumber        = credit.ToInt32(),
     GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid()
 }))
 .Given(new GeneralLedgerEntryPosted {
     GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid(),
     Period = period.ToString()
 })
 .Then(_schema, "balance_sheet_general_ledger_entry_period",
       Array.Empty <BalanceSheetReportProjection.GeneralLedgerEntryPeriod>())
 .Then(_schema, "balance_sheet_items_unposted",
       Array.Empty <BalanceSheetReportProjection.UnpostedGeneralLedgerEntryLine>())
 .Then(_schema, "balance_sheet_report", new BalanceSheetReportProjection.Item {
     Balance       = amount.ToDecimal() * iterations,
     PeriodMonth   = period.Month,
     PeriodYear    = period.Year,
     AccountNumber = debit.ToInt32()
 }, new BalanceSheetReportProjection.Item {
     Balance       = -amount.ToDecimal() * iterations,
     PeriodMonth   = period.Month,
     PeriodYear    = period.Year,
     AccountNumber = credit.ToInt32()
 })
 .Assert();
示例#13
0
 public Task deactivating_an_account_when_it_was_not_defined_throws(AccountName accountName,
                                                                    AccountNumber accountNumber, AccountNumber secondAccountNumber) =>
 new Scenario()
 .Given("chartOfAccounts", new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new DeactivateAccount {
     AccountNumber = secondAccountNumber.ToInt32()
 })
 .Throws(new InvalidOperationException())
 .Assert(_handler, _facts);
示例#14
0
 public Task reactivating_an_account_when_it_was_not_defined_throws(AccountName accountName,
                                                                    AccountNumber accountNumber, AccountNumber secondAccountNumber) =>
 new Scenario()
 .Given(ChartOfAccounts.Identifier, new AccountDefined {
     AccountName   = accountName.ToString(),
     AccountNumber = accountNumber.ToInt32()
 })
 .When(new ReactivateAccount {
     AccountNumber = secondAccountNumber.ToInt32()
 })
 .Throws(new AccountNotFoundException(secondAccountNumber))
 .Assert(_handler, _facts);
示例#15
0
 public Task closing_an_open_period(Period period,
                                    GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers,
                                    GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier) =>
 new Scenario()
 .Given("generalLedger", new GeneralLedgerOpened {
     OpenedOn = new DateTimeOffset(new DateTime(period.Year, period.Month, 2))
 })
 .When(new BeginClosingAccountingPeriod {
     GeneralLedgerEntryIds         = Array.ConvertAll(generalLedgerEntryIdentifiers, x => x.ToGuid()),
     ClosingOn                     = new DateTimeOffset(new DateTime(period.Year, period.Month, 2)),
     RetainedEarningsAccountNumber = _retainedEarnings.ToInt32(),
     ClosingGeneralLedgerEntryId   = closingGeneralLedgerEntryIdentifier.ToGuid()
 })
 .Then("generalLedger", new AccountingPeriodClosing {
     Period = period.ToString(),
     GeneralLedgerEntryIds         = Array.ConvertAll(generalLedgerEntryIdentifiers, x => x.ToGuid()),
     ClosingOn                     = new DateTimeOffset(new DateTime(period.Year, period.Month, 2)),
     RetainedEarningsAccountNumber = _retainedEarnings.ToInt32(),
     ClosingGeneralLedgerEntryId   = closingGeneralLedgerEntryIdentifier.ToGuid()
 })
 .Assert(_handler, _facts);
示例#16
0
        OpenBooks(DateTimeOffset now)
        {
            await HttpClient.SendCommand("/general-ledger", new OpenGeneralLedger {
                OpenedOn = now
            }, TransactoSerializerOptions.Commands);

            foreach (var(accountNumber, accountName) in GetChartOfAccounts().OrderBy(_ => Guid.NewGuid()))
            {
                await HttpClient.SendCommand("/chart-of-accounts", new DefineAccount {
                    AccountName   = accountName.ToString(),
                    AccountNumber = accountNumber.ToInt32()
                }, TransactoSerializerOptions.BusinessTransactions());

                yield return(accountNumber, accountName);
            }

            await Task.Delay(TimeSpan.FromMilliseconds(500));
        }
示例#17
0
        public Task period_closing_started(DateTimeOffset openedOn,
                                           GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers,
                                           GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier,
                                           Money amount)
        {
            var period              = Period.Open(openedOn);
            var cashAccountNumber   = new AccountNumber(new Random().Next(1000, 1999));
            var incomeAccountNumber = new AccountNumber(new Random().Next(4000, 4999));

            var closingOn = new DateTimeOffset(new DateTime(period.Year, period.Month, 2));

            var accountingPeriodClosing = new AccountingPeriodClosing {
                Period    = period.ToString(),
                ClosingOn = closingOn,
                RetainedEarningsAccountNumber = _retainedEarnings.ToInt32(),
                ClosingGeneralLedgerEntryId   = closingGeneralLedgerEntryIdentifier.ToGuid(),
                GeneralLedgerEntryIds         =
                    Array.ConvertAll(generalLedgerEntryIdentifiers, identifier => identifier.ToGuid())
            };
            var generalLedgerEntryFacts = generalLedgerEntryIdentifiers.SelectMany(
                (identifier, index) => Array.ConvertAll(new object[] {
                new GeneralLedgerEntryCreated {
                    Number               = $"sale-{index}",
                    Period               = period.ToString(),
                    CreatedOn            = openedOn,
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new DebitApplied {
                    Amount               = amount.ToDecimal(),
                    AccountNumber        = cashAccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new CreditApplied {
                    Amount               = amount.ToDecimal(),
                    AccountNumber        = incomeAccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new GeneralLedgerEntryPosted {
                    Period = period.ToString(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
            }, e => new Fact($"generalLedgerEntry-{identifier}", e)))
                                          .ToArray();

            return(new Scenario()
                   .Given("chartOfAccounts",
                          new AccountDefined {
                AccountName = "Cash on Hand",
                AccountNumber = cashAccountNumber.ToInt32()
            },
                          new AccountDefined {
                AccountName = "Income",
                AccountNumber = incomeAccountNumber.ToInt32()
            },
                          new AccountDefined {
                AccountName = "Retained Earnings",
                AccountNumber = _retainedEarnings.ToInt32()
            })
                   .Given("generalLedger",
                          new GeneralLedgerOpened {
                OpenedOn = openedOn
            },
                          accountingPeriodClosing)
                   .Given(generalLedgerEntryFacts)
                   .When(accountingPeriodClosing)
                   .Then("generalLedger",
                         new GeneralLedgerEntryCreated {
                CreatedOn = closingOn,
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid(),
                Number = $"jec-{period}",
                Period = period.ToString()
            },
                         new DebitApplied {
                Amount = amount.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = incomeAccountNumber.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new CreditApplied {
                Amount = amount.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = _retainedEarnings.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new GeneralLedgerEntryPosted {
                Period = period.ToString(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new AccountingPeriodClosed {
                Period = period.ToString(),
                GeneralLedgerEntryIds = Array.ConvertAll(generalLedgerEntryIdentifiers,
                                                         identifier => identifier.ToGuid()),
                ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid(),
                Balance = new Dictionary <int, decimal> {
                    [cashAccountNumber.ToInt32()] = amount.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                    [incomeAccountNumber.ToInt32()] = Money.Zero.ToDecimal(),
                    [_retainedEarnings.ToInt32()] = -(amount.ToDecimal() * generalLedgerEntryIdentifiers.Length)
                }
            })
                   .Assert(_handler, _facts));
        }