Example #1
0
        public void ListItemTypesTest1()
        {
            // Arrange
            const string accountName = "ExpenseManagerAccount01";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };

            const string typeName1 = "Food";
            const string typeName2 = "PC";
            var          type1     = new CostTypeModel
            {
                Name         = typeName1,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var type2 = new CostTypeModel
            {
                Name         = typeName2,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.CostTypes.Add(type1);
                db.CostTypes.Add(type2);
                db.SaveChanges();
            }

            // Act
            var types = _expenseFacade.ListItemTypes(null, account.Id, null);

            // Assert
            Assert.That(types.Count == 2, "Types were not listed.");
        }
Example #2
0
        public void DeleteItemTypeTest()
        {
            // Arrange
            Guid         typeId;
            const string accountName = "ExpenseManagerAccount01";
            const string typeName    = "Food";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };

            var type = new CostTypeModel
            {
                Name         = typeName,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                typeId = type.Id;
            }

            // Act
            _expenseFacade.DeleteItemType(typeId);

            // Assert
            var deletedType = GetTypeByName(typeName);

            Assert.That(deletedType == null, "Type was not deleted.");
        }
Example #3
0
        public void GetAccount_ExistingAccount_ReturnCorrectAccount()
        {
            var account = new Account
            {
                Badges = new List <AccountBadge>(),
                Costs  = new List <CostInfo>(),
                Name   = "ExpenseManagerAccount01"
            };
            var accountModel = _mapper.Map <Account, AccountModel>(account);

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Accounts.Add(accountModel);
                dbContext.SaveChanges();
            }
            var accountId = accountModel.Id;

            // Act
            var obtainedAccount = _accountFacade.GetAccount(accountId);

            // Assert
            Assert.AreEqual(obtainedAccount, account, "GetAccount failed - accounts do not match.");
        }
Example #4
0
        public void GetItemCountTest4()
        {
            // Arrange
            Guid         accountId;
            Guid         typeId1;
            const string accountName = "ExpenseManagerAccount01";
            const string typeName1   = "Food";
            const string typeName2   = "PC";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            var type1 = new CostTypeModel
            {
                Name         = typeName1,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var type2 = new CostTypeModel
            {
                Name         = typeName2,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type1);
                db.CostTypes.Add(type2);
                db.SaveChanges();
                accountId = account.Id;
                typeId1   = type1.Id;
                var typeId2 = type2.Id;
                db.CostInfos.Add(new CostInfoModel
                {
                    Description = "bread",
                    AccountId   = accountId,
                    TypeId      = typeId1,
                    IsIncome    = true,
                    Money       = 25,
                    Created     = DateTime.Now
                });
                db.CostInfos.Add(new CostInfoModel
                {
                    Description = "WoW",
                    AccountId   = accountId,
                    TypeId      = typeId2,
                    IsIncome    = false,
                    Money       = 1500,
                    Created     = DateTime.Now
                });
                db.SaveChanges();
            }

            // Act
            var mixedItemsCount = _expenseFacade.GetCostInfosCount(accountId, null, null, null, 25, 2000, typeId1, true);

            // Assert
            Assert.That(mixedItemsCount == 1, "Number of mixed items is not correct.");
        }
Example #5
0
        public void ListItemTest1()
        {
            // Arrange
            const string accountName = "ExpenseManagerAccount01";
            const string typeName1   = "Food";
            const string typeName2   = "PC";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            var type1 = new CostTypeModel
            {
                Name         = typeName1,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var type2 = new CostTypeModel
            {
                Name         = typeName2,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type1);
                db.CostTypes.Add(type2);
                db.SaveChanges();
                var accountId = account.Id;
                var typeId1   = type1.Id;
                var typeId2   = type2.Id;
                db.CostInfos.Add(new CostInfoModel
                {
                    Description = "bread",
                    AccountId   = accountId,
                    TypeId      = typeId1,
                    IsIncome    = true,
                    Money       = 25,
                    Created     = DateTime.Now
                });
                db.CostInfos.Add(new CostInfoModel
                {
                    Description = "WoW",
                    AccountId   = accountId,
                    TypeId      = typeId2,
                    IsIncome    = false,
                    Money       = 1500,
                    Created     = DateTime.Now
                });
                db.SaveChanges();
            }

            // Act
            var items = _expenseFacade.ListItems(null, null, null);

            // Assert
            Assert.That(items.Count == 2, "Items were not listed.");
        }
Example #6
0
 public void Add(Despesa despesa)
 {
     _contexto.Despesas.Add(despesa);
     _contexto.SaveChanges();
 }
