Example #1
0
        private string ExecuteQuery(string query, Func <IRecordSet, string> formatLambda, params QlParameter[] parameters)
        {
            Utils.ClearJournal <Quote>();
            var config = Utils.ReadConfig <Quote>();

            using (var qj = Utils.CreateJournal <Quote>(config, EFileAccess.ReadWrite))
            {
                AppendRecords(qj, 0, 1);
            }

            using (var qj = new JournalBuilder()
                            .WithAccess(EFileAccess.Read)
                            .WithLocation(config.DefaultPath)
                            .ToJournal())
            {
                using (var rdr = qj.OpenRecordReadTx())
                {
                    var qts = rdr.Execute(query, parameters);

                    // Act.
                    var result = formatLambda(qts);

                    // Verify.
                    return(string.Join(",", result));
                }
            }
        }
        private JournalMetadata CreateMetadata <T>(JournalElement conf = null, string[] privateFields = null)
        {
            var settings = conf ?? new JournalElement();
            var meta     = JournalBuilder.CreateNewJournalMetadata(settings, typeof(T));

            return(meta);
        }
Example #3
0
        public void GivenJournal_WhenBuildWithout_ThenUseAsDefaultIsFalse()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .WithContraAccount(internalOrganisationGlAccount)
                          .WithDescription("journal")
                          .Build();

            this.Session.Derive(false);

            Assert.False(journal.UseAsDefault);
        }
Example #4
0
        public void GivenJournal_WhenDeriving_ThenSingletonMustExist()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var glAccount = new GeneralLedgerAccountBuilder(this.Session)
                            .WithAccountNumber("0001")
                            .WithName("GeneralLedgerAccount")
                            .WithBalanceSheetAccount(true)
                            .WithSide(new DebitCreditConstants(this.Session).Debit)
                            .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                            .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                            .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithFromDate(this.Session.Now())
                                                .WithGeneralLedgerAccount(glAccount)
                                                .Build();

            this.Session.Commit();

            var builder = new JournalBuilder(this.Session);

            builder.WithDescription("description");
            builder.WithJournalType(new JournalTypes(this.Session).Bank);
            builder.WithContraAccount(internalOrganisationGlAccount);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #5
0
        private string ExecuteQuery(string query, Func <IRecordSet, string> formatLambda, params QlParameter[] parameters)
        {
            Utils.ClearJournal <Quote>(FOLDER_PATH);
            string location;

            using (var qj = OpenJournal(EFileAccess.ReadWrite))
            {
                location = qj.Metadata.Settings.DefaultPath;
                AppendRecords(qj, 0, 1);
            }

            using (var qj = new JournalBuilder()
                            .WithAccess(EFileAccess.Read)
                            .WithLocation(location)
                            .ToJournal())
            {
                using (var rdr = qj.OpenRecordReadTx())
                {
                    var qts = rdr.Execute(query, parameters);

                    // Act.
                    var result = formatLambda(qts);

                    // Verify.
                    return(string.Join(",", result));
                }
            }
        }
Example #6
0
        public static PartitionData <T> CreatePartition <T>(int?recordHint = null, EFileAccess access = EFileAccess.Read, EFileFlags fileFlags = EFileFlags.None)
        {
            var mmFactory = new CompositeFileFactory(fileFlags);

            using (var dbXml = typeof(Quote).Assembly.GetManifestResourceStream(
                       "Apaf.NFSdb.TestShared.Resources.nfsdb.xml"))
            {
                var dbElement = ConfigurationSerializer.ReadConfiguration(dbXml);
                var jconf     = dbElement.Journals.Single(j => j.Class.EndsWith("." + typeof(T).Name));
                if (recordHint.HasValue)
                {
                    jconf.RecordHint = recordHint.Value;
                }
                var journalPath = Path.Combine(FindJournalsPath(), jconf.DefaultPath);
                jconf.DefaultPath = journalPath;

                var metadata       = JournalBuilder.CreateNewJournalMetadata(jconf);
                var startDate      = new DateTime(2013, 10, 1);
                var journalStorage = new ColumnStorage(metadata, jconf.DefaultPath,
                                                       access, 0, mmFactory);

                var part = new Partition(
                    metadata, new CompositeFileFactory(fileFlags),
                    access, new PartitionDate(startDate, 0, metadata.Settings.PartitionType), 0,
                    Path.Combine(jconf.DefaultPath, "2013-10"), new AsyncJournalServer(TimeSpan.FromSeconds(1)));

                return(new PartitionData <T>(part, metadata, journalStorage, journalPath));
            }
        }
        private static JournalMetadata CreateMetadata <T>(EPartitionType configValue,
                                                          string workingDir, params string[] symbols)
        {
            var jconf = new JournalElement
            {
                DefaultPath   = workingDir,
                PartitionType = configValue
            };

            if (symbols != null)
            {
                foreach (string sym in symbols)
                {
                    var se = new SymbolElement
                    {
                        AvgSize           = 20,
                        HintDistinctCount = 100,
                        MaxSize           = 120,
                        Name = sym
                    };
                    jconf.Columns.Add(se);
                }
            }
            var meta = JournalBuilder.CreateNewJournalMetadata(jconf, typeof(T));

            return(meta);
        }
