Esempio n. 1
0
 public CommandInterpreter(RepositoryBag repositories, CommandLibrary library)
 {
     Repositories = repositories;
     Commands     = library;
 }
Esempio n. 2
0
 /// <summary>
 /// New Command constructor
 /// </summary>
 protected CommandActionBase(string rawText, RepositoryBag repositories)
 {
     RawText      = rawText;
     Repositories = repositories;
 }
Esempio n. 3
0
 public HelpCommand(string rawText, RepositoryBag repositories, ICommandRoot helpTarget) : base(rawText, repositories)
 {
     HelpTarget = helpTarget;
 }
Esempio n. 4
0
 public static Transaction FromDto(TransactionDto dto, RepositoryBag repositories)
 {
     return(new Transaction(dto.Id.Value, dto.Timestamp, dto.SourceAccountId, dto.DestinationAccountId, new Money(dto.TransferAmount, true), dto.Memo, repositories));
 }
Esempio n. 5
0
        public void TestAddAccountActionExecute_PastState()
        {
            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    = 123,
                    Description = "account1 description",
                    CategoryId  = null
                };

                UpsertAccount(account1, repositories);

                DateTime        state1Timestamp = DateTime.Today.AddDays(-100);
                AccountStateDto accountState    = new AccountStateDto()
                {
                    AccountId = account1.Id.Value,
                    Funds     = (new Money(100)).InternalValue,
                    IsClosed  = false,
                    Timestamp = state1Timestamp
                };
                accountStateRepo.Upsert(accountState);

                DateTime        state2Timestamp = DateTime.Today.AddDays(-500);
                AccountStateDto accountState2   = new AccountStateDto()
                {
                    AccountId = account1.Id.Value,
                    Funds     = (new Money(200)).InternalValue,
                    IsClosed  = false,
                    Timestamp = state2Timestamp
                };
                accountStateRepo.Upsert(accountState2);

                DetailAccountCommand action = new DetailAccountCommand("detail account account1", repositories);
                action.NameOption.SetData("account1");
                action.DateOption.SetData(state1Timestamp.AddDays(-1)); //Latest state should be at timestamp2

                ReadDetailsCommandResult <Account> result       = null;
                Mock <ICommandActionListener>      mockListener = new Mock <ICommandActionListener>();
                mockListener.Setup(x => x.OnCommand(It.IsAny <ReadDetailsCommandResult <Account> >())).Callback <ReadDetailsCommandResult <Account> >((y) => { result = y; });

                //Act
                bool successful = action.TryExecute(mockLog.Object, new [] { mockListener.Object });

                //Assert
                Assert.True(successful);
                Assert.NotNull(result);
                Assert.Equal(account1.Id, result.Item.Id);
                Assert.Equal(200, result.Item.CurrentState.Funds);
            }
        }
Esempio n. 6
0
 public AccountState(long id, long accountId, Money funds, DateTime timestamp, bool isClosed, RepositoryBag repositories)
 {
     if (repositories == null)
     {
         throw new ArgumentNullException(nameof(repositories));
     }
     Id           = id;
     AccountId    = accountId;
     Funds        = funds;
     Timestamp    = timestamp;
     IsClosed     = isClosed;
     Repositories = repositories;
 }
Esempio n. 7
0
 public static Account FromDto(AccountDto dto, DateTime date, RepositoryBag repositories)
 {
     return(new Account(dto.Id.Value, dto.Name, dto.CategoryId, dto.Priority, dto.AccountKind, dto.Description, date, repositories));
 }
        public void TestDeleteAccountActionExecute_WithListeners()
        {
            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 accountDto = new AccountDto()
                {
                    AccountKind = Data.Enums.AccountKind.Sink,
                    CategoryId  = null,
                    Description = "test account",
                    Name        = "Test Account",
                    Priority    = 5
                };
                bool isInsertSuccessful = repo.Upsert(accountDto);
                long accountId          = accountDto.Id.Value;

                int             accountCountBeforeDelete = repo.GetAll().Count();
                AccountStateDto stateDto = new AccountStateDto()
                {
                    AccountId = accountId,
                    Funds     = 0,
                    Timestamp = DateTime.Now,
                    IsClosed  = false
                };
                isInsertSuccessful &= accountStateRepo.Upsert(stateDto);
                int stateCountBeforeDelete = accountStateRepo.GetAll().Count();


                DeleteAccountCommand action = new DeleteAccountCommand("rm account \"Test Account\"", repositories);
                action.AccountName.SetData("Test Account");
                action.IsRecursiveOption.SetData(false);

                Mock <ICommandActionListener> mockListener = new Mock <ICommandActionListener>();
                mockListener.Setup(x => x.OnCommand(It.Is <DeleteCommandResult <Account> >(a => a.IsSuccessful && a.DeletedItems.Count() == 1 && a.DeletedItems.First().Name.Equals("Test Account")))).Verifiable();

                List <ICommandActionListener> listeners = new List <ICommandActionListener>();
                listeners.Add(mockListener.Object);

                //Act
                bool successful = action.TryExecute(mockLog.Object, listeners);

                int accountCountAfterDelete = repo.GetAll().Count();
                int stateCountAfterDelete   = accountStateRepo.GetAll().Count();

                bool isClosed = accountStateRepo.GetLatestByAccountId(accountId).IsClosed;

                //Assert
                Assert.True(isInsertSuccessful);
                Assert.True(successful);
                Assert.Equal(1, accountCountBeforeDelete);
                Assert.Equal(1, accountCountAfterDelete);
                Assert.Equal(1, stateCountBeforeDelete);
                Assert.Equal(2, stateCountAfterDelete);
                Assert.True(isClosed);

                mockListener.VerifyAll();
            }
        }
