public void CreatePlanTest() { // Arrange Guid accountId; 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(); accountId = account.Id; typeId = type.Id; } var plan = new Plan() { AccountId = accountId, Description = "I want money for food!", PlanType = PlanType.Save, PlannedMoney = 10000, Deadline = DateTime.Today, IsCompleted = false, PlannedTypeId = typeId }; // Act var planId = _balanceFacade.CreatePlan(plan); // Assert var createdPlan = GetPlanById(planId); Assert.That(createdPlan != null, "Plan was not created."); }
public IActionResult Store(CreateViewModel model) { var costType = _expenseFacade.GetItemType(model.PlannedTypeId); var account = CurrentAccountProvider.GetCurrentAccount(HttpContext.User); if (!ModelState.IsValid || costType == null || costType.AccountId != account.Id) { ModelState.AddModelError(string.Empty, ExpenseManagerResource.InvalidInputData); model.CostTypes = GetAllCostTypes(); return(View("Create", model)); } var plan = Mapper.Map <Plan>(model); plan.AccountId = account.Id; plan.Start = DateTime.Now; _balanceFacade.CreatePlan(plan); return(RedirectToAction("Index", new { successMessage = ExpenseManagerResource.PlanCreated })); }