public void Execute_WillGetBalanceForOnlyAssetAndLiabilityAccounts() { var repository = MockRepository.GenerateMock<IRepository>(); var getAccountBalanceForDateCommand = MockRepository.GenerateMock<IGetAccountBalanceForDateCommand>(); var date = DateTime.Today.AddDays(1); const decimal assetAccountBalance = 100; const decimal liabilityAccountBalance = 20; var assetAccount = new AssetAccount { Name = "some asset account" }; var liabilityAccount = new LiabilityAccount { Name = "some liability account" }; var expenseAccount = new ExpenseAccount { Name = "some expense account" }; var incomeAccount = new IncomeAccount { Name = "some income account" }; var accounts = new List<Account> { assetAccount, liabilityAccount, expenseAccount, incomeAccount }; repository.Stub(x => x.Get<Account>()).Return(accounts); getAccountBalanceForDateCommand.Stub(x => x.Execute(assetAccount.Id, date)).Return(assetAccountBalance); getAccountBalanceForDateCommand.Stub(x => x.Execute(liabilityAccount.Id, date)).Return(liabilityAccountBalance); var command = new GetAccountBalancesCommand(repository, getAccountBalanceForDateCommand); var result = command.Execute(date); Assert.That(result.Count(), Is.EqualTo(2)); Assert.That(result.Any(x => (x.AccountName == assetAccount.Name) && (x.Balance == assetAccountBalance)), Is.True); Assert.That(result.Any(x => (x.AccountName == liabilityAccount.Name) && (x.Balance == liabilityAccountBalance)), Is.True); }
public void Create_ShouldSaveTransactionToRepository() { const decimal amount = 100; var date = DateTime.Today.AddDays(1); const string comments = "something"; var incomeAccount = new IncomeAccount(); var assetAccount = new AssetAccount(); var model = new CreateModel(); model.Amount = amount; model.Date = date; model.Comments = comments; model.SelectedIncomeAccountId = incomeAccount.Id; model.SelectedAssetAccountId = assetAccount.Id; _repository.Stub(x => x.Find<Account>(incomeAccount.Id)).Return(incomeAccount); _repository.Stub(x => x.Find<Account>(assetAccount.Id)).Return(assetAccount); _repository.Expect(x => x.Save(Arg<IncomeTransaction>.Matches( y => (y.Date == date) && (y.Comments == comments) && (y.Entries.Count == 2) && (y.Entries.Any(z => (z.Account.Id == incomeAccount.Id) && (z.Amount == amount) && (z.Type == EntryType.Credit))) && (y.Entries.Any(z => (z.Account.Id == assetAccount.Id) && (z.Amount == amount) && (z.Type == EntryType.Debit)))))).Return(null); var controller = GetController(); controller.Create(model); _repository.VerifyAllExpectations(); }
public void Create_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 }; _repository.Stub(x => x.Get<Account>()).Repeat.Times(2).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.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(incomeAccount1.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(assetAccount1.Id)); Assert.That(viewModel.Date, Is.EqualTo(DateTime.Today)); Assert.That(viewModel.Amount, Is.EqualTo(0)); Assert.That(viewModel.Comments, Is.Null); }
public void CanSaveAndGet() { var account = new IncomeAccount(); account.Name = "some name"; Repository.Save(account); var retrieved = Repository.Find<IncomeAccount>(account.Id); Assert.That(retrieved, Is.Not.Null); Assert.That(retrieved.Id, Is.EqualTo(account.Id)); Assert.That(retrieved.Name, Is.EqualTo(account.Name)); }
public void Delete_ShouldDeleteFromRepository() { var id = Guid.NewGuid(); var account = new IncomeAccount(); _repository.Stub(x => x.Find<Account>(id)).Return(account); _repository.Expect(x => x.Delete(account)); var controller = GetController(); controller.Delete(id); _repository.VerifyAllExpectations(); }
public void CanSaveAndGetEntries() { var account = new IncomeAccount(); account.Name = "some name"; Repository.Save(account); var entry1 = SaveEntry(account); var entry2 = SaveEntry(account); var retrieved = Repository.Find<IncomeAccount>(account.Id); Assert.That(retrieved, Is.Not.Null); Assert.That(retrieved.Entries.Count, Is.EqualTo(2)); Assert.That(retrieved.Entries.SingleOrDefault(x => x.Id == entry1.Id), Is.Not.Null); Assert.That(retrieved.Entries.SingleOrDefault(x => x.Id == entry2.Id), Is.Not.Null); }
public void Create_ShouldReturnRedirectToIndex() { var incomeAccount = new IncomeAccount(); var assetAccount = new AssetAccount(); var model = new CreateModel(); model.SelectedIncomeAccountId = incomeAccount.Id; model.SelectedAssetAccountId = assetAccount.Id; _repository.Stub(x => x.Find<Account>(incomeAccount.Id)).Return(incomeAccount); _repository.Stub(x => x.Find<Account>(assetAccount.Id)).Return(assetAccount); var controller = GetController(); var result = (RedirectToRouteResult)controller.Create(model); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); Assert.That(result.RouteValues["controller"], Is.EqualTo("Transaction")); }
public void Configure_ShouldSetPropertiesAsExpected() { const decimal amount = 100; var date = DateTime.Today.AddDays(1); const string comments = "something"; var incomeAccount = new IncomeAccount(); var assetAccount = new AssetAccount(); var transaction = new IncomeTransaction(); transaction.Configure(amount) .ForDate(date) .WithComments(comments) .IncomeAccount(incomeAccount) .AccountToDebit(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.Credit) && (x.Account == incomeAccount)), Is.True); Assert.That(transaction.Entries.Any(x => (x.Amount == amount) && (x.Type == EntryType.Debit) && (x.Account == assetAccount)), Is.True); }
public Account Create(AccountType type) { Account account = null; switch (type) { case AccountType.Asset: account = new AssetAccount(); break; case AccountType.Income: account = new IncomeAccount(); break; case AccountType.Expense: account = new ExpenseAccount(); break; case AccountType.Liability: account = new LiabilityAccount(); break; } return account; }
public void AccountType_ShouldReturnExpense() { var account = new IncomeAccount(); Assert.That(account.AccountType, Is.EqualTo(AccountType.Income)); }
public void Edit_ShouldSaveAccountToRepository() { var id = Guid.NewGuid(); const string newName = "some other name"; var model = new EditModel { Id = id, Name = newName }; var account = new IncomeAccount { Id = id }; _repository.Stub(x => x.Find<Account>(id)).Return(account); _repository.Expect(x => x.Save( Arg<Account>.Matches(y => (y.Id == id) && (y.Name == newName)))).Return(account); var controller = GetController(); controller.Edit(model); _repository.VerifyAllExpectations(); }
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)); }