Example #7
0
        public void UpdatePlanTest()
        {
            // Arrange
            Guid         accountId;
            Guid         planId;
            Guid         typeId;
            const string accountName = "ExpenseManagerAccount01";
            const string typeName    = "Food";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            var type = new CostTypeModel
            {
                Name         = typeName,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var plan = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 10000,
                Deadline     = DateTime.Today.AddDays(5),
                Start        = DateTime.Today,
                IsCompleted  = false,
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                accountId        = account.Id;
                typeId           = plan.Id;
                plan.AccountId   = accountId;
                plan.PlannedType = type;
                db.Plans.Add(plan);
                db.SaveChanges();
                planId = plan.Id;
            }

            // Act
            _balanceFacade.UpdatePlan(new Plan
            {
                Id            = planId,
                Description   = "I want money for games!",
                PlanType      = PlanType.Save,
                PlannedMoney  = 10000,
                Deadline      = DateTime.Today,
                IsCompleted   = false,
                AccountId     = accountId,
                PlannedTypeId = typeId
            });

            // Assert
            var updatedPlan = GetPlanById(planId);

            Assert.That(updatedPlan.Description.Equals("I want money for games!"), "Plan was not updated.");
        }
Example #8
0
        public void CheckBadgesRequirements()
        {
            const string accountName = "ExpenseManagerAccount01";
            const string typeName    = "Food";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            var type = new CostTypeModel
            {
                Name         = typeName,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var plan = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 1000,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan1 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 100000,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan2 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 1001,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan3 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan4 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan5 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                var accountId = account.Id;
                plan.AccountId    = accountId;
                plan.PlannedType  = type;
                plan1.AccountId   = accountId;
                plan1.PlannedType = type;
                plan2.AccountId   = accountId;
                plan2.PlannedType = type;
                plan3.AccountId   = accountId;
                plan3.PlannedType = type;
                plan4.AccountId   = accountId;
                plan4.PlannedType = type;
                plan5.AccountId   = accountId;
                plan5.PlannedType = type;

                db.Plans.Add(plan);
                db.Plans.Add(plan1);
                db.Plans.Add(plan2);
                db.Plans.Add(plan3);
                db.Plans.Add(plan4);
                db.Plans.Add(plan5);
                db.SaveChanges();
                var item = new CostInfoModel()
                {
                    Description          = "bread",
                    AccountId            = accountId,
                    TypeId               = type.Id,
                    IsIncome             = true,
                    Money                = 10001,
                    Created              = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                    Account              = db.Accounts.Find(accountId),
                    Type                 = db.CostTypes.Find(type.Id),
                    Periodicity          = PeriodicityModel.None,
                    PeriodicMultiplicity = 3
                };
                db.CostInfos.Add(item);

                db.Badges.Add(new BadgeModel
                {
                    Accounts    = new List <AccountBadgeModel>(),
                    BadgeImgUri = "badge.png",
                    Name        = "PlanCompleter",
                    Description = "Complete at least 5 plans"
                });

                db.SaveChanges();
            }
            _balanceFacade.CheckBadgesRequirements();
            var badgedAccount = _accountFacade.GetAccount(account.Id);

            Assert.IsTrue(badgedAccount.Badges.Count > 0);
        }
