public async Task Test_FundBalanceIs0_WhenBudgetCreated() { Budget createdBudget = null; Budget rootBudget = this.buildersAndFactories.BudgetBuilder.Build(); decimal expectedFundBalance = 0; Mock <IUnitOfWork> unitOfWork = new Mock <IUnitOfWork>(); Mock <IRepository <Budget> > budgetRepo = new Mock <IRepository <Budget> >(); UserFactory userFactory = this.buildersAndFactories.GetService <UserFactory>(); IIncludableQuerySet <Budget> budgets = new InMemoryIncludableQuerySet <Budget>(new List <Budget>() { rootBudget }); budgetRepo.Setup(r => r.GetAll()).Returns(budgets); budgetRepo.Setup(r => r.Add(It.IsAny <Budget>())).Callback((Budget budget) => { createdBudget = budget; }); unitOfWork.Setup(u => u.SaveChangesAsync()).Returns(Task.CompletedTask); unitOfWork.Setup(u => u.GetRepository <Budget>()).Returns(budgetRepo.Object); CreateBudgetCommand command = new CreateBudgetCommand(unitOfWork.Object, rootBudget.Id, "", 12); await command.Run(); Assert.Equal(expectedFundBalance, createdBudget.Fund.FundBalance); }
public async Task <JsonResult> CreateBudget([FromBody] CreateBudgetRequest body) { CreateBudgetCommand command = new CreateBudgetCommand(this.unitOfWork, body.ParentBudgetId, body.Name, body.SetAmount); await command.Run(); return(new JsonResult(new { success = true })); }