예제 #1
0
        public void UpdateTransaction()
        {
            var userService = new UserService();
            var service     = new MoneyService();
            var userId      = userService.Register("testUser1" + Guid.NewGuid(), "testPassword");

            service.CreateAccount(userId, "Test Account 1", 1);
            var accounts = service.GetAllAccounts(userId);

            service.CreateCategory(userId, "Test Category 1", 1);
            var categories = service.GetAllCategories(userId);

            service.Deposit(userId, accounts[0].Id, DateTime.Now, 25, 10, "Some income comment", null);
            service.Withdrawal(userId, accounts[0].Id, DateTime.Now, 10, 5, "Some expense comment", categories[0].Id);

            var balance = service.GetAccountBalance(userId, accounts[0].Id);

            Assert.Equal(200, balance);

            var transactionRecords = service.GetAllTransactions(userId, accounts[0].Id);
            var transactionId      = transactionRecords[0].TransactionId;

            Assert.NotNull(transactionRecords);
            Assert.Equal(2, transactionRecords.Count);

            service.UpdateTransaction(transactionId, userId, accounts[0].Id, DateTime.Now, 32, 20, "Updated income", categories[0].Id, false);

            balance = service.GetAccountBalance(userId, accounts[0].Id);
            Assert.Equal(-690, balance);
        }
예제 #2
0
        public void GetTransaction()
        {
            const string accountName  = "Test Account 1";
            const string categoryName = "Test Category 1";
            const byte   categoryType = 1;
            var          service      = new MoneyService();
            var          userService  = new UserService();
            var          userId1      = userService.Register("testUser1" + Guid.NewGuid(), "testPassword");

            service.CreateAccount(userId1, accountName, 1);
            var accounts1 = service.GetAllAccounts(userId1);

            service.CreateCategory(userId1, categoryName, categoryType);
            var categories = service.GetAllCategories(userId1);

            service.Deposit(userId1, accounts1[0].Id, DateTime.Now, 25, 10, "Some income comment", categories[0].Id);

            var transactions = service.GetAllTransactions(userId1, accounts1[0].Id);

            Assert.Equal(1, transactions.Count);

            var transaction = service.GetTransaction(userId1, accounts1[0].Id, transactions[0].TransactionId);

            Assert.NotNull(transaction);
            Assert.Equal(2, transaction.Postings.Count);

            Assert.NotNull(transaction.Category);
            Assert.Equal(categoryName, transaction.Category.Name);
            Assert.Equal(categoryType, transaction.Category.CategoryType);

            Assert.NotNull(transaction.Postings[0].Account);
            Assert.Equal(accountName, transaction.Postings[0].Account.Name);
        }
예제 #3
0
        public void Check_Cached_Values_For_User_Accounts()
        {
            var account1 = moneyService.CreateAccount("Account 1", 1);
            var account2 = moneyService.CreateAccount("Account 2", 2);
            var account3 = moneyService.CreateAccount("Account 3", 3);

            moneyService.Deposit(account1, new DateTime(2012, 2, 11), 10, 3, null, null);
            moneyService.Deposit(account1, new DateTime(2012, 2, 10), 5, 4, null, null);
            moneyService.Withdrawal(account1, new DateTime(2012, 2, 13), 20, 2, null, null);

            moneyService.Deposit(account2, new DateTime(2012, 2, 5), 8, 1, null, null);

            var maintenanceAccounts = adminService.UpdateCachedValuesForUserAccounts(currentUser.Id, true);

            Assert.Equal(7, maintenanceAccounts.Count);
        }
예제 #4
0
        public void Deposit()
        {
            var service     = new MoneyService();
            var userService = new UserService();
            var userId      = userService.Register("testUser" + Guid.NewGuid(), "testPassword");

            service.CreateAccount(userId, "Test Account", 1);
            var accounts = service.GetAllAccounts(userId);

            service.CreateCategory(userId, "Test Category", 1);
            var categories = service.GetAllCategories(userId);

            service.Deposit(userId, accounts[0].Id, DateTime.Now, 25, 2, "Some income comment", categories[0].Id);
        }
예제 #5
0
        public void GetAccountBalance()
        {
            var service     = new MoneyService();
            var userService = new UserService();
            var userId1     = userService.Register("testUser1" + Guid.NewGuid(), "testPassword");
            var userId2     = userService.Register("testUser2" + Guid.NewGuid(), "testPassword");

            service.CreateAccount(userId1, "Test Account 1", 1);
            service.CreateAccount(userId2, "Test Account 2", 1);
            var accounts1 = service.GetAllAccounts(userId1);
            var accounts2 = service.GetAllAccounts(userId2);

            service.CreateCategory(userId1, "Test Category 1", 1);
            var categories1 = service.GetAllCategories(userId1);

            service.Deposit(userId1, accounts1[0].Id, DateTime.Now, 25, 10, "Some income comment", null);

            var balance = service.GetAccountBalance(userId1, accounts1[0].Id);

            Assert.Equal(250, balance);

            service.Withdrawal(userId1, accounts1[0].Id, DateTime.Now, 10, 5, "Some expense comment", categories1[0].Id);

            balance = service.GetAccountBalance(userId1, accounts1[0].Id);
            Assert.Equal(200, balance);

            balance = service.GetAccountBalance(userId2, accounts2[0].Id);
            Assert.Equal(0, balance);

            service.Transfer(userId1, accounts1[0].Id, userId2, accounts2[0].Id, DateTime.Now, 75, "Some transfer comment");

            balance = service.GetAccountBalance(userId1, accounts1[0].Id);
            Assert.Equal(125, balance);

            balance = service.GetAccountBalance(userId2, accounts2[0].Id);
            Assert.Equal(75, balance);
        }