public void ListAccountCommandExecute_PriorityOption() { using (var testDbInfo = SetupUtil.CreateTestDb()) { //Arrange Mock <ILog> mockLog = new Mock <ILog>(); AccountRepository repo = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object); AccountStateRepository accountStateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object); RepositoryBag repositories = SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, repo, accountStateRepo); AccountDto account1 = new AccountDto() { Id = null, AccountKind = AccountKind.Sink, Name = "account1", Priority = 5, Description = "account1 description", CategoryId = null }; AccountDto account2 = new AccountDto() { Id = null, AccountKind = AccountKind.Sink, Name = "account2", Priority = 10, Description = "account2 description", CategoryId = null }; UpsertAccount(account1, repositories); UpsertAccount(account2, repositories); ListAccountCommand action = new ListAccountCommand("ls accounts", repositories); action.PriorityOption.SetData(new Range <long>(4, 6)); FakeCommandActionListener listener = new FakeCommandActionListener(); //Act bool successful = action.TryExecute(mockLog.Object, new ICommandActionListener[] { listener }); IEnumerable <ReadCommandResult <Account> > results = listener.GetResults <ReadCommandResult <Account> >(); IEnumerable <Account> accounts = results.First().FilteredItems; //Assert Assert.True(successful); Assert.True(listener.OnlyHasType <ReadCommandResult <Account> >()); Assert.Equal(1, results.Count()); Assert.Equal(1, accounts.Count()); Assert.Contains(DtoToModelTranslator.FromDto(account1, DateTime.Today, repositories), accounts); Assert.DoesNotContain(DtoToModelTranslator.FromDto(account2, DateTime.Today, repositories), accounts); } }
private ICommandAction BuildListAccountCommand(string input, CommandUsageMatchData matchData) { ListAccountCommand cmd = new ListAccountCommand(input, Repositories); AccountKind accountType; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_ACCOUNT_TYPE.Arguments[0], out accountType)) { cmd.AccountTypeOption.SetData(accountType); } string categoryName; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_CATEGORY.Arguments[0], out categoryName)) { cmd.CategoryIdOption.SetData(Repositories.AccountRepository.GetIdByName(categoryName)); } string description; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_DESCRIPTION.Arguments[0], out description)) { cmd.DescriptionOption.SetData(description); } string name; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_ACCOUNT_NAME.Arguments[0], out name)) { cmd.NameOption.SetData(name); } Range <Money> fundsRange; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_FUNDS_RANGE.Arguments[0], out fundsRange)) { cmd.FundsOption.SetData(fundsRange); } Range <long> priorityRange; if (matchData.TryGetArgValue(BudgetCliCommands.OPT_PRIORITY_RANGE.Arguments[0], out priorityRange)) { cmd.PriorityOption.SetData(priorityRange); } return(cmd); }
public void ListAccountCommand_NullListeners() { using (var testDbInfo = SetupUtil.CreateTestDb()) { //Arrange Mock <ILog> mockLog = new Mock <ILog>(); AccountRepository repo = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object); AccountStateRepository accountStateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object); RepositoryBag repositories = SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, repo, accountStateRepo); ListAccountCommand action = new ListAccountCommand("ls accounts", repositories); //Act bool successful = action.TryExecute(mockLog.Object, null); //Passes automatically if no exceptions were thrown } }
public void ListAccountCommandActionKind() { ListAccountCommand action = new ListAccountCommand("ls accounts", SetupUtil.CreateMockRepositoryBag(string.Empty, null)); Assert.Equal(CommandActionKind.ListAccount, action.CommandActionKind); }
public void ListAccountCommand_Options() { using (var testDbInfo = SetupUtil.CreateTestDb()) { Mock <ILog> mockLog = new Mock <ILog>(); AccountRepository repo = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object); AccountStateRepository stateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object); //Id will be 1 repo.Upsert(new Data.Models.AccountDto() { AccountKind = AccountKind.Source, CategoryId = 2, Description = "Description", Name = "Name", Priority = 10 }); stateRepo.Upsert(new Data.Models.AccountStateDto() { AccountId = 1, Funds = 10, IsClosed = false, Timestamp = DateTime.Today }); //Id will be 2 repo.Upsert(new Data.Models.AccountDto() { AccountKind = AccountKind.Category, CategoryId = null, Description = "", Name = "Category", Priority = 5 }); stateRepo.Upsert(new Data.Models.AccountStateDto() { AccountId = 2, Funds = 100, IsClosed = false, Timestamp = DateTime.Today }); //Id will be 3 repo.Upsert(new Data.Models.AccountDto() { AccountKind = AccountKind.Category, CategoryId = null, Description = "", Name = "Category2", Priority = 5 }); stateRepo.Upsert(new Data.Models.AccountStateDto() { AccountId = 3, Funds = 50, IsClosed = false, Timestamp = DateTime.Today }); CommandInterpreter interpreter = new CommandInterpreter(SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, repo, stateRepo), BudgetCliCommands.BuildCommandLibrary()); ICommandAction action; bool success = interpreter.TryParseCommand("list accounts -n Name -c Category -d Description -y Source -p (4,6) -f (90,110)", out action); Assert.True(success); Assert.IsType <ListAccountCommand>(action); ListAccountCommand command = (ListAccountCommand)action; Assert.Equal("Name", command.NameOption.GetValue("N/A")); Assert.Equal("Description", command.DescriptionOption.GetValue("N/A")); Assert.Equal(2L, command.CategoryIdOption.GetValue("N/A")); Assert.Equal(AccountKind.Source, command.AccountTypeOption.GetValue(AccountKind.Sink)); Range <long> expectedPriorityRange = new Range <long>(4, 6, false, false); Range <Money> expectedFundsRange = new Range <Money>(90, 110, false, false); Assert.Equal(expectedFundsRange, command.FundsOption.GetValue(null)); Assert.Equal(expectedPriorityRange, command.PriorityOption.GetValue(null)); } }