public ActionResult Create(Models.ExpenseTransaction.CreateModel model)
        {
            var expenseTransaction = new ExpenseTransaction();
            expenseTransaction.Configure(model.Amount)
                .ForDate(model.Date)
                .WithComments(model.Comments)
                .ExpenseAccount(_repository.Find<Account>(model.SelectedExpenseAccountId))
                .AccountToCredit(_repository.Find<Account>(model.SelectedAssetOrLiabilityAccountId));

            _repository.Save(expenseTransaction);

            return RedirectToAction("Index", "Transaction");
        }
        public void Configure_ShouldSetPropertiesAsExpected()
        {
            const decimal amount = 100;
            var date = DateTime.Today.AddDays(1);
            const string comments = "something";
            var expenseAccount = new ExpenseAccount();
            var assetAccount = new AssetAccount();

            var transaction = new ExpenseTransaction();
            transaction.Configure(amount)
                    .ForDate(date)
                    .WithComments(comments)
                    .ExpenseAccount(expenseAccount)
                    .AccountToCredit(assetAccount);

            Assert.That(transaction.Date, Is.EqualTo(date));
            Assert.That(transaction.Comments, Is.EqualTo(comments));
            Assert.That(transaction.Entries.Count, Is.EqualTo(2));
            Assert.That(transaction.Entries.Any(x => (x.Amount == amount) && (x.Type == EntryType.Debit) && (x.Account == expenseAccount)), Is.True);
            Assert.That(transaction.Entries.Any(x => (x.Amount == amount) && (x.Type == EntryType.Credit) && (x.Account == assetAccount)), Is.True);
        }
        public void Edit_ShouldReturnViewWithModel()
        {
            var expenseAccount1 = new ExpenseAccount();
            var expenseAccount2 = new ExpenseAccount();
            var assetAccount = new AssetAccount();
            var liabilityAccount = new LiabilityAccount();
            var accounts = new Account[] { expenseAccount1, expenseAccount2, assetAccount, liabilityAccount };

            const string comments = "something";
            const decimal amount = 100;
            var date = DateTime.Today.AddDays(1);

            var expenseTransaction = new ExpenseTransaction();
            expenseTransaction.Configure(amount)
                .ForDate(date)
                .WithComments(comments)
                .ExpenseAccount(expenseAccount2)
                .AccountToCredit(liabilityAccount);

            _repository.Stub(x => x.Find<ExpenseTransaction>(expenseTransaction.Id)).Return(expenseTransaction);
            _repository.Stub(x => x.Get<Account>()).Repeat.Times(2).Return(accounts);

            var controller = GetController();
            var result = (ViewResult)controller.Edit(expenseTransaction.Id);

            Assert.That(result.ViewName, Is.EqualTo("Edit"));

            var viewModel = (EditModel)result.Model;
            Assert.That(viewModel.Id, Is.EqualTo(expenseTransaction.Id));
            Assert.That(viewModel.ExpenseAccounts.Count(), Is.EqualTo(2));
            Assert.That(viewModel.ExpenseAccounts.Any(x => x.Id == expenseAccount1.Id), Is.True);
            Assert.That(viewModel.ExpenseAccounts.Any(x => x.Id == expenseAccount2.Id), Is.True);
            Assert.That(viewModel.SelectedExpenseAccountId, Is.EqualTo(expenseAccount2.Id));
            Assert.That(viewModel.AssetAndLiabilityAccounts.Count(), Is.EqualTo(2));
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == assetAccount.Id), Is.True);
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == liabilityAccount.Id), Is.True);
            Assert.That(viewModel.SelectedAssetOrLiabilityAccountId, Is.EqualTo(liabilityAccount.Id));
            Assert.That(viewModel.Date, Is.EqualTo(date));
            Assert.That(viewModel.Amount, Is.EqualTo(amount));
            Assert.That(viewModel.Comments, Is.EqualTo(comments));
        }