public void TestCreateManyTransactions()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var newTransactions = new Transaction[]
                {
                    new Transaction {
                        CreditAccount = accountService.GetAsLink(incomeAccountEntity.AccountId),
                        DebitAccount  = accountService.GetAsLink(checkingAccountEntity.AccountId),
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 9, 0, 0)
                    },
                    new Transaction {
                        CreditAccount = accountService.GetAsLink(incomeAccountEntity.AccountId),
                        DebitAccount  = accountService.GetAsLink(checkingAccountEntity.AccountId),
                        Amount        = 70m,
                        At            = new DateTime(2018, 1, 1, 9, 25, 0)
                    }
                };
                transactionService.CreateMany(newTransactions);

                List <Entities.Transaction> transactionEntities = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(2, transactionEntities.Count);
                Assert.AreEqual(newTransactions[0].TransactionId, transactionEntities[0].TransactionId);
                Assert.AreEqual(newTransactions[0].CreditAccount.AccountId, transactionEntities[0].CreditAccount.AccountId);
                Assert.AreEqual(newTransactions[0].DebitAccount.AccountId, transactionEntities[0].DebitAccount.AccountId);
                Assert.AreEqual(newTransactions[0].Amount, transactionEntities[0].Amount);
                Assert.AreEqual(newTransactions[0].At, transactionEntities[0].At);
                Assert.AreEqual(newTransactions[1].TransactionId, transactionEntities[1].TransactionId);
                Assert.AreEqual(newTransactions[1].CreditAccount.AccountId, transactionEntities[1].CreditAccount.AccountId);
                Assert.AreEqual(newTransactions[1].DebitAccount.AccountId, transactionEntities[1].DebitAccount.AccountId);
                Assert.AreEqual(newTransactions[1].Amount, transactionEntities[1].Amount);
                Assert.AreEqual(newTransactions[1].At, transactionEntities[1].At);
            }
        }
        public void TestGetAllAccountRelationships()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountRelationshipService = new AccountRelationshipService(loggerFactory, sqliteMemoryWrapper.DbContext);

                List <AccountRelationship> accountRelationships = accountRelationshipService.GetAll().ToList();

                Assert.AreEqual(2, accountRelationships.Count);
                Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationships[0].Type);
                Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationships[0].SourceAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accountRelationships[0].SourceAccount.Name);
                Assert.AreEqual(groceriesPrepaymentAccountEntity.AccountId, accountRelationships[0].DestinationAccount.AccountId);
                Assert.AreEqual(groceriesPrepaymentAccountEntity.Name, accountRelationships[0].DestinationAccount.Name);
                Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationships[1].Type);
                Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationships[1].SourceAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accountRelationships[1].SourceAccount.Name);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationships[1].DestinationAccount.AccountId);
                Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationships[1].DestinationAccount.Name);
            }
        }
示例#3
0
        public void TestTransactionCreateViewModelCancel()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity   = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var mockViewModelFactory = new Mock <IAccountLinkViewModelFactory>();
                mockViewModelFactory
                .Setup(f => f.Create(It.IsAny <AccountLink>()))
                .Returns((AccountLink accountLink) =>
                {
                    return(new AccountLinkViewModel(
                               loggerFactory,
                               accountLink));
                });

                var hint = new Transaction
                {
                    CreditAccount = accountService.GetAsLink(incomeAccountEntity.AccountId),
                    DebitAccount  = accountService.GetAsLink(checkingAccountEntity.AccountId),
                    Amount        = 10m,
                    At            = new DateTime(2018, 1, 1, 9, 0, 0)
                };

                var viewModel = new TransactionCreateViewModel(
                    loggerFactory,
                    accountService,
                    transactionService,
                    mockViewModelFactory.Object,
                    hint
                    );

                viewModel.CancelCommand.Execute(this);

                List <Transaction> transactions = transactionService.GetAll().ToList();

                Assert.AreEqual(0, transactions.Count);
            }
        }
示例#4
0
        public void TestAccountRelationshipEditViewModelOK()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var accountRelationshipService = new AccountRelationshipService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var viewModel = new AccountRelationshipEditViewModel(
                    loggerFactory,
                    accountService,
                    accountRelationshipService,
                    checkingToRentPrepaymentRelationship.AccountRelationshipId
                    );

                viewModel.SelectedType = AccountRelationshipType.PrepaymentToExpense;
                viewModel.OKCommand.Execute(this);

                List <AccountRelationship> accountRelationships = accountRelationshipService.GetAll().ToList();

                Assert.AreEqual(1, accountRelationships.Count);
                Assert.AreEqual(checkingToRentPrepaymentRelationship.SourceAccountId,
                                accountRelationships[0].SourceAccount.AccountId);
                Assert.AreEqual(checkingToRentPrepaymentRelationship.DestinationAccountId,
                                accountRelationships[0].DestinationAccount.AccountId);
                Assert.AreEqual(viewModel.SelectedType,
                                accountRelationships[0].Type);
            }
        }
示例#5
0
        public void TestReloadAccountRelationship()
        {
            const string   path          = "TestData/AccountRelationshipReload.xml";
            ILoggerFactory loggerFactory = new LoggerFactory();

            var currencyFactory   = new CurrencyFactory();
            var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);

            var accountFactory = new AccountFactory();

            Entities.Account checkingAccountEntity =
                accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
            Entities.Account rentPrepaymentAccountEntity =
                accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);

            var accountRelationship = new Entities.AccountRelationship
            {
                SourceAccount      = checkingAccountEntity,
                DestinationAccount = rentPrepaymentAccountEntity,
                Type = AccountRelationshipType.PhysicalToLogical
            };

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(accountRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Save(path);
            }

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Load(path);

                List <Entities.Account>             accounts             = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Entities.AccountRelationship> accountRelationships = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();
                List <Entities.Currency>            currencies           = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Entities.Transaction>         transactions         = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(2, accounts.Count);
                Assert.AreEqual(1, accountRelationships.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);

                Assert.AreEqual(checkingAccountEntity.Name, accountRelationships[0].SourceAccount.Name);
                Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationships[0].DestinationAccount.Name);
                Assert.AreEqual(accountRelationship.Type, accountRelationships[0].Type);
            }
        }
        public void TestCreateAccountRelationship()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );

                AccountLink checkingAccountLink       = accountService.GetAsLink(checkingAccountEntity.AccountId);
                AccountLink rentPrepaymentAccountLink = accountService.GetAsLink(rentPrepaymentAccountEntity.AccountId);

                var accountRelationshipService = new AccountRelationshipService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );

                var newRelationship = new AccountRelationship
                {
                    SourceAccount      = checkingAccountLink,
                    DestinationAccount = rentPrepaymentAccountLink,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                accountRelationshipService.Create(newRelationship);

                List <Entities.AccountRelationship> accountRelationshipEntities =
                    sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();

                Assert.AreEqual(1, accountRelationshipEntities.Count);
                Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationshipEntities[0].Type);
                Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationshipEntities[0].SourceAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accountRelationshipEntities[0].SourceAccount.Name);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationshipEntities[0].DestinationAccount.AccountId);
                Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationshipEntities[0].DestinationAccount.Name);
            }
        }
