public void CheckAllMaxSpendDeadlinesTest() { 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.MaxSpend, PlannedMoney = 10000, PlannedType = type, IsCompleted = false, Start = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)), Deadline = DateTime.Now.Add(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; db.Plans.Add(plan); db.SaveChanges(); var item = new CostInfoModel() { Description = "bread", AccountId = accountId, TypeId = type.Id, IsIncome = true, Money = 999, 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.SaveChanges(); } _balanceFacade.CheckAllMaxSpendDeadlines(); Assert.IsTrue(_balanceFacade.ListPlans(null, null).Count == 1); Assert.IsTrue(_balanceFacade.ListPlans(null, null).Single().IsCompleted); }
public void UpdateItemTest() { // Arrange const string accountName = "ExpenseManagerAccount01"; const string typeName = "Food"; Guid accountId; Guid typeId; Guid infoId; 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 info = new CostInfoModel { Description = "bread", IsIncome = true, Money = 25, Created = DateTime.Now }; using ( var db = new ExpenseDbContext( Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection))) { db.Accounts.Add(account); db.CostTypes.Add(type); db.SaveChanges(); accountId = account.Id; typeId = type.Id; info.AccountId = accountId; info.TypeId = typeId; db.CostInfos.Add(info); db.SaveChanges(); infoId = info.Id; } // Act _expenseFacade.UpdateItem(new CostInfo { Id = infoId, Description = "bread", AccountId = accountId, TypeId = typeId, IsIncome = true, Money = 50, Created = DateTime.Now }); // Assert Assert.That(GetItemById(infoId).Money == 50, "Item was not updated."); }
public void ClosePlanTest() { 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, IsCompleted = false, }; 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; db.Plans.Add(plan); 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.SaveChanges(); } var closeable = _balanceFacade.ListAllCloseablePlans(account.Id); var balance = _balanceFacade.GetBalance(account.Id); Assert.IsTrue(closeable.Count == 1, "Plan not found as closeable"); _balanceFacade.ClosePlan(closeable.Single()); Assert.IsTrue(balance == _expenseFacade.ListItems(null, null, null, null, null, null, null, false, null).Single().Money + _balanceFacade.GetBalance(account.Id)); }
public void RecomputePeriodicCosts() { // Arrange 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(); var accountId = account.Id; var typeId = type.Id; var item = new CostInfoModel() { Description = "bread", AccountId = accountId, TypeId = typeId, IsIncome = true, Money = 25, Created = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)), Account = db.Accounts.Find(accountId), Type = db.CostTypes.Find(typeId), Periodicity = PeriodicityModel.Month, PeriodicMultiplicity = 3 }; db.CostInfos.Add(item); db.SaveChanges(); } _balanceFacade.RecomputePeriodicCosts(); var result = _expenseFacade.ListItems(null, Periodicity.None, null); Assert.IsTrue(result.Count == 1); Assert.IsTrue(result.Single().Description.Equals("bread")); }
private void CloneToCost(PlanModel plan) { CostInfoModel costInfo = new CostInfoModel { Money = plan.PlannedMoney, Account = plan.Account, Type = plan.PlannedType, Created = DateTime.Now, IsIncome = false, Description = plan.Description, PeriodicMultiplicity = 0, Periodicity = PeriodicityModel.None }; using (var unitOfWork = UnitOfWorkProvider.Create()) { _costInfoRepository.Insert(costInfo); unitOfWork.Commit(); } }
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); }
/// <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(); }