public void Create_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 };
            _repository.Stub(x => x.Get<Account>()).Return(accounts);

            var controller = GetController();
            var result = (ViewResult)controller.Create();

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

            var viewModel = (CreateModel)result.Model;
            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(DateTime.Today));
            Assert.That(viewModel.Amount, Is.EqualTo(0));
            Assert.That(viewModel.Comments, Is.Null);
        }
        private Entry SaveEntry(Account account)
        {
            var entry = new Entry();
            entry.Account = account;

            return Repository.Save(entry);
        }
        private Entry GetEntry(DateTime date, decimal amount, Account account, EntryType entryType = EntryType.Debit)
        {
            var transaction = new IncomeTransaction { Date = date };
            var entry = new Entry { Amount = amount, Account = account, Transaction = transaction, Type = entryType };
            transaction.Entries.Add(entry);

            Repository.Save(transaction);

            return entry;
        }
 IConfigureIncomeTransaction IConfigureIncomeTransaction.IncomeAccount(Account incomeAccount)
 {
     AddEntry(new Entry { Account = incomeAccount, Type = EntryType.Credit, Amount = _amount });
     return this;
 }
 IConfigureIncomeTransaction IConfigureIncomeTransaction.AccountToDebit(Account accountToDebit)
 {
     AddEntry(new Entry { Account = accountToDebit, Type = EntryType.Debit, Amount = _amount });
     return this;
 }
        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));
        }
        private Account SaveAccount(Account account)
        {
            Repository.Save(account);

            return Repository.Save(account);
        }
 IConfigureTransferTransaction IConfigureTransferTransaction.ToAccount(Account toAccount)
 {
     AddEntry(new Entry { Account = toAccount, Type = EntryType.Debit, Amount = _amount });
     return this;
 }
 IConfigureTransferTransaction IConfigureTransferTransaction.FromAccount(Account fromAccount)
 {
     AddEntry(new Entry { Account = fromAccount, Type = EntryType.Credit, Amount = _amount });
     return this;
 }
        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));
        }
 IConfigureExpenseTransaction IConfigureExpenseTransaction.ExpenseAccount(Account expenseAccount)
 {
     AddEntry(new Entry { Account = expenseAccount, Type = EntryType.Debit, Amount = _amount });
     return this;
 }
 IConfigureExpenseTransaction IConfigureExpenseTransaction.AccountToCredit(Account accountToCredit)
 {
     AddEntry(new Entry { Account = accountToCredit, Type = EntryType.Credit, Amount = _amount });
     return this;
 }
        public void Edit_ShouldReturnViewWithModel()
        {
            var incomeAccount1 = new IncomeAccount();
            var incomeAccount2 = new IncomeAccount();
            var assetAccount1 = new AssetAccount();
            var assetAccount2 = new AssetAccount();
            var accounts = new Account[] { incomeAccount1, incomeAccount2, assetAccount1, assetAccount2 };

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

            var IncomeTransaction = new IncomeTransaction();
            IncomeTransaction.Configure(amount)
                .ForDate(date)
                .WithComments(comments)
                .IncomeAccount(incomeAccount2)
                .AccountToDebit(assetAccount2);

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

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

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

            var viewModel = (EditModel)result.Model;
            Assert.That(viewModel.Id, Is.EqualTo(IncomeTransaction.Id));
            Assert.That(viewModel.IncomeAccounts.Count(), Is.EqualTo(2));
            Assert.That(viewModel.IncomeAccounts.Any(x => x.Id == incomeAccount1.Id), Is.True);
            Assert.That(viewModel.IncomeAccounts.Any(x => x.Id == incomeAccount2.Id), Is.True);
            Assert.That(viewModel.SelectedIncomeAccountId, Is.EqualTo(incomeAccount2.Id));
            Assert.That(viewModel.AssetAccounts.Count(), Is.EqualTo(2));
            Assert.That(viewModel.AssetAccounts.Any(x => x.Id == assetAccount1.Id), Is.True);
            Assert.That(viewModel.AssetAccounts.Any(x => x.Id == assetAccount2.Id), Is.True);
            Assert.That(viewModel.SelectedAssetAccountId, 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));
        }