Ejemplo n.º 1
0
        public void Transfer_Amount_Test()
        {
            var repo = new FileRepository(".");
            var accountFactoryMock = new Mock <IAccountFactory>();
            var accountFactory     = new AccountFactory();

            repo.Save(accountFactory.Create(1, 2000));
            repo.Save(accountFactory.Create(2, 3000));
            var     consoleMock = new Mock <IShell>();
            var     repoMock    = new Mock <IRepository>();
            var     accId       = 0;
            decimal balance     = 0;

            repoMock.Setup(r => r.Save(It.IsAny <IAccount>()))
            .Callback <IAccount>(a => (accId, balance) = (a.AccountId, a.Balance));
            consoleMock.SetupSequence(c => c.ReadLine())
            .Returns("4");
            Options.Show(consoleMock.Object);
            consoleMock.SetupSequence(c => c.ReadLine())
            .Returns("1")
            .Returns("2")
            .Returns("1000");
            var viewFactory = new ViewFactory(consoleMock.Object, repoMock.Object, accountFactoryMock.Object);
            var myview      = viewFactory.Create(4);

            myview.Show();
            Assert.Equal(2, accId);
            Assert.Equal(4000, balance);
        }
        public void TestCreateManyTransactions()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

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

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

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

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

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

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

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

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

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

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

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

                Assert.AreEqual(2, accountRelationships.Count);
                Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationships[0].Type);
                Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationships[0].SourceAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accountRelationships[0].SourceAccount.Name);
                Assert.AreEqual(groceriesPrepaymentAccountEntity.AccountId, accountRelationships[0].DestinationAccount.AccountId);
                Assert.AreEqual(groceriesPrepaymentAccountEntity.Name, accountRelationships[0].DestinationAccount.Name);
                Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationships[1].Type);
                Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationships[1].SourceAccount.AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accountRelationships[1].SourceAccount.Name);
                Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationships[1].DestinationAccount.AccountId);
                Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationships[1].DestinationAccount.Name);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
        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);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        public void TestGetLogicalAccountIds()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Assert.AreEqual(1, transactions.Count);
                Assert.AreEqual(transactionEntities[1].TransactionId, transactions[0].TransactionId);
                Assert.AreEqual(transactionEntities[1].Amount, transactions[0].Amount);
                Assert.AreEqual(transactionEntities[1].At, transactions[0].At);
                Assert.AreEqual(transactionEntities[1].CreditAccountId, transactions[0].CreditAccount.AccountId);
                Assert.AreEqual(transactionEntities[1].DebitAccountId, transactions[0].DebitAccount.AccountId);
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
0
        public void NewAccountHasName()
        {
            var offBudgetId = BudgetId.OffBudgetId;
            var account     = AccountFactory.Create(new AccountId(new Guid("DB1C3C3E-C8C4-47A0-AD43-F154FDDB0577")), "Test1", offBudgetId, this.unitOfWork);

            Assert.AreEqual("Test1", account.Name);
        }
Ejemplo n.º 13
0
        public int ExecuteHealthCheck(CalamariVariableDictionary variables)
        {
            var account = AccountFactory.Create(variables);

            var cloudServiceName = variables.Get(SpecialVariables.Action.Azure.CloudServiceName);

            if (account is AzureAccount azureAccount)
            {
                using (var azureClient = azureAccount.CreateComputeManagementClient(certificateStore))
                {
                    var azureResponse = azureClient.HostedServices.List();
                    if (azureResponse.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception("Azure returned HTTP status-code " + azureResponse.StatusCode);
                    }

                    var hostedService = azureResponse.HostedServices.FirstOrDefault(hs => hs.ServiceName == cloudServiceName);
                    if (hostedService == null)
                    {
                        throw new Exception($"Hosted service with name {cloudServiceName} was not found.");
                    }
                }
            }
            else if (account is AzureServicePrincipalAccount servicePrincipalAccount)
            {
                throw new Exception($"Cloud service targets cannot use Service Principal accounts, a Management Certificate account is required.");
            }

            return(0);
        }
        public void TestFindExistentAccount()
        {
            var created = AccountFactory.Create();
            var finded  = _repository.Find(created.Id.GetValueOrDefault());

            Assert.AreEqual(created.Id, finded.Id);
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates new account
        /// </summary>
        /// <param name="firstName">The firstname</param>
        /// <param name="lastName">The lastname</param>
        /// <param name="typeAccount">The account type</param>
        /// <returns>Created account</returns>
        public Account CreateAccount(string firstName, string lastName, AccountType typeAccount)
        {
            var account      = AccountFactory.Create(0, firstName, lastName, typeAccount, this._bonusCounter);
            var addedAccount = this._accountRepository.Add(account.MapBankAccount(this._bonusCounter));

            return(addedAccount.MapAccount(this._bonusCounter));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 转换为账户实体
 /// </summary>
 /// <param name="dto">账户数据传输对象</param>
 public static Account ToEntity3(this AccountDto dto)
 {
     if (dto == null)
     {
         return(new Account());
     }
     return(AccountFactory.Create(
                accountId: dto.Id.ToGuid(),
                type: dto.Type,
                state: dto.State,
                nickname: dto.Nickname,
                password: dto.Password,
                head: dto.Head,
                mobile: dto.Mobile,
                saltd: dto.Saltd,
                idCard: dto.IdCard,
                realName: dto.RealName,
                sex: dto.Sex,
                creationTime: dto.CreationTime,
                creatorId: dto.CreatorId,
                lastModificationTime: dto.LastModificationTime,
                lastModifierId: dto.LastModifierId,
                isDeleted: dto.IsDeleted,
                version: dto.Version
                ));
 }
        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);
            }
        }
        public void TestFindOrCreateExistAccount()
        {
            var created = AccountFactory.Create();
            var finded  = _repository.FindOrCreateBy(created.Number, created.Bank, created.Type, created.Identity);

            Assert.IsNotNull(finded.Id);
            Assert.AreEqual(_repository.Count(), 1);
        }
