public void TestInitialise()
 {
     var accountRepo = new InMemoryAccountTypeRepository();
     var bucketRepo = new BucketBucketRepoAlwaysFind();
     var subject = new Mapper_LedgerBookDto_LedgerBook(bucketRepo, accountRepo, new LedgerBucketFactory(bucketRepo, accountRepo), new LedgerTransactionFactory(), new Mock<IReconciliationBuilder>().Object);
     Result = subject.ToDto(TestData);
 }
        protected override void SaveDtoToDisk(LedgerBookDto dataEntity)
        {
            if (SaveDtoToDiskOverride == null)
            {
                base.SaveDtoToDisk(dataEntity);
                return;
            }

            SaveDtoToDiskOverride(dataEntity);
        }
        protected override async Task SaveDtoToDiskAsync(LedgerBookDto dataEntity, bool isEncrypted)
        {
            if (SaveDtoToDiskOverride == null)
            {
                await base.SaveDtoToDiskAsync(dataEntity, isEncrypted);
                return;
            }

            SaveDtoToDiskOverride(dataEntity);
        }
Beispiel #4
0
        /// <summary>
        ///     Custom initialisation and validation to be done directly after mapping the <see cref="LedgerBook" />.
        ///     For example: Must make sure that the <see cref="LedgerBook.Ledgers" /> Collection is populated and each one has a
        ///     default storage Account.
        /// </summary>
        private void InitialiseAndValidateLedgerBook(LedgerBookDto dto, LedgerBook model)
        {
            this.cachedLedgers.Clear();
            foreach (var ledgerBucket in model.Ledgers)
            {
                if (ledgerBucket.StoredInAccount == null)
                {
                    // Defaults to Cheque Account if unspecified.
                    ledgerBucket.StoredInAccount = this.accountTypeRepo.GetByKey(AccountTypeRepositoryConstants.Cheque);
                }

                GetOrAddFromCache(ledgerBucket);
            }

            var ledgersMapWasEmpty = model.Ledgers.None();

            // Default to CHEQUE when StoredInAccount is null.
            foreach (var line in model.Reconciliations)
            {
                foreach (var entry in line.Entries)
                {
                    // Ensure the ledger bucker is the same instance as listed in the book.Legders;
                    entry.LedgerBucket = GetOrAddFromCache(entry.LedgerBucket, true);
                    if (entry.LedgerBucket.StoredInAccount == null)
                    {
                        entry.LedgerBucket.StoredInAccount = this.accountTypeRepo.GetByKey(AccountTypeRepositoryConstants.Cheque);
                    }
                }
            }

            // If ledger column map at the book level was empty, default it to the last used ledger columns in the Dated Entries.
            if (ledgersMapWasEmpty && model.Reconciliations.Any())
            {
                model.Ledgers = model.Reconciliations.First().Entries.Select(e => e.LedgerBucket);
            }
        }
        /// <summary>
        ///     Custom initialisation and validation to be done directly after mapping the <see cref="LedgerBook" />.
        ///     For example: Must make sure that the <see cref="LedgerBook.Ledgers" /> Collection is populated and each one has a
        ///     default storage Account.
        /// </summary>
        private void InitialiseAndValidateLedgerBook(LedgerBookDto dto, LedgerBook model)
        {
            this.cachedLedgers.Clear();
            foreach (var ledgerBucket in model.Ledgers)
            {
                if (ledgerBucket.StoredInAccount == null)
                {
                    // Defaults to Cheque Account if unspecified.
                    ledgerBucket.StoredInAccount = this.accountTypeRepo.GetByKey(AccountTypeRepositoryConstants.Cheque);
                }

                GetOrAddFromCache(ledgerBucket);
            }

            var ledgersMapWasEmpty = model.Ledgers.None();

            // Default to CHEQUE when StoredInAccount is null.
            foreach (var line in model.Reconciliations)
            {
                foreach (var entry in line.Entries)
                {
                    // Ensure the ledger bucker is the same instance as listed in the book.Legders;
                    entry.LedgerBucket = GetOrAddFromCache(entry.LedgerBucket, true);
                    if (entry.LedgerBucket.StoredInAccount == null)
                    {
                        entry.LedgerBucket.StoredInAccount = this.accountTypeRepo.GetByKey(AccountTypeRepositoryConstants.Cheque);
                    }
                }
            }

            // If ledger column map at the book level was empty, default it to the last used ledger columns in the Dated Entries.
            if (ledgersMapWasEmpty && model.Reconciliations.Any())
            {
                model.Ledgers = model.Reconciliations.First().Entries.Select(e => e.LedgerBucket);
            }
        }
        public void ShouldMapLineBalanceAdjustments()
        {
            TestData = LedgerBookDtoTestData.TestData2();
            LedgerBook result = ArrangeAndAct();
            LedgerEntryLine subject = result.DatedEntries.First();

            Assert.AreEqual(TestData.DatedEntries.First().BankBalanceAdjustments.Sum(a => a.Credit - a.Debit), subject.TotalBalanceAdjustments);
            Assert.AreNotEqual(0, subject.BankBalanceAdjustments.Count());
        }
 public void TestInitialise()
 {
     AutoMapperConfigurationTest.AutoMapperConfiguration();
     TestData = LedgerBookDtoTestData.TestData1();
 }
