public void TestAccountCreateViewModelCancel()
        {
            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 accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

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

                var viewModel = new AccountCreateViewModel(
                    loggerFactory,
                    accountService,
                    currencyService
                    );

                viewModel.Name = "MyAccount";
                viewModel.SelectedAccountType    = AccountType.Asset;
                viewModel.SelectedAccountSubType = AccountSubType.Investment;
                viewModel.CancelCommand.Execute(this);

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

                Assert.AreEqual(0, accounts.Count);
            }
        }
Exemplo n.º 2
0
        public void TestBalanceSheetNoAccounts()
        {
            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 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));

                Assert.AreEqual(usdCurrencyEntity.Symbol, balanceSheet.CurrencySymbol);
                Assert.AreEqual(0, balanceSheet.TotalAssets);
                Assert.AreEqual(0, balanceSheet.TotalLiabilities);
                Assert.AreEqual(0, balanceSheet.Assets.Count());
                Assert.AreEqual(0, balanceSheet.Liabilities.Count());
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public void TestGetAllManyCurrencies()
        {
            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             currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext);
                List <Currency> currencies      = currencyService.GetAll().ToList();

                Assert.AreEqual(2, currencies.Count);
                Assert.AreEqual(usdCurrencyEntity.Name, currencies[0].Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, currencies[0].ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, currencies[0].Symbol);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, currencies[0].IsPrimary);
                Assert.AreEqual(gbpCurrencyEntity.Name, currencies[1].Name);
                Assert.AreEqual(gbpCurrencyEntity.ShortName, currencies[1].ShortName);
                Assert.AreEqual(gbpCurrencyEntity.Symbol, currencies[1].Symbol);
                Assert.AreEqual(gbpCurrencyEntity.IsPrimary, currencies[1].IsPrimary);
            }
        }
Exemplo n.º 5
0
        public void TestBudgetCreateViewModelCancel()
        {
            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 budgetService = new BudgetService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var viewModel = new BudgetCreateViewModel(
                    loggerFactory,
                    budgetService,
                    new Mock <IBudgetTransactionListViewModelFactory>().Object
                    );

                viewModel.Name = "My First Budget";
                viewModel.CancelCommand.Execute(this);

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

                Assert.AreEqual(0, budgets.Count);
            }
        }
        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);
            }
        }
        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);
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 12
0
        private void TestLoadFailure(string path)
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Load(path);
            }
        }
Exemplo n.º 13
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 TestGetAccountRelationshipInvalidId()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

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

                accountRelationshipService.Get(666);
            }
        }
        public void TestTransactionDeleteFailInvalidId()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

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

                transactionService.Delete(666);
            }
        }
        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);
            }
        }
Exemplo n.º 17
0
        public void TestGetAllNoCurrencies()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext);
                IEnumerable <Currency> currencies = currencyService.GetAll();

                Assert.AreEqual(0, currencies.Count());
            }
        }
Exemplo n.º 18
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);
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
 public void TestCreateInMemoryInDbContext()
 {
     using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
     {
         FinancierDbContext dbContext = sqliteMemoryWrapper.DbContext;
         Assert.AreEqual(0, dbContext.Accounts.Count());
         Assert.AreEqual(0, dbContext.AccountRelationships.Count());
         Assert.AreEqual(0, dbContext.Budgets.Count());
         Assert.AreEqual(0, dbContext.BudgetTransactions.Count());
         Assert.AreEqual(0, dbContext.Currencies.Count());
         Assert.AreEqual(0, dbContext.Transactions.Count());
         Assert.AreEqual(0, dbContext.TransactionRelationships.Count());
     }
 }
        public void TestAccountEditViewModelOK()
        {
            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 accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

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

                Currency primaryCurrency = currencyService.GetPrimary();
                var      account         = new Account
                {
                    Name     = "My First Account",
                    Type     = AccountType.Asset,
                    SubType  = AccountSubType.Checking,
                    Currency = primaryCurrency,
                };
                accountService.Create(account);

                var viewModel = new AccountEditViewModel(
                    loggerFactory,
                    accountService,
                    currencyService,
                    account.AccountId
                    );

                viewModel.Name = "Updated Account";
                viewModel.SelectedAccountType    = AccountType.Liability;
                viewModel.SelectedAccountSubType = AccountSubType.CreditCard;
                viewModel.OKCommand.Execute(this);

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

                Assert.AreEqual(1, accounts.Count);
                Assert.AreEqual(viewModel.Name, accounts[0].Name);
                Assert.AreEqual(viewModel.SelectedAccountType, accounts[0].Type);
                Assert.AreEqual(viewModel.SelectedAccountSubType, accounts[0].SubType);
                Assert.AreEqual(account.Currency.CurrencyId, accounts[0].Currency.CurrencyId);
            }
        }
Exemplo n.º 22
0
        public void TestSaveEmpty()
        {
            const string   path          = "TestData/EmptySaved.xml";
            ILoggerFactory loggerFactory = new LoggerFactory();

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

            XDocument document = XDocument.Load(path);

            Assert.AreEqual(0, document.Root.DescendantNodes().Count());
        }
Exemplo n.º 23
0
        public void TestGetPrimaryFailsWithMultiplePrimaries()
        {
            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, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, gbpCurrencyEntity);

                var      currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext);
                Currency primaryCurrency = currencyService.GetPrimary();
            }
        }
        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);
            }
        }
Exemplo n.º 25
0
        public void TestCreateCurrencyInDbContext()
        {
            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory = new CurrencyFactory();
                Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

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

                Assert.AreEqual(0, accounts.Count);
                Assert.AreEqual(1, currencies.Count);
                Assert.AreEqual(0, transactions.Count);
            }
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
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);
            }
        }
Exemplo n.º 28
0
        public void TestGetPrimaryValid()
        {
            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      currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext);
                Currency primaryCurrency = currencyService.GetPrimary();

                Assert.AreEqual(usdCurrencyEntity.Name, primaryCurrency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, primaryCurrency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, primaryCurrency.Symbol);
                Assert.AreEqual(true, primaryCurrency.IsPrimary);
            }
        }
Exemplo n.º 29
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);
            }
        }
Exemplo n.º 30
0
        public void TestCreateAccount()
        {
            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 accountService = new AccountService(loggerFactory, sqliteMemoryWrapper.DbContext);

                var account = new Account
                {
                    Name     = "Checking",
                    Type     = AccountType.Asset,
                    Currency = new Currency
                    {
                        CurrencyId = usdCurrencyEntity.CurrencyId,
                        Name       = usdCurrencyEntity.Name,
                        ShortName  = usdCurrencyEntity.ShortName,
                        Symbol     = usdCurrencyEntity.Symbol,
                        IsPrimary  = usdCurrencyEntity.IsPrimary
                    }
                };
                accountService.Create(account);

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

                Assert.AreEqual(1, accountEntities.Count);
                Assert.AreEqual(account.Name, accountEntities[0].Name);
                Assert.AreEqual(AccountType.Asset, accountEntities[0].Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, accountEntities[0].Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, accountEntities[0].Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, accountEntities[0].Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accountEntities[0].Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, accountEntities[0].Currency.Symbol);
            }
        }