Esempio n. 1
0
        public void ExpenseCreateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                DefaultCommandBus commandBus = lifetime.Resolve<DefaultCommandBus>();
                ICategoryRepository categoryRepository = lifetime.Resolve<ICategoryRepository>();

                Category category = categoryRepository.Get(x => x.Name == "Test Category");
                Assert.IsNotNull(category, "Error: Category not found");

                CreateOrUpdateExpenseCommand command = new CreateOrUpdateExpenseCommand();
                command.Amount = 120;
                command.Date = DateTime.Now;
                command.Category = category;
                command.Transaction = "Test transaction.";

                ICommandHandler<CreateOrUpdateExpenseCommand> commnadHandler = lifetime.Resolve<ICommandHandler<CreateOrUpdateExpenseCommand>>();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Tipo Via Was Not Created by CommandBus");
                Assert.IsTrue(result.Success, "Error: Tipo Via Was Not Created by CommandBus");
            }
        }
Esempio n. 2
0
        public ActionResult Save(ExpenseFormModel form)
        {
            Category category = categoryRepository.GetById(form.CategoryId);

            if (ModelState.IsValid)
            {
                var command = new CreateOrUpdateExpenseCommand
                {
                    ExpenseId = form.ExpenseId,
                    Category = category,
                    Date = form.Date,
                    Transaction = form.Transaction,
                    Amount = form.Amount
                };
                var result = commandBus.Submit(command);
                if (result.Success) return RedirectToAction("Index");
            }

            if (form.ExpenseId == 0)
                return View("Create", form);
            else
                return View("Edit", form);
        }
Esempio n. 3
0
        public void ExpenseUpdateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                IExpenseRepository expenseRepository = lifetime.Resolve<IExpenseRepository>();
                DefaultCommandBus commandBus = lifetime.Resolve<DefaultCommandBus>();

                Expense expense = expenseRepository.Get(c => c.Amount == 120);
                Assert.IsNotNull(expense, "Error: Expense was not found");

                CreateOrUpdateExpenseCommand command = new CreateOrUpdateExpenseCommand();
                command.Amount = 150;
                command.Date = expense.Date;
                command.Category = expense.Category;
                command.Transaction = expense.TransactionDesc;

                ICommandHandler<CreateOrUpdateExpenseCommand> commnadHandler = lifetime.Resolve<ICommandHandler<CreateOrUpdateExpenseCommand>>();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Expense was not updated");
                Assert.IsTrue(result.Success, "Error: Expense was not updated");
            }
        }