Beispiel #8
0
 partial void ToModelPostprocessing(LedgerBookDto dto, ref LedgerBook model)
 {
     InitialiseAndValidateLedgerBook(dto, model);
 }
Beispiel #9
0
 // ReSharper disable once RedundantAssignment
 partial void ModelFactory(LedgerBookDto dto, ref LedgerBook model)
 {
     // TODO Seems odd that a mapper requires the ReconciliationBuilder, either need a factory or better yet move the reconciliation code out of the LedgerBook class.
     model = new LedgerBook(this.reconciliationBuilder);
 }
        public static LedgerBookDto TestData1()
        {
            var book = new LedgerBookDto
            {
                Modified = new DateTime(2013, 12, 14),
                Name = "Test Budget Ledger Book 1",
                FileName = "C:\\Folder\\FooBook.xml",
            };

            var lines = new List<LedgerEntryLineDto>();

            var line1 = AddEntryLineForTestData1(lines, new DateTime(2013, 12, 20));
            line1.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    Balance = 0, // because would go into negative
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id1,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                        new LedgerTransactionDto
                        {
                            Id = id2,
                            Debit = 195,
                            Narrative = "Rates payment",
                            TransactionType = typeof(DebitLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    Balance = 21.15M,
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id3,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    Balance = 0, // because would go into negative
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id4,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                        new LedgerTransactionDto
                        {
                            Id = id5,
                            Debit = 295.45M,
                            Narrative = "Fix car",
                            TransactionType = typeof(DebitLedgerTransaction).FullName,
                        }
                    }
                }
            });

            var line2 = AddEntryLineForTestData1(lines, new DateTime(2014, 1, 20));
            line2.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id6,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id7,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id8,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                }
            });

            var line3 = AddEntryLineForTestData1(lines, new DateTime(2014, 02, 20));
            line3.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id9,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id10,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id11,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                }
            });

            UpdateLineBalances(line1, null, 1999.25M);
            UpdateLineBalances(line2, line1, 2001.15M);
            UpdateLineBalances(line3, line2, 1801.45M);
            book.DatedEntries = lines.OrderByDescending(e => e.Date).ToList();
            return book;
        }
 // ReSharper disable once RedundantAssignment
 partial void ModelFactory(LedgerBookDto dto, ref LedgerBook model)
 {
     // TODO Seems odd that a mapper requires the ReconciliationBuilder, either need a factory or better yet move the reconciliation code out of the LedgerBook class.
     model = new LedgerBook(this.reconciliationBuilder);
 }
 partial void ToModelPostprocessing(LedgerBookDto dto, ref LedgerBook model)
 {
     InitialiseAndValidateLedgerBook(dto, model);
 }
 public void TestInitialise()
 {
     TestData = LedgerBookDtoTestData.TestData1();
 }
        public void ShouldMapLineBalanceAdjustments()
        {
            TestData = LedgerBookDtoTestData.TestData2();
            LedgerBook result = ArrangeAndAct();
            LedgerEntryLine subject = result.Reconciliations.First();

            Assert.AreEqual(TestData.Reconciliations.First().BankBalanceAdjustments.Sum(a => a.Amount), subject.TotalBalanceAdjustments);
            Assert.AreNotEqual(0, subject.BankBalanceAdjustments.Count());
        }
        /// <summary>
        /// Same as TestData1 but with some Balance Adjustments on the most recent line.
        /// The most recent line also has two bank balances associated with it.
        /// </summary>
        public static LedgerBookDto TestData3()
        {
            var book = new LedgerBookDto
            {
                Modified = new DateTime(2013, 12, 14),
                Name = "Test Budget Ledger Book 3",
                FileName = "C:\\Folder\\FooBook3.xml",
            };

            var lines = new List<LedgerEntryLineDto>();

            var line1 = AddEntryLineForTestData1(lines, new DateTime(2013, 12, 20));
            line1.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    Balance = 0, // because would go into negative
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id1,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                        new LedgerTransactionDto
                        {
                            Id = id2,
                            Debit = 195,
                            Narrative = "Rates payment",
                            TransactionType = typeof(DebitLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    Balance = 21.15M,
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id3,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    Balance = 0, // because would go into negative
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id4,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                        new LedgerTransactionDto
                        {
                            Id = id5,
                            Debit = 295.45M,
                            Narrative = "Fix car",
                            TransactionType = typeof(DebitLedgerTransaction).FullName,
                        }
                    }
                }
            });

            var line2 = AddEntryLineForTestData1(lines, new DateTime(2014, 1, 20));
            line2.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id6,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id7,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id8,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                }
            });

            var line3 = AddEntryLineForTestData1(lines, new DateTime(2014, 02, 20));
            line3.Entries.AddRange(new[]
            {
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RatesBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id9,
                            Credit = 75,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.RegoBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id10,
                            Credit = 21.15M,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        }
                    }
                },
                new LedgerEntryDto
                {
                    BucketCode = TestDataConstants.CarMtcBucketCode,
                    Transactions = new List<LedgerTransactionDto>
                    {
                        new LedgerTransactionDto
                        {
                            Id = id11,
                            Credit = 95,
                            Narrative = "Budgeted Amount",
                            TransactionType = typeof(BudgetCreditLedgerTransaction).FullName,
                        },
                    }
                }
            });

            line3.BankBalanceAdjustments.Add(new LedgerTransactionDto
            {
                AccountType = StatementModelTestData.ChequeAccount.Name,
                Debit = 100.01M,
                Narrative = "Visa payment yet to go out",
                Id = new Guid("22927CF0-BAA2-4828-A669-C77396888BD6"),
                TransactionType = typeof(CreditLedgerTransaction).FullName,
            });

            UpdateLineBalances(line1, null, 1999.25M);
            UpdateLineBalances(line2, line1, 2001.15M);
            UpdateLineBalances(line3, line2, 1801.45M);
            line3.BankBalances.Add(
                new BankBalanceDto
                {
                    Account = StatementModelTestData.SavingsAccount.Name,
                    Balance = 201M,
                });
            line3.BankBalance += 201M;

            book.DatedEntries = lines.OrderByDescending(e => e.Date).ToList();
            return book;
        }
        /// <summary>
        ///     Serialises the specified data entity.
        /// </summary>
        /// <param name="dataEntity">The data entity.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        protected virtual string Serialise(LedgerBookDto dataEntity)
        {
            if (dataEntity == null)
            {
                throw new ArgumentNullException(nameof(dataEntity));
            }

            return XamlServices.Save(dataEntity);
        }
 protected override string Serialise(LedgerBookDto dataEntity)
 {
     SerialisedData = base.Serialise(dataEntity);
     return SerialisedData;
 }
        public static LedgerBookDto TestData2()
        {
            var book = new LedgerBookDto
            {
                Modified = new DateTime(2013, 12, 14),
                Name = "Test Budget Ledger Book 2",
                StorageKey = "C:\\Folder\\FooBook2.xml"
            };

            var lines = new List<LedgerEntryLineDto>();

            LedgerEntryLineDto line1 = AddEntryLineForTestData2(lines, new DateTime(2013, 12, 20));
            line1.Entries.AddRange(
                new[]
                {
                    new LedgerEntryDto
                    {
                        Balance = 0, // because would go into negative
                        BucketCode = TestDataConstants.RatesBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id1,
                                Amount = 75,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        Balance = 21.15M,
                        BucketCode = TestDataConstants.RegoBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id2,
                                Amount = 21.15M,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        Balance = 0, // because would go into negative
                        BucketCode = TestDataConstants.CarMtcBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id3,
                                Amount = 95,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    }
                });

            LedgerEntryLineDto line2 = AddEntryLineForTestData2(lines, new DateTime(2014, 1, 20));
            line2.Entries.AddRange(
                new[]
                {
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.RatesBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id4,
                                Amount = 75,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.RegoBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id5,
                                Amount = 21.15M,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.CarMtcBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id6,
                                Amount = 95,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    }
                });

            LedgerEntryLineDto line3 = AddEntryLineForTestData2(lines, new DateTime(2014, 02, 20));
            line3.Entries.AddRange(
                new[]
                {
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.RatesBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id7,
                                Amount = 75,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            },
                            new LedgerTransactionDto
                            {
                                Id = id8,
                                Amount = -195,
                                Narrative = "Rates payment",
                                TransactionType = typeof(CreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.RegoBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id9,
                                Amount = 21.15M,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            }
                        }
                    },
                    new LedgerEntryDto
                    {
                        BucketCode = TestDataConstants.CarMtcBucketCode,
                        Transactions = new List<LedgerTransactionDto>
                        {
                            new LedgerTransactionDto
                            {
                                Id = id10,
                                Amount = 95,
                                Narrative = "Budgeted Amount",
                                TransactionType = typeof(BudgetCreditLedgerTransaction).FullName
                            },
                            new LedgerTransactionDto
                            {
                                Id = id11,
                                Amount = -295.45M,
                                Narrative = "Fix car",
                                TransactionType = typeof(CreditLedgerTransaction).FullName
                            }
                        }
                    }
                });

            UpdateLineBalances(line1, null, 1999.25M);
            UpdateLineBalances(line2, line1, 2001.15M);
            UpdateLineBalances(line3, line2, 1801.45M);
            book.Reconciliations = lines.OrderByDescending(e => e.Date).ToList();
            book.Ledgers.Add(new LedgerBucketDto { BucketCode = TestDataConstants.RegoBucketCode, StoredInAccount = TestDataConstants.ChequeAccountName });
            book.Ledgers.Add(new LedgerBucketDto { BucketCode = TestDataConstants.CarMtcBucketCode, StoredInAccount = TestDataConstants.ChequeAccountName });
            book.Ledgers.Add(new LedgerBucketDto { BucketCode = TestDataConstants.RatesBucketCode, StoredInAccount = TestDataConstants.ChequeAccountName });
            return book;
        }