示例#7
0
        public void TestGetLogicalAccountIds()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(loggerFactory, sqliteMemoryWrapper.DbContext);

                var incomeAccountLogicalAccountIds              = new HashSet <int>(accountService.GetLogicalAccountIds(incomeAccountEntity.AccountId));
                var checkingAccountLogicalAccountIds            = new HashSet <int>(accountService.GetLogicalAccountIds(checkingAccountEntity.AccountId));
                var groceriesPrepaymentAccountLogicalAccountIds = new HashSet <int>(accountService.GetLogicalAccountIds(groceriesPrepaymentAccountEntity.AccountId));

                Assert.AreEqual(0, incomeAccountLogicalAccountIds.Count);
                Assert.AreEqual(2, checkingAccountLogicalAccountIds.Count);
                Assert.IsTrue(checkingAccountLogicalAccountIds.Contains(groceriesPrepaymentAccountEntity.AccountId));
                Assert.IsTrue(checkingAccountLogicalAccountIds.Contains(rentPrepaymentAccountEntity.AccountId));
                Assert.AreEqual(0, groceriesPrepaymentAccountLogicalAccountIds.Count);
            }
        }
        public void TestTransactionDelete()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 60m,
                        At            = new DateTime(2018, 1, 1, 8, 31, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var transactionService = new TransactionService(loggerFactory, sqliteMemoryWrapper.DbContext);

                transactionService.Delete(transactionEntities[0].TransactionId);

                List <Transaction> transactions = transactionService.GetAll().ToList();

                Assert.AreEqual(1, transactions.Count);
                Assert.AreEqual(transactionEntities[1].TransactionId, transactions[0].TransactionId);
                Assert.AreEqual(transactionEntities[1].Amount, transactions[0].Amount);
                Assert.AreEqual(transactionEntities[1].At, transactions[0].At);
                Assert.AreEqual(transactionEntities[1].CreditAccountId, transactions[0].CreditAccount.AccountId);
                Assert.AreEqual(transactionEntities[1].DebitAccountId, transactions[0].DebitAccount.AccountId);
            }
        }
示例#9
0
        public void TestBalanceSheetNoTransactions()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account capitalAccountEntity =
                    accountFactory.Create(AccountPrefab.Capital, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account creditCardAccountEntity =
                    accountFactory.Create(AccountPrefab.CreditCard, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, capitalAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, creditCardAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var currencyService = new CurrencyService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var balanceSheetService = new BalanceSheetService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );

                BalanceSheet            balanceSheet            = balanceSheetService.Generate(new DateTime(2018, 1, 1));
                List <BalanceSheetItem> balanceSheetAssets      = balanceSheet.Assets.ToList();
                List <BalanceSheetItem> balanceSheetLiabilities = balanceSheet.Liabilities.ToList();

                Assert.AreEqual(usdCurrencyEntity.Symbol, balanceSheet.CurrencySymbol);
                Assert.AreEqual(0, balanceSheet.TotalAssets);
                Assert.AreEqual(0, balanceSheet.TotalLiabilities);
                Assert.AreEqual(0, balanceSheetAssets.Count);
                Assert.AreEqual(0, balanceSheetLiabilities.Count);
            }
        }
示例#10
0
        public void TestCreateAccountRelationshipsInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);

                var checkingToRentPrepaymentRelationship = new AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var rentPrepaymentToExpenseRelationship = new AccountRelationship
                {
                    SourceAccount      = rentPrepaymentAccountEntity,
                    DestinationAccount = rentExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                List <Account>             accounts            = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <AccountRelationship> accountRelationsips = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();
                List <Currency>            currencies          = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Transaction>         transactions        = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(3, accounts.Count);
                Assert.AreEqual(2, accountRelationsips.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);
                Assert.AreEqual(checkingToRentPrepaymentRelationship.SourceAccount.Name, accountRelationsips[0].SourceAccount.Name);
                Assert.AreEqual(checkingToRentPrepaymentRelationship.DestinationAccount.Name, accountRelationsips[0].DestinationAccount.Name);
                Assert.AreEqual(rentPrepaymentToExpenseRelationship.SourceAccount.Name, accountRelationsips[1].SourceAccount.Name);
                Assert.AreEqual(rentPrepaymentToExpenseRelationship.DestinationAccount.Name, accountRelationsips[1].DestinationAccount.Name);
            }
        }
示例#11
0
        public void TestGetAccount()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var accountService = new AccountService(loggerFactory, sqliteMemoryWrapper.DbContext);

                Account checkingAccount = accountService.Get(checkingAccountEntity.AccountId);

                Assert.AreEqual(checkingAccountEntity.AccountId, checkingAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, checkingAccount.Name);
                Assert.AreEqual(AccountType.Asset, checkingAccount.Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, checkingAccount.Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, checkingAccount.Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, checkingAccount.Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, checkingAccount.Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, checkingAccount.Currency.Symbol);
            }
        }
        public void TestAccountRelationshipCreateViewModelCancel()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var accountRelationshipService = new AccountRelationshipService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var hint = new AccountRelationship
                {
                    SourceAccount      = accountService.GetAsLink(checkingAccountEntity.AccountId),
                    DestinationAccount = accountService.GetAsLink(rentPrepaymentAccountEntity.AccountId),
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var viewModel = new AccountRelationshipCreateViewModel(
                    loggerFactory,
                    accountService,
                    accountRelationshipService,
                    hint
                    );

                viewModel.SelectedType = AccountRelationshipType.PrepaymentToExpense;
                viewModel.CancelCommand.Execute(this);

                List <AccountRelationship> accountRelationships = accountRelationshipService.GetAll().ToList();

                Assert.AreEqual(0, accountRelationships.Count);
            }
        }