Ejemplo n.º 20
0
        public void ReconstitutedNewAccountHasCorrectName()
        {
            var offBudgetId             = BudgetId.OffBudgetId;
            var accountId               = new AccountId(new Guid("A34C7724-F9FE-4A14-89A2-C8F1D662EE2A"));
            var prevouslyCreatedAccount = AccountFactory.Create(accountId, "Test2", offBudgetId, this.unitOfWork);

            var account = AccountFactory.Load(accountId, this.unitOfWork);

            Assert.AreEqual("Test2", account.Name);
        }
Ejemplo n.º 21
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);
            }
        }
Ejemplo n.º 22
0
        public void TestCount(int count)
        {
            var account = AccountFactory.Create();

            for (int i = 0; i < count; i++)
            {
                InterestFactory.Create(x => x.Account = account);
            }

            Assert.AreEqual(count, _repository.Count());
        }
Ejemplo n.º 23
0
        public static BankAccount ToBllModel(Account account)
        {
            if (ReferenceEquals(null, account))
            {
                throw new ArgumentNullException($"{nameof(account)} is null.");
            }

            AccountType type = AccountTypeMapper.ToBllModel(account.Type);

            return(AccountFactory.Create(account.Firstname, account.Lastname, type, account.Id));
        }
        public void TestUpdateAccount()
        {
            var created = AccountFactory.Create();

            created.Identity = "0002-9";
            _repository.Update(created);
            var finded = _repository.Find(created.Id);

            Assert.AreEqual(_repository.Count(), 1);
            Assert.AreEqual(created.Id, created.Id);
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        public void TestGetAllAccounts()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

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

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

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

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

                Assert.AreEqual(2, accounts.Count);
                Assert.AreEqual(incomeAccountEntity.AccountId, accounts[0].AccountId);
                Assert.AreEqual(incomeAccountEntity.Name, accounts[0].Name);
                Assert.AreEqual(AccountType.Income, accounts[0].Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, accounts[0].Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, accounts[0].Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, accounts[0].Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accounts[0].Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, accounts[0].Currency.Symbol);
                Assert.AreEqual(checkingAccountEntity.AccountId, accounts[1].AccountId);
                Assert.AreEqual(checkingAccountEntity.Name, accounts[1].Name);
                Assert.AreEqual(AccountType.Asset, accounts[1].Type);
                Assert.AreEqual(usdCurrencyEntity.CurrencyId, accounts[1].Currency.CurrencyId);
                Assert.AreEqual(usdCurrencyEntity.IsPrimary, accounts[1].Currency.IsPrimary);
                Assert.AreEqual(usdCurrencyEntity.Name, accounts[1].Currency.Name);
                Assert.AreEqual(usdCurrencyEntity.ShortName, accounts[1].Currency.ShortName);
                Assert.AreEqual(usdCurrencyEntity.Symbol, accounts[1].Currency.Symbol);
            }
        }
Ejemplo n.º 28
0
        protected override void ShowContent()
        {
            Shell.Write("Account No:");
            var accountId = Convert.ToInt32(Shell.ReadLine());

            Shell.Write("Balance:");
            var amount  = Convert.ToDecimal(Shell.ReadLine());
            var account = AccountFactory.Create(accountId, amount);

            Repository.Save(account);
            Shell.WriteLine($"Account {accountId} created successfully");
            Shell.WriteLine("Press Enter to continue...");
            Shell.ReadLine();
        }
        public void CreateTest()
        {
            // Given
            var id    = Guid.NewGuid();
            var money = 500;
            var owner = new Owner(Guid.NewGuid(), "John", "Doe");

            // When
            var result = factory.Create(id, money, owner);

            // Then
            Assert.AreEqual(id, result.Id);
            Assert.AreEqual(money, result.Money);
            Assert.AreEqual(owner, result.Owner);
        }
        public void TestFindOrCreatedDontHaveBalanceOfDay()
        {
            var account = AccountFactory.Create();
            var created = BalanceFactory.Create(x =>
            {
                x.Date    = DateTime.Today;
                x.Account = account;
            });


            var finded = _repository.FindOrCreateBy(account, DateTime.Today);

            //check
            Assert.AreEqual(created.Id, finded.Id);
        }