Exemplo n.º 1
0
        public void Create()
        {
            m_dbContext.Database.EnsureCreated();
            m_logger.LogInformation("Database is created");

            if (!m_dbContext.Currencies.Any())
            {
                var dollar = new Entities.Currency
                {
                    Name      = "US Dollar",
                    ShortName = "USD",
                    Symbol    = "$",
                    IsPrimary = true
                };
                m_dbContext.Currencies.Add(dollar);
                var sterling = new Entities.Currency
                {
                    Name      = "UK Sterling",
                    ShortName = "GBP",
                    Symbol    = "£",
                    IsPrimary = false
                };
                m_dbContext.Currencies.Add(sterling);
                m_dbContext.SaveChanges();

                m_logger.LogInformation("Populated database with default currencies");
            }
        }
Exemplo n.º 2
0
		private void OnCurrencyBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentCurrency = uxCurrencyBindingSource.Current as Entities.Currency;
			
			if (_currentCurrency != null)
			{
				_currentCurrency.Validate();
			}
			//_Currency.Validate();
			OnCurrentEntityChanged();
		}
Exemplo n.º 3
0
 private static Currency FromEntity(Entities.Currency currencyEntity)
 {
     return(new Currency
     {
         CurrencyId = currencyEntity.CurrencyId,
         IsPrimary = currencyEntity.IsPrimary,
         Name = currencyEntity.Name,
         ShortName = currencyEntity.ShortName,
         Symbol = currencyEntity.Symbol
     });
 }
        private static XElement ElementFromCurrency(Entities.Currency currency)
        {
            var element = new XElement(XName.Get("Currency"),
                                       new XAttribute(XName.Get("name"), currency.Name),
                                       new XAttribute(XName.Get("shortName"), currency.ShortName),
                                       new XAttribute(XName.Get("symbol"), currency.Symbol),
                                       new XAttribute(XName.Get("isPrimary"), currency.IsPrimary)
                                       );

            return(element);
        }
        private void OnCurrencyBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
        {
            _currentCurrency = uxCurrencyBindingSource.Current as Entities.Currency;

            if (_currentCurrency != null)
            {
                _currentCurrency.Validate();
            }
            //_Currency.Validate();
            OnCurrentEntityChanged();
        }
        private static Entities.Currency CurrencyFromElement(XElement element)
        {
            var currency = new Entities.Currency
            {
                Name      = GetRequiredAttribute(element, "name").Value,
                ShortName = GetRequiredAttribute(element, "shortName").Value,
                Symbol    = GetRequiredAttribute(element, "symbol").Value,
                IsPrimary = Boolean.Parse(GetRequiredAttribute(element, "isPrimary").Value)
            };

            return(currency);
        }
Exemplo n.º 7
0
        public Entities.Currency Create(CurrencyPrefab prefab, bool isPrimary)
        {
            var currencyEntity = new Entities.Currency
            {
                Name      = m_entitiesByPrefab[prefab].Name,
                ShortName = m_entitiesByPrefab[prefab].ShortName,
                Symbol    = m_entitiesByPrefab[prefab].Symbol,
                IsPrimary = isPrimary
            };

            return(currencyEntity);
        }
Exemplo n.º 8
0
        public Entities.Account Create(AccountPrefab prefab, Entities.Currency currencyEntity)
        {
            var accountEntity = new Entities.Account
            {
                Currency = currencyEntity,
                Name     = m_entitiesByPrefab[prefab].Name,
                Type     = m_entitiesByPrefab[prefab].Type,
                SubType  = m_entitiesByPrefab[prefab].SubType
            };

            return(accountEntity);
        }
Exemplo n.º 9
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);
            }
        }
        public double GetRate(Entities.Currency source, Entities.Currency target)
        {
            if (myClient == null)
            {
                myClient = new CurrencyConvertorSoapClient(new BasicHttpBinding(), new EndpointAddress("http://www.webservicex.net/CurrencyConvertor.asmx"));
            }

            var sourceCurrency = (CurrencyConverter.Currency)Enum.Parse(typeof(CurrencyConverter.Currency), source.Symbol);
            var targetCurrency = (CurrencyConverter.Currency)Enum.Parse(typeof(CurrencyConverter.Currency), target.Symbol);

            var rate = myClient.ConversionRate(sourceCurrency, targetCurrency);

            return(rate);
        }
Exemplo n.º 11
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.º 12
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.º 13
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);
            }
        }
Exemplo n.º 14
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 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());
            }
        }
Exemplo n.º 16
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);
            }
        }