示例#13
0
        public void TestAccountTransactionListViewModelNoTransactions()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity   = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                IAccountTransactionItemViewModelFactory accountTransactionViewModelFactory =
                    new Concrete.StubAccountTransactionItemViewModelFactory();

                var viewModel = new AccountTransactionListViewModel(
                    loggerFactory,
                    accountService,
                    transactionService,
                    accountTransactionViewModelFactory,
                    new Mock <IDeleteConfirmationViewService>().Object,
                    new Mock <ITransactionCreateViewService>().Object,
                    new Mock <ITransactionEditViewService>().Object,
                    new Mock <IReconcileBalanceViewService>().Object,
                    checkingAccountEntity.AccountId);

                Assert.AreEqual(false, viewModel.HasLogicalAcounts);
                Assert.AreEqual(0, viewModel.Transactions.Count);
            }
        }
示例#14
0
        public void TestGetAllAccounts()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity   = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var accountService = new AccountService(loggerFactory, sqliteMemoryWrapper.DbContext);

                List <Account> accounts = accountService.GetAll().ToList();

                Assert.AreEqual(2, accounts.Count);
                Assert.AreEqual(incomeAccountEntity.AccountId, accounts[0].AccountId);
                Assert.AreEqual(incomeAccountEntity.Name, accounts[0].Name);
                Assert.AreEqual(AccountType.Income, accounts[0].Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, accounts[0].Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, accounts[0].Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, accounts[0].Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accounts[0].Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, accounts[0].Currency.Symbol);
                Assert.AreEqual(checkingAccountEntity.AccountId, accounts[1].AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accounts[1].Name);
                Assert.AreEqual(AccountType.Asset, accounts[1].Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, accounts[1].Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, accounts[1].Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, accounts[1].Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accounts[1].Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, accounts[1].Currency.Symbol);
            }
        }
示例#15
0
        public void TestUpdateAccount()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                var gbpCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Gbp, false);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, gbpCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var     accountService  = new AccountService(loggerFactory, sqliteMemoryWrapper.DbContext);
                Account checkingAccount = accountService.Get(checkingAccountEntity.AccountId);
                checkingAccount.Name = "Updated";
                checkingAccount.Type = AccountType.Expense;
                checkingAccount.Currency.CurrencyId = gbpCurrencyEntity.CurrencyId;
                accountService.Update(checkingAccount);

                List <Entities.Account> accountEntities = sqliteMemoryWrapper.DbContext.Accounts.ToList();

                Assert.AreEqual(2, accountEntities.Count);
                Assert.AreEqual(checkingAccount.Name, accountEntities[1].Name);
                Assert.AreEqual(AccountType.Expense, accountEntities[1].Type);
                Assert.AreEqual(gbpCurrencyEntity.CurrencyId, accountEntities[1].Currency.CurrencyId);
                Assert.AreEqual(gbpCurrencyEntity.IsPrimary, accountEntities[1].Currency.IsPrimary);
                Assert.AreEqual(gbpCurrencyEntity.Name, accountEntities[1].Currency.Name);
                Assert.AreEqual(gbpCurrencyEntity.ShortName, accountEntities[1].Currency.ShortName);
                Assert.AreEqual(gbpCurrencyEntity.Symbol, accountEntities[1].Currency.Symbol);
            }
        }
示例#16
0
        public void TestCreateTransactionInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var transaction = new Transaction
                {
                    CreditAccount = incomeAccountEntity,
                    DebitAccount  = checkingAccountEntity,
                    Amount        = 10m,
                    At            = new DateTime(2018, 1, 1, 8, 30, 1)
                };

                sqliteMemoryWrapper.DbContext.Transactions.Add(transaction);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                List <Account>     accounts     = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Currency>    currencies   = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Transaction> transactions = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(2, accounts.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(1, transactions.Count);
                Assert.AreEqual(transaction.CreditAccount.AccountId, transactions[0].CreditAccount.AccountId);
                Assert.AreEqual(transaction.Amount, transactions[0].Amount);
                Assert.AreEqual(transaction.DebitAccount.AccountId, transactions[0].DebitAccount.AccountId);
            }
        }
示例#17
0
        public void TestReloadAccount()
        {
            const string   path          = "TestData/AccountReload.xml";
            ILoggerFactory loggerFactory = new LoggerFactory();

            var currencyFactory = new CurrencyFactory();

            Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);

            var accountFactory = new AccountFactory();

            Entities.Account checkingAccountEntity =
                accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Save(path);
            }

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Load(path);

                List <Entities.Account>             accounts             = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Entities.AccountRelationship> accountRelationships = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();
                List <Entities.Currency>            currencies           = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Entities.Transaction>         transactions         = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(1, accounts.Count);
                Assert.AreEqual(0, accountRelationships.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);

                Assert.AreEqual(checkingAccountEntity.Name, accounts[0].Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accounts[0].Currency.ShortName);
            }
        }
示例#18
0
        public void TestCreateAccountInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                List <Account>     accounts     = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Currency>    currencies   = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Transaction> transactions = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(1, accounts.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);
                Assert.AreEqual(checkingAccountEntity.Currency.CurrencyId, accounts[0].Currency.CurrencyId);
            }
        }