Esempio n. 9
0
        public void TestAccountPropertyValues()
        {
            using (var testDbInfo = SetupUtil.CreateTestDb())
            {
                //Arrange
                Mock <ILog>            mockLog   = new Mock <ILog>();
                AccountRepository      repo      = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object);
                AccountStateRepository stateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object);

                long        id;
                string      name        = "Test Account";
                long        priority    = 7;
                long?       categoryId  = null;
                string      description = "description";
                AccountKind accountKind = AccountKind.Source;

                Money    initialFunds = 123.45;
                DateTime timestamp    = DateTime.Now;

                AccountDto accountDto = new AccountDto()
                {
                    Name        = name,
                    Priority    = priority,
                    Description = description,
                    CategoryId  = categoryId,
                    AccountKind = accountKind,
                };
                repo.Upsert(accountDto);
                id = accountDto.Id.Value;

                AccountStateDto stateDto = new AccountStateDto()
                {
                    AccountId = id,
                    Funds     = initialFunds.InternalValue,
                    IsClosed  = false,
                    Timestamp = timestamp,
                };
                stateRepo.Upsert(stateDto);


                RepositoryBag repositories = SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, repo, stateRepo);

                //Act
                Account account = new Account(accountDto.Id.Value, accountDto.Name, accountDto.CategoryId, accountDto.Priority, accountDto.AccountKind, accountDto.Description, timestamp, repositories);

                var propertyValues = account.GetPropertyValues().ToList();

                AccountState state = DtoToModelTranslator.FromDto(stateDto, repositories);

                //Assert
                Assert.Equal(7, propertyValues.Count);

                Assert.Equal(id, propertyValues.First(x => x.Property.Equals(Account.PROP_ID)).Value);
                Assert.Equal(name, propertyValues.First(x => x.Property.Equals(Account.PROP_NAME)).Value);
                Assert.Equal(description, propertyValues.First(x => x.Property.Equals(Account.PROP_DESCRIPTION)).Value);
                Assert.Equal(accountKind, propertyValues.First(x => x.Property.Equals(Account.PROP_ACCOUNT_KIND)).Value);
                Assert.Equal(null, propertyValues.First(x => x.Property.Equals(Account.PROP_CATEGORY)).Value);
                Assert.Equal(priority, propertyValues.First(x => x.Property.Equals(Account.PROP_PRIORITY)).Value);
                Assert.Equal(state, propertyValues.First(x => x.Property.Equals(Account.PROP_CURRENT_STATE)).Value);
            }
        }
Esempio n. 10
0
 public DetailAccountCommand(string rawText, RepositoryBag repositories) : base(rawText, repositories)
 {
     NameOption = new StringCommandOption(CommandOptionKind.Name);
     DateOption = new DateCommandOption(CommandOptionKind.Date);
 }
Esempio n. 11
0
 public DeleteAccountCommand(string rawText, RepositoryBag repositories) : base(rawText, repositories)
 {
     AccountName       = new StringCommandOption(CommandOptionKind.Name);
     IsRecursiveOption = new BoolCommandOption(CommandOptionKind.Recursive);
 }
Esempio n. 12
0
 /// <summary>
 /// From DTO Constructor
 /// </summary>
 public Account(long id, string name, long?categoryId, long priority, AccountKind accountKind, string description, DateTime date, RepositoryBag repositories)
 {
     if (repositories == null)
     {
         throw new ArgumentNullException(nameof(repositories));
     }
     this.Id           = id;
     this.Name         = name;
     this.CategoryId   = categoryId;
     this.Priority     = priority;
     this.AccountKind  = accountKind;
     this.Description  = description;
     this.CurrentDate  = date;
     this.Repositories = repositories;
 }