public void DetailAccountCommand()
        {
            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  = null,
                    Description = "Description",
                    Name        = "Name",
                    Priority    = 5
                });
                stateRepo.Upsert(new Data.Models.AccountStateDto()
                {
                    AccountId = 1,
                    Funds     = 10,
                    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("detail account \"Name\"", out action);

                Assert.True(success);
                Assert.IsType <DetailAccountCommand>(action);

                DetailAccountCommand command = (DetailAccountCommand)action;
                Assert.Equal("Name", command.NameOption.GetValue("N/A"));
                Assert.Null(command.DateOption.GetValue(null));
            }
        }
        public void ListAccountCommand()
        {
            using (var testDbInfo = SetupUtil.CreateTestDb())
            {
                Mock <ILog> mockLog = new Mock <ILog>();

                CommandInterpreter interpreter = new CommandInterpreter(SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object), BudgetCliCommands.BuildCommandLibrary());

                ICommandAction action;
                bool           success = interpreter.TryParseCommand("ls accounts", out action);

                Assert.True(success);
                Assert.IsType <ListAccountCommand>(action);
            }
        }
        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));
            }
        }
        public void AddAccountCommand_WithOptions()
        {
            using (var testDbInfo = SetupUtil.CreateTestDb())
            {
                Mock <ILog> mockLog = new Mock <ILog>();

                CommandInterpreter interpreter = new CommandInterpreter(SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object), BudgetCliCommands.BuildCommandLibrary());

                ICommandAction action;
                bool           success = interpreter.TryParseCommand("new account name -p 4 -c category -d description -f 10 -y Sink", out action);

                Assert.True(success);
                Assert.IsType <AddAccountCommand>(action);

                AddAccountCommand addAccount = (AddAccountCommand)action;
                Assert.Equal("name", addAccount.AccountName.GetValue(null));

                Assert.Equal(4L, addAccount.PriorityOption.GetValue(null));
                Assert.Equal("category", addAccount.CategoryNameOption.GetValue(null));
                Assert.Equal("description", addAccount.DescriptionOption.GetValue(null));
                Assert.Equal(new Money(10), addAccount.FundsOption.GetValue(null));
                Assert.Equal(AccountKind.Sink, addAccount.AccountTypeOption.GetValue(null));
            }
        }