示例#19
0
        public void TestAccountTransactionListViewModelPostDeleteBalanceRefresh()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 60m,
                        At            = new DateTime(2018, 1, 1, 8, 31, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 8, 32, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                IAccountTransactionItemViewModelFactory accountTransactionViewModelFactory =
                    new Concrete.StubAccountTransactionItemViewModelFactory();

                // Force transaction deletion to always confirm
                var mockDeleteConfirmationViewService = new Mock <IDeleteConfirmationViewService>();
                mockDeleteConfirmationViewService
                .Setup(s => s.Show(It.IsAny <string>()))
                .Returns(true);

                var viewModel = new AccountTransactionListViewModel(
                    loggerFactory,
                    accountService,
                    transactionService,
                    accountTransactionViewModelFactory,
                    mockDeleteConfirmationViewService.Object,
                    new Mock <ITransactionCreateViewService>().Object,
                    new Mock <ITransactionEditViewService>().Object,
                    new Mock <IReconcileBalanceViewService>().Object,
                    checkingAccountEntity.AccountId
                    );

                // Delete the first transaction
                viewModel.SelectedTransaction = viewModel.Transactions.OrderBy(t => t.At).First();
                viewModel.DeleteCommand.Execute(this);

                var transactionViewModels = new List <IAccountTransactionItemViewModel>(viewModel.Transactions.OrderBy(t => t.At));

                Assert.AreEqual(2, transactionViewModels.Count);
                Assert.AreEqual(transactionEntities[1].CreditAccount.AccountId, transactionViewModels[0].CreditAccount.AccountId);
                Assert.AreEqual(transactionEntities[1].DebitAccount.AccountId, transactionViewModels[0].DebitAccount.AccountId);
                Assert.AreEqual(transactionEntities[1].Amount, transactionViewModels[0].Amount);
                Assert.AreEqual(transactionEntities[1].At, transactionViewModels[0].At);
                Assert.AreEqual(-60m, transactionViewModels[0].Balance);
                Assert.AreEqual(transactionEntities[2].CreditAccount.AccountId, transactionViewModels[1].CreditAccount.AccountId);
                Assert.AreEqual(transactionEntities[2].DebitAccount.AccountId, transactionViewModels[1].DebitAccount.AccountId);
                Assert.AreEqual(transactionEntities[2].Amount, transactionViewModels[1].Amount);
                Assert.AreEqual(transactionEntities[2].At, transactionViewModels[1].At);
                Assert.AreEqual(-70m, transactionViewModels[1].Balance);
            }
        }
        public void TestGetAllTransactionsFilteredByAccountAndDateRange()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 60m,
                        At            = new DateTime(2018, 1, 1, 8, 35, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 9, 45, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 11, 15, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var transactionService = new TransactionService(loggerFactory, sqliteMemoryWrapper.DbContext);

                int[] accountIds = new int[1] {
                    rentPrepaymentAccountEntity.AccountId
                };
                List <Transaction> transactions = transactionService
                                                  .GetAll(
                    accountIds,
                    new DateTime(2018, 1, 1, 8, 35, 0),
                    new DateTime(2018, 1, 1, 10, 0, 0)
                    )
                                                  .ToList();

                Assert.AreEqual(2, transactions.Count);

                Assert.AreEqual(2, transactions[0].TransactionId);
                Assert.AreEqual(checkingAccountEntity.AccountId, transactions[0].CreditAccount.AccountId);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, transactions[0].DebitAccount.AccountId);
                Assert.AreEqual(transactionEntities[1].Amount, transactions[0].Amount);
                Assert.AreEqual(transactionEntities[1].At, transactions[0].At);
                Assert.AreEqual(checkingAccountEntity.AccountId, transactions[1].CreditAccount.AccountId);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, transactions[1].DebitAccount.AccountId);
                Assert.AreEqual(transactionEntities[2].Amount, transactions[1].Amount);
                Assert.AreEqual(transactionEntities[2].At, transactions[1].At);
            }
        }
示例#21
0
        public void TestCreateTransactionRelationship()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();

                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account creditCardAccountEntity =
                    accountFactory.Create(AccountPrefab.CreditCard, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, creditCardAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 60m,
                        At            = new DateTime(2018, 1, 1, 8, 31, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 8, 32, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = rentPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 8, 33, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = rentPrepaymentAccountEntity,
                    DestinationAccount = rentExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var transactionRelationshipService = new TransactionRelationshipService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );

                Transaction creditCardToExpenseTransaction    = transactionService.Get(transactionEntities[1].TransactionId);
                Transaction prepaymentToCreditCardTransaction = transactionService.Get(transactionEntities[2].TransactionId);
                var         newTransactionRelationship        = new TransactionRelationship
                {
                    SourceTransaction      = creditCardToExpenseTransaction,
                    DestinationTransaction = prepaymentToCreditCardTransaction,
                    Type = TransactionRelationshipType.CreditCardPayment
                };
                transactionRelationshipService.Create(newTransactionRelationship);

                List <Entities.TransactionRelationship> transactionRelationshipEntities =
                    sqliteMemoryWrapper.DbContext.TransactionRelationships.ToList();

                Assert.AreEqual(1, transactionRelationshipEntities.Count);
                Assert.AreEqual(newTransactionRelationship.TransactionRelationshipId, transactionRelationshipEntities[0].TransactionRelationshipId);
                Assert.AreEqual(newTransactionRelationship.SourceTransaction.TransactionId, transactionRelationshipEntities[0].SourceTransaction.TransactionId);
                Assert.AreEqual(newTransactionRelationship.DestinationTransaction.TransactionId, transactionRelationshipEntities[0].DestinationTransaction.TransactionId);
                Assert.AreEqual(newTransactionRelationship.Type, transactionRelationshipEntities[0].Type);
            }
        }
