Esempio n. 1
0
        public void TestAccountStatePropertyValues()
        {
            using (var testDbInfo = SetupUtil.CreateTestDb())
            {
                //Arrange
                Mock <ILog>            mockLog          = new Mock <ILog>();
                AccountRepository      accountRepo      = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object);
                AccountStateRepository accountStateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object);

                RepositoryBag repositories = SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, accountRepo, accountStateRepo);

                var accountDto = new AccountDto()
                {
                    Name        = "account",
                    Priority    = 5,
                    AccountKind = AccountKind.Sink
                };
                accountRepo.Upsert(accountDto);

                long     accountId = accountDto.Id.Value;
                Money    funds     = 123.45;
                DateTime timestamp = DateTime.Now;
                bool     isClosed  = false;

                AccountStateDto accountStateDto = new AccountStateDto()
                {
                    AccountId = accountId,
                    IsClosed  = isClosed,
                    Funds     = funds.InternalValue,
                    Timestamp = timestamp
                };
                accountStateRepo.Upsert(accountStateDto);

                long id = accountStateDto.Id.Value;


                //Act
                Account      account        = DtoToModelTranslator.FromDto(accountDto, DateTime.Today, repositories);
                AccountState state          = DtoToModelTranslator.FromDto(accountStateDto, repositories);
                var          propertyValues = state.GetPropertyValues().ToList();

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

                Assert.Equal(id, propertyValues.First(x => x.Property.Equals(AccountState.PROP_ID)).Value);
                Assert.Equal(account, propertyValues.First(x => x.Property.Equals(AccountState.PROP_ACCOUNT)).Value);
                Assert.Equal(funds, propertyValues.First(x => x.Property.Equals(AccountState.PROP_FUNDS)).Value);
                Assert.Equal(isClosed, propertyValues.First(x => x.Property.Equals(AccountState.PROP_STATUS)).Value);
                Assert.Equal(timestamp, propertyValues.First(x => x.Property.Equals(AccountState.PROP_TIMESTAMP)).Value);
            }
        }