public ActionResult Create(Models.TransferTransaction.CreateModel model)
        {
            var transferTransaction = new TransferTransaction();
            transferTransaction.Configure(model.Amount)
                .ForDate(model.Date)
                .WithComments(model.Comments)
                .FromAccount(_repository.Find<Account>(model.SelectedFromAccountId))
                .ToAccount(_repository.Find<Account>(model.SelectedToAccountId));

            _repository.Save(transferTransaction);

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

            var transaction = new TransferTransaction();
            transaction.Configure(amount)
                    .ForDate(date)
                    .WithComments(comments)
                    .FromAccount(assetAccount)
                    .ToAccount(liabilityAccount);

            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.Credit) && (x.Account == assetAccount)), Is.True);
            Assert.That(transaction.Entries.Any(x => (x.Amount == amount) && (x.Type == EntryType.Debit) && (x.Account == liabilityAccount)), Is.True);
        }
        public void Edit_ShouldReturnViewWithModel()
        {
            var assetAccount1 = new AssetAccount();
            var assetAccount2 = new AssetAccount();
            var liabilityAccount1 = new LiabilityAccount();
            var liabilityAccount2 = new LiabilityAccount();
            var accounts = new Account[] { assetAccount1, assetAccount2, liabilityAccount1, liabilityAccount2 };

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

            var TransferTransaction = new TransferTransaction();
            TransferTransaction.Configure(amount)
                .ForDate(date)
                .WithComments(comments)
                .FromAccount(assetAccount1)
                .ToAccount(assetAccount2);

            _repository.Stub(x => x.Find<TransferTransaction>(TransferTransaction.Id)).Return(TransferTransaction);
            _repository.Stub(x => x.Get<Account>()).Return(accounts);

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

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

            var viewModel = (EditModel)result.Model;
            Assert.That(viewModel.Id, Is.EqualTo(TransferTransaction.Id));
            Assert.That(viewModel.AssetAndLiabilityAccounts.Count(), Is.EqualTo(4));
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == assetAccount1.Id), Is.True);
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == assetAccount2.Id), Is.True);
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == liabilityAccount1.Id), Is.True);
            Assert.That(viewModel.AssetAndLiabilityAccounts.Any(x => x.Id == liabilityAccount2.Id), Is.True);
            Assert.That(viewModel.SelectedFromAccountId, Is.EqualTo(assetAccount1.Id));
            Assert.That(viewModel.SelectedToAccountId, Is.EqualTo(assetAccount2.Id));
            Assert.That(viewModel.Date, Is.EqualTo(date));
            Assert.That(viewModel.Amount, Is.EqualTo(amount));
            Assert.That(viewModel.Comments, Is.EqualTo(comments));
        }