示例#22
0
        public void TestBudgetCreateViewModelOK()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var budgetService = new BudgetService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var mockAccountLinkViewModelFactory = new Mock <IAccountLinkViewModelFactory>();
                mockAccountLinkViewModelFactory
                .Setup(f => f.Create(It.IsAny <AccountLink>()))
                .Returns((AccountLink accountLink) =>
                {
                    return(new AccountLinkViewModel(
                               loggerFactory,
                               accountLink));
                });

                var mockBudgetTransactionItemViewModelFactory = new Mock <IBudgetTransactionItemViewModelFactory>();
                mockBudgetTransactionItemViewModelFactory
                .Setup(f => f.Create(
                           It.IsAny <ObservableCollection <IAccountLinkViewModel> >(),
                           It.IsAny <BudgetTransaction>(),
                           It.IsAny <BudgetTransactionType>()))
                .Returns(
                    (ObservableCollection <IAccountLinkViewModel> accountLinks,
                     BudgetTransaction budgetTransaction,
                     BudgetTransactionType type) =>
                {
                    return(new BudgetTransactionItemViewModel(
                               loggerFactory,
                               accountLinks,
                               budgetTransaction,
                               type));
                });

                var mockTransactionListViewModelFactory = new Mock <IBudgetTransactionListViewModelFactory>();
                mockTransactionListViewModelFactory
                .Setup(f => f.Create(It.IsAny <int>()))
                .Returns((int budgetId) =>
                {
                    return(new BudgetTransactionListViewModel(
                               loggerFactory,
                               accountService,
                               budgetService,
                               mockAccountLinkViewModelFactory.Object,
                               mockBudgetTransactionItemViewModelFactory.Object,
                               new Mock <IDeleteConfirmationViewService>().Object,
                               budgetId
                               ));
                });

                var viewModel = new BudgetCreateViewModel(
                    loggerFactory,
                    budgetService,
                    mockTransactionListViewModelFactory.Object
                    );

                viewModel.Name           = "My First Budget";
                viewModel.SelectedPeriod = BudgetPeriod.Monthly;
                viewModel.OKCommand.Execute(this);

                List <Budget> budgets = budgetService.GetAll().ToList();

                Assert.AreEqual(1, budgets.Count);
                Assert.AreEqual(viewModel.Name, budgets[0].Name);
                Assert.AreEqual(viewModel.SelectedPeriod, budgets[0].Period);
                Assert.AreEqual(AccountType.Income, budgets[0].InitialTransaction.CreditAccount.Type);
                Assert.AreEqual(AccountType.Asset, budgets[0].InitialTransaction.DebitAccount.Type);
                Assert.AreEqual(AccountType.Asset, budgets[0].SurplusTransaction.CreditAccount.Type);
                Assert.AreEqual(AccountType.Asset, budgets[0].SurplusTransaction.DebitAccount.Type);
                Assert.AreEqual(0, budgets[0].Transactions.Count());
            }
        }
        public void TestGetPendingCreditCardTransactionsOneResult()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account creditCardAccountEntity =
                    accountFactory.Create(AccountPrefab.CreditCard, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, creditCardAccountEntity);

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var rentPrepaymentToExpenseRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = rentPrepaymentAccountEntity,
                    DestinationAccount = rentExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var transactionsToAdd = new Entities.Transaction[4]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 1)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 50m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 2)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 3)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = rentPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 4)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionsToAdd);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                ILoggerFactory     loggerFactory      = new LoggerFactory();
                TransactionService transactionService = new TransactionService(loggerFactory, sqliteMemoryWrapper.DbContext);

                List <Payment> pendingPayments =
                    transactionService.GetPendingCreditCardPayments(creditCardAccountEntity.AccountId).ToList();

                Assert.AreEqual(1, pendingPayments.Count);
                Assert.AreEqual(creditCardAccountEntity.AccountId, pendingPayments[0].OriginalTransaction.CreditAccount.AccountId);
                Assert.AreEqual(rentExpenseAccountEntity.AccountId, pendingPayments[0].OriginalTransaction.DebitAccount.AccountId);
                Assert.AreEqual(transactionsToAdd[2].Amount, pendingPayments[0].OriginalTransaction.Amount);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, pendingPayments[0].PaymentTransaction.CreditAccount.AccountId);
                Assert.AreEqual(creditCardAccountEntity.AccountId, pendingPayments[0].PaymentTransaction.DebitAccount.AccountId);
                Assert.AreEqual(transactionsToAdd[2].Amount, pendingPayments[0].PaymentTransaction.Amount);
            }
        }
        public void TestBudgetEditViewModelOK()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account savingsAccountEntity =
                    accountFactory.Create(AccountPrefab.Savings, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                Entities.Account groceriesExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesExpense, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, savingsAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesExpenseAccountEntity);

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var rentPrepaymentToExpenseRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = rentPrepaymentAccountEntity,
                    DestinationAccount = rentExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };
                var groceriesPrepaymentToExpenseRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = groceriesPrepaymentAccountEntity,
                    DestinationAccount = groceriesExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(groceriesPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var budget = new Entities.Budget
                {
                    Name   = "Budget",
                    Period = BudgetPeriod.Fortnightly
                };
                sqliteMemoryWrapper.DbContext.Budgets.Add(budget);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var initialTransaction = new Entities.BudgetTransaction
                {
                    CreditAccount = incomeAccountEntity,
                    DebitAccount  = checkingAccountEntity,
                    Amount        = 200m,
                    IsInitial     = true,
                    Budget        = budget
                };
                var rentTransaction = new Entities.BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = rentPrepaymentAccountEntity,
                    Amount        = 100m,
                    Budget        = budget
                };
                var groceriesTransaction = new Entities.BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = groceriesPrepaymentAccountEntity,
                    Amount        = 50m,
                    Budget        = budget
                };
                var surplusTransaction = new Entities.BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = groceriesPrepaymentAccountEntity,
                    IsSurplus     = true,
                    Budget        = budget
                };
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(initialTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(rentTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(groceriesTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(surplusTransaction);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var budgetService = new BudgetService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var mockTransactionItemViewModelFactory = new Mock <IBudgetTransactionItemViewModelFactory>();
                mockTransactionItemViewModelFactory
                .Setup(f => f.Create(
                           It.IsAny <ObservableCollection <IAccountLinkViewModel> >(),
                           It.IsAny <BudgetTransaction>(),
                           It.IsAny <BudgetTransactionType>()))
                .Returns(
                    (ObservableCollection <IAccountLinkViewModel> accountLinks,
                     BudgetTransaction budgetTransaction,
                     BudgetTransactionType type) =>
                {
                    return(new BudgetTransactionItemViewModel(
                               loggerFactory,
                               accountLinks,
                               budgetTransaction,
                               type));
                });

                var mockTransactionListViewModelFactory = new Mock <IBudgetTransactionListViewModelFactory>();
                mockTransactionListViewModelFactory
                .Setup(f => f.Create(It.IsAny <int>()))
                .Returns((int budgetId) =>
                {
                    return(new BudgetTransactionListViewModel(
                               loggerFactory,
                               accountService,
                               budgetService,
                               new Concrete.StubAccountLinkViewModelFactory(),
                               mockTransactionItemViewModelFactory.Object,
                               new Mock <IDeleteConfirmationViewService>().Object,
                               budgetId
                               ));
                });

                var viewModel = new BudgetEditViewModel(
                    loggerFactory,
                    budgetService,
                    mockTransactionListViewModelFactory.Object,
                    budget.BudgetId
                    );

                viewModel.Name           = "My First Budget";
                viewModel.SelectedPeriod = BudgetPeriod.Monthly;
                viewModel.OKCommand.Execute(this);

                List <Budget> budgets = budgetService.GetAll().ToList();

                Assert.AreEqual(1, budgets.Count);
                Assert.AreEqual(viewModel.Name, budgets[0].Name);
                Assert.AreEqual(viewModel.SelectedPeriod, budgets[0].Period);
                Assert.AreEqual(initialTransaction.CreditAccountId, budgets[0].InitialTransaction.CreditAccount.AccountId);
                Assert.AreEqual(initialTransaction.DebitAccountId, budgets[0].InitialTransaction.DebitAccount.AccountId);
                Assert.AreEqual(initialTransaction.Amount, budgets[0].InitialTransaction.Amount);
                Assert.AreEqual(surplusTransaction.CreditAccountId, budgets[0].SurplusTransaction.CreditAccount.AccountId);
                Assert.AreEqual(surplusTransaction.DebitAccountId, budgets[0].SurplusTransaction.DebitAccount.AccountId);
                Assert.AreEqual(surplusTransaction.Amount, budgets[0].SurplusTransaction.Amount);
                Assert.AreEqual(2, budgets[0].Transactions.Count());
            }
        }
示例#25
0
        public void TestCreateTransactionRelationshipInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account creditCardAccountEntity =
                    accountFactory.Create(AccountPrefab.CreditCard, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, creditCardAccountEntity);

                var transactionsToAdd = new Entities.Transaction[4]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 109m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 1)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 50m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 2)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 3)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = rentPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 4)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionsToAdd);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var expenseToPaymentRelationship = new Entities.TransactionRelationship
                {
                    SourceTransaction      = transactionsToAdd[2],
                    DestinationTransaction = transactionsToAdd[2],
                    Type = TransactionRelationshipType.CreditCardPayment
                };

                sqliteMemoryWrapper.DbContext.TransactionRelationships.Add(expenseToPaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                List <Account>                 accounts                 = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Currency>                currencies               = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Transaction>             transactions             = sqliteMemoryWrapper.DbContext.Transactions.ToList();
                List <TransactionRelationship> transactionRelationships = sqliteMemoryWrapper.DbContext.TransactionRelationships.ToList();

                Assert.AreEqual(5, accounts.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(4, transactions.Count);
                Assert.AreEqual(1, transactionRelationships.Count);
                Assert.AreEqual(expenseToPaymentRelationship.SourceTransactionId,
                                transactionRelationships[0].SourceTransactionId);
                Assert.AreEqual(expenseToPaymentRelationship.DestinationTransactionId,
                                transactionRelationships[0].DestinationTransactionId);
                Assert.AreEqual(expenseToPaymentRelationship.Type, transactionRelationships[0].Type);
            }
        }