Example #9
0
        /// <summary>
        /// Performs ExpenseDB initialization
        /// </summary>
        /// <param name="context">ExpenseDbContext to initialize the db</param>
        internal static void InitializeDatabase(ExpenseDbContext context)
        {
            TruncateDB(context);

            context.Users.AddOrUpdate(new UserModel {
                Name = "Demo user", Email = "*****@*****.**"
            });

            Random random = new Random();

            var account = new AccountModel()
            {
                Name = "testerAccount"
            };

            context.Accounts.AddOrUpdate(account);

            var badge1 = new BadgeModel
            {
                Accounts    = new List <AccountBadgeModel>(),
                BadgeImgUri = "badge.png",
                Name        = "PassionatePennyPincher",
                Description = "Save >=20k $ within all completed plans"
            };

            context.Badges.AddOrUpdate(badge1);

            context.Badges.AddOrUpdate(new BadgeModel
            {
                Accounts    = new List <AccountBadgeModel>(),
                BadgeImgUri = "badge.png",
                Name        = "PlanCompleter",
                Description = "Complete at least 5 plans"
            });

            var accountBadge = new AccountBadgeModel()
            {
                Account  = account,
                Badge    = badge1,
                Achieved = DateTime.Now
            };

            context.AccountBadges.AddOrUpdate(accountBadge);

            var user = new UserModel()
            {
                AccessType = AccountAccessTypeModel.Full,
                Name       = "tester",
                Email      = "*****@*****.**",
                Account    = account
            };

            context.Users.AddOrUpdate(user);

            var user2 = new UserModel()
            {
                Name  = "tester2",
                Email = "*****@*****.**",
            };

            context.Users.AddOrUpdate(user2);

            var costType1 = new CostTypeModel()
            {
                Name    = "Strava",
                Account = account
            };

            var costType2 = new CostTypeModel()
            {
                Name    = "Zábava",
                Account = account
            };

            context.CostTypes.AddOrUpdate(costType1);
            context.CostTypes.AddOrUpdate(costType2);

            var cost1 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Fajný rohlík",
                IsIncome    = false,
                Periodicity = PeriodicityModel.None,
                Money       = 20,
                Type        = costType1
            };

            var cost2 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Chlebík",
                IsIncome    = false,
                Periodicity = PeriodicityModel.None,
                Money       = 50,
                Type        = costType1
            };

            var cost3 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Futsal",
                IsIncome    = false,
                Periodicity = PeriodicityModel.None,
                Money       = 100,
                Type        = costType2
            };

            var cost4 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Byt",
                IsIncome    = false,
                Periodicity = PeriodicityModel.Month,
                Money       = 200,
                Type        = costType1
            };

            var cost5 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Výplata",
                IsIncome    = true,
                Periodicity = PeriodicityModel.Day,
                Money       = 1000,
                Type        = costType1
            };

            var cost6 = new CostInfoModel()
            {
                Account     = account,
                Created     = DateTime.Now,
                Description = "Príjem",
                IsIncome    = true,
                Periodicity = PeriodicityModel.None,
                Money       = 2700,
                Type        = costType1
            };

            context.CostInfos.AddOrUpdate(cost1);
            context.CostInfos.AddOrUpdate(cost2);
            context.CostInfos.AddOrUpdate(cost3);
            context.CostInfos.AddOrUpdate(cost4);
            context.CostInfos.AddOrUpdate(cost5);
            context.CostInfos.AddOrUpdate(cost6);

            for (int i = 0; i < 30; i++)
            {
                var cost = new CostInfoModel()
                {
                    Account     = account,
                    Created     = DateTime.UtcNow.AddDays(-random.Next(0, 14)),
                    Description = "Seeded expense",
                    IsIncome    = false,
                    Periodicity = PeriodicityModel.None,
                    Money       = (decimal)(random.NextDouble() * 150),
                    Type        = costType1
                };
                context.CostInfos.Add(cost);
            }

            var plan1 = new PlanModel()
            {
                Account      = account,
                Start        = DateTime.ParseExact("22/11/2016", "dd/MM/yyyy", null),
                Deadline     = DateTime.ParseExact("24/12/2016", "dd/MM/yyyy", null),
                Description  = "Ušetriť na rohlík",
                IsCompleted  = false,
                PlannedMoney = 100,
                PlannedType  = costType1,
                PlanType     = PlanTypeModel.Save
            };

            var plan2 = new PlanModel()
            {
                Account      = account,
                Start        = DateTime.ParseExact("15/11/2016", "dd/MM/yyyy", null),
                Deadline     = DateTime.ParseExact("20/11/2016", "dd/MM/yyyy", null),
                Description  = "Ušetriť na Škodovku",
                IsCompleted  = false,
                PlannedMoney = 5200,
                PlannedType  = costType2,
                PlanType     = PlanTypeModel.Save
            };

            var plan3 = new PlanModel()
            {
                Account      = account,
                Start        = DateTime.ParseExact("22/11/2016", "dd/MM/yyyy", null),
                Deadline     = DateTime.ParseExact("24/12/2016", "dd/MM/yyyy", null),
                Description  = "Nemíňať na jedlo",
                IsCompleted  = false,
                PlannedMoney = 2000,
                PlannedType  = costType1,
                PlanType     = PlanTypeModel.MaxSpend
            };

            var plan4 = new PlanModel()
            {
                Account      = account,
                Start        = DateTime.ParseExact("11/10/2016", "dd/MM/yyyy", null),
                Deadline     = DateTime.ParseExact("15/10/2016", "dd/MM/yyyy", null),
                Description  = "Ušetrené na niečo",
                IsCompleted  = true,
                PlannedMoney = 2000,
                PlannedType  = costType1,
                PlanType     = PlanTypeModel.MaxSpend
            };

            var plan5 = new PlanModel()
            {
                Account      = account,
                Start        = DateTime.ParseExact("15/11/2016", "dd/MM/yyyy", null),
                Deadline     = DateTime.ParseExact("24/12/2016", "dd/MM/yyyy", null),
                Description  = "Ušetriť na Škodovku",
                IsCompleted  = false,
                PlannedMoney = 3200,
                PlannedType  = costType2,
                PlanType     = PlanTypeModel.Save
            };

            context.Plans.AddOrUpdate(plan1);
            context.Plans.AddOrUpdate(plan2);
            context.Plans.AddOrUpdate(plan3);
            context.Plans.AddOrUpdate(plan4);
            context.Plans.AddOrUpdate(plan5);

            context.CostTypes.AddOrUpdate(new CostTypeModel {
                CostInfoList = new List <CostInfoModel>(), Name = "Food", Account = account
            });

            context.SaveChanges();
        }