示例#1
0
        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 }));
        }
示例#3
0
        public int CreateBudget(CreateBudgetCommand cmd, ApplicationUser createdBy)
        {
            var budget = cmd.ToBudget(createdBy);

            _context.Add(budget);
            _context.SaveChanges();
            return(budget.BudgetId);
        }
示例#4
0
        public async Task <IActionResult> Create([FromBody] CreateBudgetCommand cmd)
        {
            var user = await _userManager.GetUserAsync(User);

            var id = _budgetService.CreateBudget(cmd, user);

            return(Ok(new { message = "Your budget id: " + id }));
        }
示例#5
0
        public Budget Create(CreateBudgetCommand command)
        {
            var service = new Budget(command.Proposal, command.Price, command.ProposalDate, command.Status, command.SessionPrice, command.IdCoachingProcess);

            service.Validate();
            _repository.Create(service);

            if (Commit())
            {
                return(service);
            }

            return(null);
        }
示例#6
0
        public async Task <IActionResult> CreateBudget(CreateBudgetCommand command)
        {
            var user = await _userService.GetUserAsync(User);

            if (user == null)
            {
                _log.LogWarning($"Unable to load user with ID '{_userService.GetUserId(User)}'. Info:{command}");
                return(Forbid());
            }
            if (ModelState.IsValid)
            {
                var id = _service.CreateBudget(command, user);
                return(RedirectToAction(nameof(ViewBudget), new { id = id }));
            }
            return(View(command));
        }
示例#7
0
        public async Task CreateBudget_CreatesCorrectly()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseSqlite(connection)
                          .Options;

            const string budgetName = "General budget";
            const double amount     = 1000.0;

            // Run the test against one instance of the context
            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();
                var service = new BudgetService(context);
                var cmd     = new CreateBudgetCommand
                {
                    Amount = amount,
                    Name   = budgetName,
                };
                var user = new ApplicationUser
                {
                    Id = 123.ToString()
                };
                var budgetId = service.CreateBudget(cmd, user);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ApplicationDbContext(options))
            {
                Assert.Equal(1, await context.Budgets.CountAsync());

                var budget = await context.Budgets.SingleAsync();

                Assert.Equal(1000.0, budget.Amount);
                Assert.Equal("General budget", budget.Name);
                Assert.NotEqual(500, budget.Amount);
                Assert.NotNull(budget);
            }
        }
示例#8
0
        public Task <HttpResponseMessage> Post([FromBody] dynamic body)
        {
            var commandBudget = new CreateBudgetCommand(
                proposal: (string)body.proposal,
                price: (float)body.price,
                status: EBudgetStatus.Enviado,
                proposalDate: DateTime.Now,
                sessionPrice: (float)body.sessionPrice,
                idCoachingProcess: (Guid)body.idCoachingProcess
                );

            var    budget          = _serviceBudget.Create(commandBudget);
            var    coachingProcess = _serviceCoachingProcess.GetOneIncludeDetails(budget.IdCoachingProcess);
            string msg             = budget.Proposal + "\n Preço da sessão: " + budget.Price + "\n Total: " + budget.Price;

            foreach (var coachee in coachingProcess.Coachee)
            {
                _serviceUser.SendEmail(coachee.IdUser, "Orçamento processo de coaching - CoachingPlan", msg);
            }

            return(CreateResponse(HttpStatusCode.Created, budget));
        }
 private void Budget_ErrorsChanged(object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
 {
     CreateBudgetCommand.RaiseCanExecuteChanged();
 }