示例#26
0
        public void TestReloadBudget()
        {
            const string   path          = "TestData/BudgetReload.xml";
            ILoggerFactory loggerFactory = new LoggerFactory();

            var currencyFactory = new CurrencyFactory();

            Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);

            var accountFactory = new AccountFactory();

            Entities.Account incomeAccountEntity =
                accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
            Entities.Account checkingAccountEntity =
                accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
            Entities.Account rentPrepaymentAccountEntity =
                accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
            Entities.Account savingsAccountEntity =
                accountFactory.Create(AccountPrefab.Savings, usdCurrencyEntity);

            var accountRelationship = new Entities.AccountRelationship
            {
                SourceAccount      = checkingAccountEntity,
                DestinationAccount = rentPrepaymentAccountEntity,
                Type = AccountRelationshipType.PhysicalToLogical
            };
            var budget = new Entities.Budget
            {
                Name         = "The Budget",
                Period       = BudgetPeriod.Fortnightly,
                Transactions = new List <Entities.BudgetTransaction>
                {
                    new Entities.BudgetTransaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        IsInitial     = true
                    },
                    new Entities.BudgetTransaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 80m,
                    },
                    new Entities.BudgetTransaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = savingsAccountEntity,
                        Amount        = 100m,
                        IsSurplus     = true
                    }
                }
            };

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, savingsAccountEntity);

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(accountRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                sqliteMemoryWrapper.DbContext.Budgets.Add(budget);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Save(path);
            }

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Load(path);

                List <Entities.Account>             accounts             = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <Entities.AccountRelationship> accountRelationships = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();
                List <Entities.Budget>            budgets            = sqliteMemoryWrapper.DbContext.Budgets.ToList();
                List <Entities.BudgetTransaction> budgetTransactions = sqliteMemoryWrapper.DbContext.BudgetTransactions.ToList();
                List <Entities.Currency>          currencies         = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Entities.Transaction>       transactions       = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(4, accounts.Count);
                Assert.AreEqual(1, accountRelationships.Count);
                Assert.AreEqual(1, budgets.Count);
                Assert.AreEqual(3, budgetTransactions.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);

                Assert.AreEqual(budget.Name, budgets[0].Name);
                Assert.AreEqual(budget.Period, budgets[0].Period);

                Entities.BudgetTransaction initialTransaction = budgetTransactions.First(bt => bt.IsInitial && !bt.IsSurplus);
                Entities.BudgetTransaction regularTransaction = budgetTransactions.First(bt => !bt.IsInitial && !bt.IsSurplus);
                Entities.BudgetTransaction surplusTransaction = budgetTransactions.First(bt => !bt.IsInitial && bt.IsSurplus);
                Assert.AreEqual(budget.Transactions[0].DebitAccount.Name, initialTransaction.DebitAccount.Name);
                Assert.AreEqual(budget.Transactions[0].CreditAccount.Name, initialTransaction.CreditAccount.Name);
                Assert.AreEqual(budget.Transactions[0].Amount, initialTransaction.Amount);
                Assert.AreEqual(budget.Transactions[0].IsInitial, initialTransaction.IsInitial);
                Assert.AreEqual(budget.Transactions[0].IsSurplus, initialTransaction.IsSurplus);
                Assert.AreEqual(budget.Transactions[1].DebitAccount.Name, regularTransaction.DebitAccount.Name);
                Assert.AreEqual(budget.Transactions[1].CreditAccount.Name, regularTransaction.CreditAccount.Name);
                Assert.AreEqual(budget.Transactions[1].Amount, regularTransaction.Amount);
                Assert.AreEqual(budget.Transactions[1].IsInitial, regularTransaction.IsInitial);
                Assert.AreEqual(budget.Transactions[1].IsSurplus, regularTransaction.IsSurplus);
                Assert.AreEqual(budget.Transactions[2].DebitAccount.Name, surplusTransaction.DebitAccount.Name);
                Assert.AreEqual(budget.Transactions[2].CreditAccount.Name, surplusTransaction.CreditAccount.Name);
                Assert.AreEqual(budget.Transactions[2].Amount, surplusTransaction.Amount);
                Assert.AreEqual(budget.Transactions[2].IsInitial, surplusTransaction.IsInitial);
                Assert.AreEqual(budget.Transactions[2].IsSurplus, surplusTransaction.IsSurplus);
            }
        }