Example #8
0
        public void GivenJournal_WhenBuildWithout_ThenCloseWhenInBalanceIsFalse()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .WithContraAccount(internalOrganisationGlAccount)
                .WithDescription("journal")
                .Build();

            this.DatabaseSession.Derive();

            Assert.IsFalse(journal.CloseWhenInBalance);
        }
Example #9
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanNotBeChangedWhenJournalEntriesArePresent()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0001")
                                        .WithName("bankAccount 1")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount1)
                                                 .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0002")
                                        .WithName("bankAccount 2")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount2)
                                                 .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("description")
                          .WithContraAccount(internalOrganisationGlAccount1)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .Build();

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.AddJournalEntry(new JournalEntryBuilder(this.Session)
                                    .WithJournalEntryDetail(new JournalEntryDetailBuilder(this.Session)
                                                            .WithAmount(1)
                                                            .WithDebit(true)
                                                            .WithGeneralLedgerAccount(internalOrganisationGlAccount1)
                                                            .Build())
                                    .Build());

            journal.ContraAccount = internalOrganisationGlAccount2;

            Assert.Equal("Journal.ContraAccount, Journal.PreviousContraAccount are not equal", this.Session.Derive(false).Errors[0].Message);
        }
Example #10
0
        public void OpenWrite()
        {
            var j = new JournalBuilder()
                    .WithLocation(@"C:\temp\QueryMonitor\VdbAlloc")
                    .ToJournal();

            using (var r = j.OpenRecordReadTx())
            {
                var records   = r.Execute("Select status from VdbAlloc latest by correlationId");
                var allStatus = records.RecordIDs().Select(rid => records.Get <string>(rid, 0)).ToArray();
                int i         = 0;
            }
        }
        public void GivenOwnCreditCard_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var collectionMethod = new OwnCreditCardBuilder(this.Session)
                                   .WithCreditCard(creditCard)
                                   .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                   .Build();

            ((OrganisationDerivedRoles)this.InternalOrganisation).AddActiveCollectionMethod(collectionMethod);

            this.Session.Commit();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = collectionMethod;

            Assert.False(this.Session.Derive(false).HasErrors);

            collectionMethod.Journal = journal;

            Assert.True(this.Session.Derive(false).HasErrors);

            collectionMethod.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #12
0
        public void GivenCashPaymentMethodForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession)
                .WithName("supplier")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build();

            this.DatabaseSession.Commit();

            var cash = new CashBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithCreditor(supplierRelationship)
                .Build();

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(cash);
            internalOrganisation.DoAccounting = true;

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            cash.Journal = journal;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            cash.RemoveJournal();
            cash.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #13
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanBeChangedWhenNotUsedYet()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0001")
                                        .WithName("bankAccount 1")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount1)
                                                 .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0002")
                                        .WithName("bankAccount 2")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount2)
                                                 .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("description")
                          .WithContraAccount(internalOrganisationGlAccount1)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .Build();

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.ContraAccount = internalOrganisationGlAccount2;

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount2, journal.PreviousContraAccount.GeneralLedgerAccount);
        }
Example #14
0
        private static IJournal <File> OpenJournal(EFileAccess access, DateTimeMode mode)
        {
            string directoryPath = Path.Combine(Utils.FindJournalsPath(), FOLDER_PATH);
            var    jb            = new JournalBuilder()
                                   .WithRecordCountHint(TestUtils.GENERATE_RECORDS_COUNT)
                                   .WithPartitionBy(EPartitionType.Month)
                                   .WithLocation(directoryPath)
                                   .WithSymbolColumn("Path", 10000, 20, 20)
                                   .WithTimestampColumn("Modified");

            if (mode == DateTimeMode.EpochMilliseconds)
            {
                jb = jb.WithEpochDateTimeColumn("Modified")
                     .WithEpochDateTimeColumn("Created");
            }
            return(jb.WithAccess(access).ToJournal <File>());
        }
