public void DeletePlanTest() { // Arrange Guid planId; 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, 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(); planId = plan.Id; } // Act _balanceFacade.DeletePlan(planId); // Assert var deletedPlan = GetPlanById(planId); Assert.That(deletedPlan == null, "Plan was not deleted."); }
public IActionResult Delete([FromForm] Guid id) { var plan = _balanceFacade.GetPlan(id); var account = CurrentAccountProvider.GetCurrentAccount(HttpContext.User); if (plan == null || plan.AccountId != account.Id) { return(RedirectWithError(ExpenseManagerResource.PlanNotDeleted)); } _balanceFacade.DeletePlan(id); return(RedirectToAction("Index", new { sucessMessage = ExpenseManagerResource.PlanDeleted })); }