Exemplo n.º 17
0
        public void TestReloadTransaction()
        {
            const string   path          = "TestData/TransactionReload.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);
            Entities.Account rentPrepaymentAccountEntity =
                accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity);

            var accountRelationship = new Entities.AccountRelationship
            {
                SourceAccount      = checkingAccountEntity,
                DestinationAccount = rentPrepaymentAccountEntity,
                Type = AccountRelationshipType.PhysicalToLogical
            };
            var transaction = new Entities.Transaction
            {
                CreditAccount = checkingAccountEntity,
                Amount        = 10m,
                DebitAccount  = rentPrepaymentAccountEntity,
                At            = new DateTime(2018, 1, 1, 8, 30, 0)
            };

            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();

                sqliteMemoryWrapper.DbContext.Transactions.Add(transaction);
                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(1, transactions.Count);

                Assert.AreEqual(checkingAccountEntity.Name, transactions[0].CreditAccount.Name);
                Assert.AreEqual(transaction.Amount, transactions[0].Amount);
                Assert.AreEqual(rentPrepaymentAccountEntity.Name, transactions[0].DebitAccount.Name);
                Assert.AreEqual(transaction.At, transactions[0].At);
            }
        }
Exemplo n.º 18
0
        public void TestLoadValid()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var service = new DatabaseSerializationXmlService(loggerFactory, sqliteMemoryWrapper.DbContext);
                service.Load("TestData/Valid.xml");

                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();
                List <Entities.TransactionRelationship> transactionRelationships = sqliteMemoryWrapper.DbContext.TransactionRelationships.ToList();

                Assert.AreEqual(6, accounts.Count);
                Assert.AreEqual(2, accountRelationships.Count);
                Assert.AreEqual(2, budgets.Count);
                Assert.AreEqual(5, budgetTransactions.Count);
                Assert.AreEqual(2, currencies.Count);
                Assert.AreEqual(4, transactions.Count);
                Assert.AreEqual(1, transactionRelationships.Count);

                Entities.Currency usdCurrency = currencies.Single(c => c.Name == "US Dollar");
                Assert.AreEqual("US Dollar", usdCurrency.Name);
                Assert.AreEqual("USD", usdCurrency.ShortName);
                Assert.AreEqual("$", usdCurrency.Symbol);

                Entities.Currency gbpCurrency = currencies.Single(c => c.Name == "UK Sterling");
                Assert.AreEqual("UK Sterling", gbpCurrency.Name);
                Assert.AreEqual("GBP", gbpCurrency.ShortName);
                Assert.AreEqual("£", gbpCurrency.Symbol);

                Entities.Account checkingAccount = accounts.Single(c => c.Name == "Checking");
                Assert.AreEqual("Checking", checkingAccount.Name);
                Assert.AreEqual("USD", checkingAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Asset, checkingAccount.Type);
                Assert.AreEqual(AccountSubType.Checking, checkingAccount.SubType);

                Entities.Account savingsAccount = accounts.Single(c => c.Name == "Savings");
                Assert.AreEqual("Savings", savingsAccount.Name);
                Assert.AreEqual("USD", savingsAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Asset, savingsAccount.Type);
                Assert.AreEqual(AccountSubType.None, savingsAccount.SubType);

                Entities.Account incomeAccount = accounts.Single(c => c.Name == "Income");
                Assert.AreEqual("Income", incomeAccount.Name);
                Assert.AreEqual("USD", incomeAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Income, incomeAccount.Type);
                Assert.AreEqual(AccountSubType.None, incomeAccount.SubType);

                Entities.Account creditCardAccount = accounts.Single(c => c.Name == "Credit Card");
                Assert.AreEqual("Credit Card", creditCardAccount.Name);
                Assert.AreEqual("USD", creditCardAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Liability, creditCardAccount.Type);
                Assert.AreEqual(AccountSubType.CreditCard, creditCardAccount.SubType);

                Entities.Account rentPrepaymentAccount = accounts.Single(c => c.Name == "Rent Prepayment");
                Assert.AreEqual("Rent Prepayment", rentPrepaymentAccount.Name);
                Assert.AreEqual("USD", rentPrepaymentAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Asset, rentPrepaymentAccount.Type);
                Assert.AreEqual(AccountSubType.None, rentPrepaymentAccount.SubType);

                Entities.Account rentExpenseAccount = accounts.Single(c => c.Name == "Rent Expense");
                Assert.AreEqual("Rent Expense", rentExpenseAccount.Name);
                Assert.AreEqual("USD", rentExpenseAccount.Currency.ShortName);
                Assert.AreEqual(AccountType.Expense, rentExpenseAccount.Type);
                Assert.AreEqual(AccountSubType.None, rentExpenseAccount.SubType);

                // TODO: check the data in a way that is not order dependent

                //Assert.AreEqual("Checking", accountRelationships[0].SourceAccount.Name);
                //Assert.AreEqual("Rent Prepayment", accountRelationships[0].DestinationAccount.Name);
                //Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationships[0].Type);

                //Assert.AreEqual("Rent Prepayment", accountRelationships[1].SourceAccount.Name);
                //Assert.AreEqual("Rent Expense", accountRelationships[1].DestinationAccount.Name);
                //Assert.AreEqual(AccountRelationshipType.PrepaymentToExpense, accountRelationships[1].Type);

                //Assert.AreEqual("Income", transactions[0].CreditAccount.Name);
                //Assert.AreEqual(100m, transactions[0].Amount);
                //Assert.AreEqual("Checking", transactions[0].DebitAccount.Name);
                //Assert.AreEqual(new DateTime(2018, 1, 1, 9, 0, 0), transactions[0].At);

                //Assert.AreEqual("Checking", transactions[1].CreditAccount.Name);
                //Assert.AreEqual(50m, transactions[1].Amount);
                //Assert.AreEqual("Rent Prepayment", transactions[1].DebitAccount.Name);
                //Assert.AreEqual(new DateTime(2018, 1, 2, 8, 30, 0), transactions[1].At);

                //Assert.AreEqual("Credit Card", transactions[2].CreditAccount.Name);
                //Assert.AreEqual(30m, transactions[2].Amount);
                //Assert.AreEqual("Rent Expense", transactions[2].DebitAccount.Name);
                //Assert.AreEqual(new DateTime(2018, 1, 3, 8, 30, 0), transactions[2].At);

                //Assert.AreEqual("Rent Prepayment", transactions[3].CreditAccount.Name);
                //Assert.AreEqual(30m, transactions[3].Amount);
                //Assert.AreEqual("Credit Card", transactions[3].DebitAccount.Name);
                //Assert.AreEqual(new DateTime(2018, 1, 4, 8, 30, 0), transactions[3].At);

                //Assert.AreEqual(transactions[2].TransactionId, transactionRelationships[0].SourceTransactionId);
                //Assert.AreEqual(transactions[3].TransactionId, transactionRelationships[0].DestinationTransactionId);
                //Assert.AreEqual(TransactionRelationshipType.CreditCardPayment, transactionRelationships[0].Type);

                //Assert.AreEqual("The Budget", budgets[0].Name);
                //Assert.AreEqual(BudgetPeriod.Fortnightly, budgets[0].Period);

                //Assert.AreEqual("Income", budgetTransactions[0].CreditAccount.Name);
                //Assert.AreEqual(100m, budgetTransactions[0].Amount);
                //Assert.AreEqual("Checking", budgetTransactions[0].DebitAccount.Name);
                //Assert.AreEqual(true, budgetTransactions[0].IsInitial);
                //Assert.AreEqual(false, budgetTransactions[0].IsSurplus);
                //Assert.AreEqual(budgets[0].BudgetId, budgetTransactions[0].BudgetId);
                //Assert.AreEqual("Checking", budgetTransactions[1].CreditAccount.Name);
                //Assert.AreEqual(80m, budgetTransactions[1].Amount);
                //Assert.AreEqual("Rent Prepayment", budgetTransactions[1].DebitAccount.Name);
                //Assert.AreEqual(false, budgetTransactions[1].IsInitial);
                //Assert.AreEqual(false, budgetTransactions[1].IsSurplus);
                //Assert.AreEqual(budgets[0].BudgetId, budgetTransactions[1].BudgetId);
                //Assert.AreEqual("Checking", budgetTransactions[2].CreditAccount.Name);
                //Assert.AreEqual(0m, budgetTransactions[2].Amount);
                //Assert.AreEqual("Savings", budgetTransactions[2].DebitAccount.Name);
                //Assert.AreEqual(false, budgetTransactions[2].IsInitial);
                //Assert.AreEqual(true, budgetTransactions[2].IsSurplus);
                //Assert.AreEqual(budgets[0].BudgetId, budgetTransactions[2].BudgetId);

                //Assert.AreEqual("Another Budget", budgets[1].Name);
                //Assert.AreEqual(BudgetPeriod.Weekly, budgets[1].Period);

                //Assert.AreEqual("Income", budgetTransactions[3].CreditAccount.Name);
                //Assert.AreEqual(50m, budgetTransactions[3].Amount);
                //Assert.AreEqual("Checking", budgetTransactions[3].DebitAccount.Name);
                //Assert.AreEqual(true, budgetTransactions[3].IsInitial);
                //Assert.AreEqual(false, budgetTransactions[3].IsSurplus);
                //Assert.AreEqual(budgets[1].BudgetId, budgetTransactions[3].BudgetId);
                //Assert.AreEqual("Checking", budgetTransactions[4].CreditAccount.Name);
                //Assert.AreEqual(0m, budgetTransactions[4].Amount);
                //Assert.AreEqual("Savings", budgetTransactions[4].DebitAccount.Name);
                //Assert.AreEqual(false, budgetTransactions[4].IsInitial);
                //Assert.AreEqual(true, budgetTransactions[4].IsSurplus);
                //Assert.AreEqual(budgets[1].BudgetId, budgetTransactions[4].BudgetId);
            }
        }
Exemplo n.º 19
0
 public void Add(FinancierDbContext dbContext, Entities.Currency currencyEntity)
 {
     dbContext.Currencies.Add(currencyEntity);
     dbContext.SaveChanges();
 }
Exemplo n.º 20
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);
            }
        }
        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);
            }
        }