Example #15
0
        private static IJournal <T> ToJournal <T>(T item)
        {
            TestShared.Utils.ClearDir("ThriftSerializerFactoryTests");
            var j = new JournalBuilder()
                    .WithAccess(EFileAccess.ReadWrite)
                    .WithLocation("ThriftSerializerFactoryTests")
                    .WithSerializerFactoryName(MetadataConstants.THRIFT_SERIALIZER_NAME)
                    .ToJournal <T>();

            using (var wr = j.OpenWriteTx())
            {
                wr.Append(item);
                wr.Commit();
            }

            return(j);
        }
Example #16
0
        public void ReadWrite()
        {
            // Clean..
            Utils.ClearJournal <PocoQuote>("c:\\temp\\quote");

            // Create.
            var journal = new JournalBuilder()
                          .WithRecordCountHint(1000000)
                          .WithPartitionBy(EPartitionType.Day)
                          .WithLocation("c:\\temp\\quote")
                          .WithSymbolColumn("Sym", 20, 5, 5)
                          .WithSymbolColumn("Ex", 20, 20, 20)
                          .WithSymbolColumn("Mode", 20, 20, 20)
                          .WithTimestampColumn("Timestamp")
                          .WithAccess(EFileAccess.ReadWrite)
                          .ToJournal <PocoQuote>();

            // Append.
            var start = DateTime.Now.Date.AddMonths(-1);

            using (var wr = journal.OpenWriteTx())
            {
                var quote = new PocoQuote();
                for (int i = 0; i < 1000000; i++)
                {
                    quote.Timestamp = start.AddSeconds(i);
                    quote.Bid       = i * 2.04;
                    quote.Bid       = i;
                    quote.BidSize   = i;
                    quote.Ask       = i * 50.09014;
                    quote.AskSize   = i;
                    quote.Ex        = "LXE";
                    quote.Mode      = "Fast trading";
                    quote.Sym       = "SYM" + i % 20;
                    wr.Append(quote);
                }
                wr.Commit();
            }

            // Query.
            // Read all where Sym = "SYM11".
            using (var rdr = journal.OpenReadTx())
            {
                Console.WriteLine(rdr.Items.Where(i => i.Sym == "SYM0").Count());
            }
        }
Example #17
0
        public int Should_calculate_bit_hint_for_fixed_columns(int recordCount, string fieldName)
        {
            // Create.
            ClearJournalFolder();
            using (var journal = new JournalBuilder()
                                 .WithRecordCountHint(recordCount)
                                 .WithLocation(DIRECTORY_PATH)
                                 .ToJournal <TestJournal>())
            {
                var storage = CreateStorage(journal);

                // Act.
                var col = journal.Metadata.GetColumnByPropertyName(fieldName);
                storage.GetFile(col, 1, EDataType.Data, journal.Metadata.Settings.RecordHint);

                return(_bitHint);
            }
        }
        public void GivenOwnBankAccountForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var internalOrganisation = this.InternalOrganisation;

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var netherlands = new Countries(this.Session).CountryByIsoCode["NL"];
            var euro        = netherlands.Currency;

            var bank        = new BankBuilder(this.Session).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();
            var bankAccount = new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build();

            var collectionMethod = new OwnBankAccountBuilder(this.Session)
                                   .WithDescription("own account")
                                   .WithBankAccount(bankAccount)
                                   .Build();

            this.Session.Commit();

            internalOrganisation.DoAccounting = true;

            ((OrganisationDerivedRoles)internalOrganisation).AddActiveCollectionMethod(collectionMethod);

            Assert.True(this.Session.Derive(false).HasErrors);

            collectionMethod.Journal = journal;

            Assert.False(this.Session.Derive(false).HasErrors);

            collectionMethod.RemoveJournal();
            collectionMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnCreditCardForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.Session)
                                .WithCreditCard(creditCard)
                                .Build();

            this.InternalOrganisation.AddPaymentMethod(paymentMethod);

            Assert.True(this.Session.Derive(false).HasErrors);

            paymentMethod.Journal = journal;

            Assert.False(this.Session.Derive(false).HasErrors);

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnBankAccount_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var netherlands = new Countries(this.Session).CountryByIsoCode["NL"];
            var euro        = netherlands.Currency;

            var bank        = new BankBuilder(this.Session).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();
            var bankAccount = new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build();

            var paymentMethod = new OwnBankAccountBuilder(this.Session)
                                .WithDescription("own account")
                                .WithBankAccount(bankAccount)
                                .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                .Build();

            this.Session.Commit();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = paymentMethod;

            Assert.False(this.Session.Derive(false).HasErrors);

            paymentMethod.Journal = journal;

            Assert.True(this.Session.Derive(false).HasErrors);

            paymentMethod.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #21
