public void Data_Create_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var category = new MABMoney.Domain.Category {
                Account_AccountID = 1,
                Name = "ADDED",
                Type = CategoryType.Income
            };

            var result = repository.Add(category);

            Assert.IsTrue(result.CategoryID == 11);
            Assert.IsTrue(result.Name == "ADDED");
            Assert.IsTrue(result.Type == CategoryType.Income);
            Assert.IsTrue(result.Account_AccountID == 1);
            Assert.IsTrue(result.AccountName == "Current");
            Assert.IsTrue(result.CreatedBy == 1);
            Assert.IsTrue(result.CreatedDate.Date == DateTime.Now.Date);
            Assert.IsTrue(result.LastModifiedBy == 1);
            Assert.IsTrue(result.LastModifiedDate.Date == DateTime.Now.Date);
        }
        public void Data_Read_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var data = repository.Get(1);

            Assert.IsTrue(data.CategoryID == 1);
            Assert.IsTrue(data.Name == "Salary");
            Assert.IsTrue(data.Account_AccountID == 1);
            Assert.IsTrue(data.AccountName == "Current");
        }
        public void Data_Read_Other_User_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var data = repository.Get(9);

            Assert.IsTrue(data == null);
        }
        public void Data_Read_Categories_By_Account()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var data = repository.All(1).OrderBy(x => x.CategoryID).ToList();

            // There are 10 test categories, but only 4 for this account and user
            Assert.IsTrue(data.Count == 4);
            Assert.IsTrue(data[0].CategoryID == 1);
            Assert.IsTrue(data[0].Name == "Salary");
            Assert.IsTrue(data[0].Account_AccountID == 1);
            Assert.IsTrue(data[0].AccountName == "Current");
            Assert.IsTrue(data[1].CategoryID == 2);
            Assert.IsTrue(data[1].Name == "Rent");
            Assert.IsTrue(data[1].Account_AccountID == 1);
            Assert.IsTrue(data[1].AccountName == "Current");
            Assert.IsTrue(data[2].CategoryID == 3);
            Assert.IsTrue(data[2].Name == "Food");
            Assert.IsTrue(data[2].Account_AccountID == 1);
            Assert.IsTrue(data[2].AccountName == "Current");
            Assert.IsTrue(data[3].CategoryID == 4);
            Assert.IsTrue(data[3].Name == "Bills");
            Assert.IsTrue(data[3].Account_AccountID == 1);
            Assert.IsTrue(data[3].AccountName == "Current");
        }
        public void Data_Read_Categories()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var data = repository.All().OrderBy(x => x.CategoryID).ToList();

            // There are 8 test categories for this user but 2 are deleted
            Assert.IsTrue(data.Count == 6);
            Assert.IsTrue(data[0].CategoryID == 1);
            Assert.IsTrue(data[0].Name == "Salary");
            Assert.IsTrue(data[0].Account_AccountID == 1);
            Assert.IsTrue(data[0].AccountName == "Current");
            Assert.IsTrue(data[1].CategoryID == 2);
            Assert.IsTrue(data[1].Name == "Rent");
            Assert.IsTrue(data[1].Account_AccountID == 1);
            Assert.IsTrue(data[1].AccountName == "Current");
            Assert.IsTrue(data[2].CategoryID == 3);
            Assert.IsTrue(data[2].Name == "Food");
            Assert.IsTrue(data[2].Account_AccountID == 1);
            Assert.IsTrue(data[2].AccountName == "Current");
            Assert.IsTrue(data[3].CategoryID == 4);
            Assert.IsTrue(data[3].Name == "Bills");
            Assert.IsTrue(data[3].Account_AccountID == 1);
            Assert.IsTrue(data[3].AccountName == "Current");
            Assert.IsTrue(data[4].CategoryID == 6);
            Assert.IsTrue(data[4].Name == "Payments");
            Assert.IsTrue(data[4].Account_AccountID == 3);
            Assert.IsTrue(data[4].AccountName == "Credit");
            Assert.IsTrue(data[5].CategoryID == 7);
            Assert.IsTrue(data[5].Name == "Bills");
            Assert.IsTrue(data[5].Account_AccountID == 3);
            Assert.IsTrue(data[5].AccountName == "Credit");
        }
        public void Data_Delete_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var result = repository.Delete(1);

            var category = repository.Get(1);

            Assert.IsTrue(category == null);
            Assert.IsTrue(result.Deleted == true);
            Assert.IsTrue(result.DeletedBy == 1);
            Assert.IsTrue(result.DeletedDate.Value.Date == DateTime.Now.Date);
        }
        public void Data_Create_Existing_Deleted_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var category = new MABMoney.Domain.Category {
                Account_AccountID = 1,
                Name = "Deleted",
                Type = CategoryType.Expense
            };

            var result = repository.Add(category);

            Assert.IsTrue(result.CategoryID == 5);
            Assert.IsTrue(result.Name == "Deleted");
            Assert.IsTrue(result.Type == CategoryType.Expense);
            Assert.IsTrue(result.Account_AccountID == 1);
            Assert.IsTrue(result.AccountName == "Current");
            Assert.IsTrue(result.LastModifiedBy == 1);
            Assert.IsTrue(result.LastModifiedDate.Date == DateTime.Now.Date);
            Assert.IsTrue(result.Deleted == false);
            Assert.IsTrue(result.DeletedDate == null);
            Assert.IsTrue(result.DeletedBy == null);
        }
        public void Data_Update_Category()
        {
            var repository = new CategoryRepository(_dataConnectionString, 1);

            var category = repository.Get(1);

            category.Account_AccountID = 2;
            category.Name = "UPDATED";
            category.Type = CategoryType.Income;

            var result = repository.Update(category);

            Assert.IsTrue(result.Account_AccountID == 2);
            Assert.IsTrue(result.AccountName == "Savings");
            Assert.IsTrue(result.Name == "UPDATED");
            Assert.IsTrue(result.Type == CategoryType.Income);
            Assert.IsTrue(result.LastModifiedBy == 1);
            Assert.IsTrue(result.LastModifiedDate.Date == DateTime.Now.Date);
        }