示例#27
0
        public void TestCreateBudgetInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account savingsAccountEntity =
                    accountFactory.Create(AccountPrefab.Savings, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                Entities.Account groceriesExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesExpense, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, savingsAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesExpenseAccountEntity);

                var checkingToRentPrepaymentRelationship = new AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToGroceriesPrepaymentRelationship = new AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var rentPrepaymentToExpenseRelationship = new AccountRelationship
                {
                    SourceAccount      = rentPrepaymentAccountEntity,
                    DestinationAccount = rentExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };
                var groceriesPrepaymentToExpenseRelationship = new AccountRelationship
                {
                    SourceAccount      = groceriesPrepaymentAccountEntity,
                    DestinationAccount = groceriesExpenseAccountEntity,
                    Type = AccountRelationshipType.PrepaymentToExpense
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(groceriesPrepaymentToExpenseRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var budget = new Budget
                {
                    Name   = "Budget",
                    Period = BudgetPeriod.Fortnightly
                };
                sqliteMemoryWrapper.DbContext.Budgets.Add(budget);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var initialTransaction = new BudgetTransaction
                {
                    CreditAccount = incomeAccountEntity,
                    DebitAccount  = checkingAccountEntity,
                    Amount        = 200m,
                    IsInitial     = true,
                    Budget        = budget
                };
                var rentTransaction = new BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = rentPrepaymentAccountEntity,
                    Amount        = 100m,
                    Budget        = budget
                };
                var groceriesTransaction = new BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = groceriesPrepaymentAccountEntity,
                    Amount        = 50m,
                    Budget        = budget
                };
                var surplusTransaction = new BudgetTransaction
                {
                    CreditAccount = checkingAccountEntity,
                    DebitAccount  = groceriesPrepaymentAccountEntity,
                    IsSurplus     = true,
                    Budget        = budget
                };
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(initialTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(rentTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(groceriesTransaction);
                sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(surplusTransaction);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                List <Account>             accounts            = sqliteMemoryWrapper.DbContext.Accounts.ToList();
                List <AccountRelationship> accountRelationsips = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList();
                List <Budget>            budgets            = sqliteMemoryWrapper.DbContext.Budgets.ToList();
                List <BudgetTransaction> budgetTransactions = sqliteMemoryWrapper.DbContext.BudgetTransactions.ToList();
                List <Currency>          currencies         = sqliteMemoryWrapper.DbContext.Currencies.ToList();
                List <Transaction>       transactions       = sqliteMemoryWrapper.DbContext.Transactions.ToList();

                Assert.AreEqual(7, accounts.Count);
                Assert.AreEqual(4, accountRelationsips.Count);
                Assert.AreEqual(1, budgets.Count);
                Assert.AreEqual(4, budgetTransactions.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);

                Assert.AreEqual(budget.Name, budgets[0].Name);
                Assert.AreEqual(budget.Period, budgets[0].Period);
                Assert.AreEqual(budgetTransactions.Count, budgets[0].Transactions.Count);
            }
        }
        public void TestGenerateCashflowStatementMultiplePeriodsMultipleAccounts()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account creditCardAccountEntity =
                    accountFactory.Create(AccountPrefab.CreditCard, usdCurrencyEntity);
                Entities.Account rentExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account groceriesExpenseAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesExpense, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);

                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, creditCardAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesExpenseAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 50m,
                        At            = new DateTime(2018, 1, 2, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = groceriesPrepaymentAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 3, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 5m,
                        At            = new DateTime(2018, 1, 4, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 8m,
                        At            = new DateTime(2018, 1, 5, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 3m,
                        At            = new DateTime(2018, 1, 6, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 5m,
                        At            = new DateTime(2018, 1, 7, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 8m,
                        At            = new DateTime(2018, 1, 8, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 3m,
                        At            = new DateTime(2018, 1, 9, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 80m,
                        At            = new DateTime(2018, 1, 14, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 50m,
                        At            = new DateTime(2018, 1, 15, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = groceriesPrepaymentAccountEntity,
                        Amount        = 20m,
                        At            = new DateTime(2018, 1, 16, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 3m,
                        At            = new DateTime(2018, 1, 17, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 7m,
                        At            = new DateTime(2018, 1, 18, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 12m,
                        At            = new DateTime(2018, 1, 19, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 3m,
                        At            = new DateTime(2018, 1, 20, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 7m,
                        At            = new DateTime(2018, 1, 21, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = groceriesPrepaymentAccountEntity,
                        DebitAccount  = creditCardAccountEntity,
                        Amount        = 12m,
                        At            = new DateTime(2018, 1, 22, 9, 0, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = rentPrepaymentAccountEntity,
                        DebitAccount  = rentExpenseAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 27, 9, 0, 0)
                    },
                    new Entities.Transaction // this should be excluded from the report
                    {
                        CreditAccount = creditCardAccountEntity,
                        DebitAccount  = groceriesExpenseAccountEntity,
                        Amount        = 7m,
                        At            = new DateTime(2018, 1, 31, 9, 0, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountRelationshipEntities = new Entities.AccountRelationship[]
                {
                    new Entities.AccountRelationship
                    {
                        SourceAccount      = checkingAccountEntity,
                        DestinationAccount = rentPrepaymentAccountEntity,
                        Type = AccountRelationshipType.PhysicalToLogical
                    },
                    new Entities.AccountRelationship
                    {
                        SourceAccount      = checkingAccountEntity,
                        DestinationAccount = groceriesPrepaymentAccountEntity,
                        Type = AccountRelationshipType.PhysicalToLogical
                    },
                    new Entities.AccountRelationship
                    {
                        SourceAccount      = rentPrepaymentAccountEntity,
                        DestinationAccount = rentExpenseAccountEntity,
                        Type = AccountRelationshipType.PrepaymentToExpense
                    },
                    new Entities.AccountRelationship
                    {
                        SourceAccount      = groceriesPrepaymentAccountEntity,
                        DestinationAccount = groceriesExpenseAccountEntity,
                        Type = AccountRelationshipType.PrepaymentToExpense
                    }
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.AddRange(accountRelationshipEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountRelationshipService = new AccountRelationshipService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var currencyService = new CurrencyService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext
                    );
                var cashflowService = new CashflowService(
                    loggerFactory,
                    accountRelationshipService,
                    accountService,
                    currencyService,
                    transactionService
                    );

                CashflowStatement cashflowStatement =
                    cashflowService.Generate(CashflowPeriod.Fortnightly, new DateTime(2018, 1, 1), new DateTime(2018, 1, 28));
                List <CashflowAccount> cashflowAccounts =
                    cashflowStatement
                    .Accounts
                    .OrderBy(i => i.Name)
                    .ToList();

                Assert.AreEqual(2, cashflowAccounts.Count);
                Assert.AreEqual("Groceries", cashflowAccounts[0].Name);
                Assert.AreEqual(2, cashflowAccounts[0].Periods.Count());
                Assert.AreEqual(20m, cashflowAccounts[0].Periods.ElementAt(0).Inflow);
                Assert.AreEqual(16m, cashflowAccounts[0].Periods.ElementAt(0).Outflow);
                Assert.AreEqual(4m, cashflowAccounts[0].Periods.ElementAt(0).Cashflow);
                Assert.AreEqual(20m, cashflowAccounts[0].Periods.ElementAt(1).Inflow);
                Assert.AreEqual(22m, cashflowAccounts[0].Periods.ElementAt(1).Outflow);
                Assert.AreEqual(-2m, cashflowAccounts[0].Periods.ElementAt(1).Cashflow);
                Assert.AreEqual(40m, cashflowAccounts[0].Inflow);
                Assert.AreEqual(38m, cashflowAccounts[0].Outflow);
                Assert.AreEqual(2m, cashflowAccounts[0].Cashflow);
                Assert.AreEqual("Rent", cashflowAccounts[1].Name);
                Assert.AreEqual(2, cashflowAccounts[1].Periods.Count());
                Assert.AreEqual(50m, cashflowAccounts[1].Periods.ElementAt(0).Inflow);
                Assert.AreEqual(0m, cashflowAccounts[1].Periods.ElementAt(0).Outflow);
                Assert.AreEqual(50m, cashflowAccounts[1].Periods.ElementAt(0).Cashflow);
                Assert.AreEqual(50m, cashflowAccounts[1].Periods.ElementAt(1).Inflow);
                Assert.AreEqual(100m, cashflowAccounts[1].Periods.ElementAt(1).Outflow);
                Assert.AreEqual(-50m, cashflowAccounts[1].Periods.ElementAt(1).Cashflow);
                Assert.AreEqual(100m, cashflowAccounts[1].Inflow);
                Assert.AreEqual(100m, cashflowAccounts[1].Outflow);
                Assert.AreEqual(0m, cashflowAccounts[1].Cashflow);
            }
        }
示例#29
0
        public void TestReconcileBalance()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity   = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var currencyService = new CurrencyService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var viewModel = new ReconcileBalanceViewModel(
                    loggerFactory,
                    accountService,
                    currencyService,
                    transactionService,
                    new Concrete.StubAccountLinkViewModelFactory(),
                    new Mock <IForeignAmountViewService>().Object,
                    checkingAccountEntity.AccountId);
                viewModel.Balance = 140m;
                viewModel.At      = new DateTime(2018, 1, 2, 7, 0, 0);
                viewModel.OKCommand.Execute(null);
                Transaction newTransaction = viewModel.ToTransaction();

                Assert.AreEqual(1, viewModel.Accounts.Count);
                Assert.AreEqual(40m, newTransaction.Amount);
                Assert.AreEqual(incomeAccountEntity.AccountId, newTransaction.CreditAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.AccountId, newTransaction.DebitAccount.AccountId);
                Assert.AreEqual(viewModel.At, newTransaction.At);
            }
        }
示例#30
0
        public void TestAccountTransactionListViewModelAccountWithLogicalsAndTransactions()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountFactory = new AccountFactory();
                Entities.Account incomeAccountEntity =
                    accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity);
                Entities.Account checkingAccountEntity =
                    accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity);
                Entities.Account rentPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);
                Entities.Account groceriesPrepaymentAccountEntity =
                    accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity);
                accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity);

                var transactionEntities = new Entities.Transaction[]
                {
                    new Entities.Transaction
                    {
                        CreditAccount = incomeAccountEntity,
                        DebitAccount  = checkingAccountEntity,
                        Amount        = 100m,
                        At            = new DateTime(2018, 1, 1, 8, 30, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = rentPrepaymentAccountEntity,
                        Amount        = 60m,
                        At            = new DateTime(2018, 1, 1, 8, 31, 0)
                    },
                    new Entities.Transaction
                    {
                        CreditAccount = checkingAccountEntity,
                        DebitAccount  = groceriesPrepaymentAccountEntity,
                        Amount        = 10m,
                        At            = new DateTime(2018, 1, 1, 8, 32, 0)
                    }
                };

                sqliteMemoryWrapper.DbContext.Transactions.AddRange(transactionEntities);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = rentPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };
                var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship
                {
                    SourceAccount      = checkingAccountEntity,
                    DestinationAccount = groceriesPrepaymentAccountEntity,
                    Type = AccountRelationshipType.PhysicalToLogical
                };

                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship);
                sqliteMemoryWrapper.DbContext.SaveChanges();

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var transactionService = new TransactionService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);


                IAccountTransactionItemViewModelFactory accountTransactionViewModelFactory =
                    new Concrete.StubAccountTransactionItemViewModelFactory();

                var viewModel = new AccountTransactionListViewModel(
                    loggerFactory,
                    accountService,
                    transactionService,
                    accountTransactionViewModelFactory,
                    new Mock <IDeleteConfirmationViewService>().Object,
                    new Mock <ITransactionCreateViewService>().Object,
                    new Mock <ITransactionEditViewService>().Object,
                    new Mock <IReconcileBalanceViewService>().Object,
                    checkingAccountEntity.AccountId);

                Assert.AreEqual(true, viewModel.HasLogicalAcounts);
                Assert.AreEqual(3, viewModel.Transactions.Count);
                Assert.AreEqual(100m, viewModel.Transactions[0].Balance);
                Assert.AreEqual(100m, viewModel.Transactions[1].Balance);
                Assert.AreEqual(100m, viewModel.Transactions[2].Balance);
            }
        }