0
        public void GivenCashPaymentMethodForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var internalOrganisation = this.InternalOrganisation;

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithInternalOrganisation(this.InternalOrganisation)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("journal")
                          .Build();

            this.Session.Commit();

            var cash = new CashBuilder(this.Session)
                       .WithDescription("description")
                       .Build();

            internalOrganisation.DoAccounting = true;
            ((OrganisationDerivedRoles)internalOrganisation).AddActiveCollectionMethod(cash);

            Assert.True(this.Session.Derive(false).HasErrors);

            cash.Journal = journal;

            Assert.False(this.Session.Derive(false).HasErrors);

            cash.RemoveJournal();
            cash.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #22
0
        public long ShouldHandleDeletedPartitoinAfterRestart(bool clearPartition1, int days)
        {
            using (WriteJournal(EPartitionType.Month, TimeSpan.FromDays(1), days))
            {
            }

            if (clearPartition1)
            {
                var newVersion = new PartitionDate(START_DATE, 0, EPartitionType.Month).Name;
                Directory.Delete(Path.Combine(_directoryPath, newVersion), true);
            }

            using (IJournal <PocoType> journal = new JournalBuilder()
                                                 .WithLocation(_directoryPath)
                                                 .ToJournal <PocoType>())
            {
                using (var rtx = journal.OpenReadTx())
                {
                    return(rtx.All().Length ?? 0L);
                }
            }
        }
Example #23
0
        public int Should_calculate_bit_hint_for_symbol_columns(
            int recordCount, int distinctCount, int avgSize, EDataType dataType)
        {
            // Create.
            ClearJournalFolder();
            const string fieldName = "symbolField";

            using (var journal = new JournalBuilder()
                                 .WithRecordCountHint(recordCount)
                                 .WithSymbolColumn(fieldName, distinctCount, avgSize)
                                 .WithLocation(DIRECTORY_PATH)
                                 .ToJournal <TestJournal>())
            {
                var storage = CreateStorage(journal);

                // Act.
                var col = journal.Metadata.GetColumnByPropertyName(fieldName);
                storage.GetFile(col, 1, dataType, journal.Metadata.Settings.RecordHint);

                return(_bitHint);
            }
        }
Example #24
0
        public void GivenCashPaymentMethod_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            this.Session.Commit();

            var cash = new CashBuilder(this.Session)
                       .WithDescription("description")
                       .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                       .Build();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = cash;

            Assert.False(this.Session.Derive(false).HasErrors);

            cash.Journal = journal;

            Assert.True(this.Session.Derive(false).HasErrors);

            cash.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #25
0
        public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession)
                .WithName("supplier")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .WithCreditor(supplierRelationship)
                .Build();

            this.DatabaseSession.Commit();

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(paymentMethod);
            internalOrganisation.DoAccounting = true;

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            paymentMethod.Journal = journal;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #26
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanBeChangedWhenNotUsedYet()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("bankAccount 1")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount1)
                .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0002")
                .WithName("bankAccount 2")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount2)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithContraAccount(internalOrganisationGlAccount1)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.ContraAccount = internalOrganisationGlAccount2;

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount2, journal.PreviousContraAccount.GeneralLedgerAccount);
        }
Example #27
0
        public void GivenJournal_WhenDeriving_ThenJournalTypeCanNotBeChangedWhenJournalEntriesArePresent()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("bankAccount 1")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount1)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithContraAccount(internalOrganisationGlAccount)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.AddJournalEntry(new JournalEntryBuilder(this.DatabaseSession)
                                        .WithJournalEntryDetail(new JournalEntryDetailBuilder(this.DatabaseSession)
                                                                    .WithAmount(1)
                                                                    .WithDebit(true)
                                                                    .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                                                    .Build())
                                        .Build());

            journal.JournalType = new JournalTypes(this.DatabaseSession).Cash;

            Assert.AreEqual("Journal.JournalType, Journal.PreviousJournalType are not equal", this.DatabaseSession.Derive().Errors[0].Message);
        }
Example #28
0
        public void GivenJournal_WhenDeriving_ThenJournalTypeMustExist()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            var glAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(glAccount)
                .Build();

            this.DatabaseSession.Commit();

            var builder = new JournalBuilder(this.DatabaseSession);
            builder.WithDescription("description");
            builder.WithContraAccount(internalOrganisationGlAccount);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithJournalType(new JournalTypes(this.DatabaseSession).Bank);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }