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); }
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); }
public void Withdrawal() { 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.Withdrawal(userId, accounts[0].Id, DateTime.Now, 13, 10, "Some expense comment", categories[0].Id); }
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); }
public void DeleteCategory() { var userService = new UserService(); var service = new MoneyService(); var userId = userService.Register("testUser" + Guid.NewGuid(), "testPassword"); service.CreateCategory(userId, "Test Category", 1); var categories = service.GetAllCategories(userId); service.DeleteCategory(userId, categories[0].Id); categories = service.GetAllCategories(userId); Assert.Equal(0, categories.Count); }
public void GetAllCategories() { const string expectedCategoryName = "Test Category"; const byte expectedNewCategoryType = 1; var userService = new UserService(); var service = new MoneyService(); var userId = userService.Register("testUser" + Guid.NewGuid(), "testPassword"); service.CreateCategory(userId, expectedCategoryName, expectedNewCategoryType); var categories = service.GetAllCategories(userId); Assert.Equal(1, categories.Count); Assert.Equal(expectedCategoryName, categories[0].Name); Assert.Equal(expectedNewCategoryType, categories[0].CategoryType); }
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); }