Esempio n. 1
0
        public void FilterFxPairs_AlreadyExistingCurrencyInstancesAreUsed()
        {
            //Arrange
            Mock <ICurrencyRepository> mockedRepository = new Mock <ICurrencyRepository>();

            FxPairDto[] dtos = getFxPairsDtos();
            FxPairDto   dto  = dtos[1];

            mockedRepository.Setup(r => r.GetFxPairById(dto.Id)).Returns(dto);
            mockedRepository.Setup(r => r.GetFxPairs(It.IsAny <string>(), It.IsAny <int>())).Returns(dtos);
            injectMockedServiceToCurrency();

            //Act
            ICurrencyService     service = testServiceInstance(mockedRepository);
            FxPair               pair    = service.GetFxPairById(dto.Id);
            IEnumerable <FxPair> pairs   = service.GetFxPairs("a", 3);

            //Assert
            FxPair fromResultCollection = pairs.SingleOrDefault(p => p.GetId() == dto.Id);

            Assert.AreSame(fromResultCollection, pair);

            //Clear
            Currency.RestoreDefaultService();
        }
Esempio n. 2
0
        private Mock <ICurrencyRepository> mockedCurrencyRepositoryForFxPairUnitTests()
        {
            Mock <ICurrencyRepository> mockedRepository = new Mock <ICurrencyRepository>();
            FxPairDto dto = defaultFxPairDto();

            mockedRepository.Setup(c => c.GetFxPairById(DEFAULT_ID)).Returns(dto);
            mockedRepository.Setup(c => c.GetFxPairBySymbol(DEFAULT_PAIR_SYMBOL)).Returns(dto);
            return(mockedRepository);
        }
        public void GetFxPairByName_returnNull_forNonExistingItem()
        {
            //Arrange
            EFCurrencyRepository repository = new EFCurrencyRepository();
            FxPairDto            baseDto    = getDefaultFxPairDto();

            insertFxPairToTestDb(baseDto);

            //Act
            FxPairDto dto = repository.GetFxPairBySymbol(baseDto.Name + "a");

            //Assert
            Assert.IsNull(dto);
        }
Esempio n. 4
0
        public void GetFxPairBySymbol_ReturnsNull_IfDoesntExist()
        {
            //Arrange
            Mock <ICurrencyRepository> mockedRepository = new Mock <ICurrencyRepository>();
            FxPairDto dto = null;

            mockedRepository.Setup(c => c.GetFxPairBySymbol(DEFAULT_PAIR_SYMBOL)).Returns(dto);

            //Act
            ICurrencyService service = testServiceInstance(mockedRepository);
            FxPair           pair    = service.GetFxPairBySymbol(DEFAULT_PAIR_SYMBOL);

            //Assert
            Assert.IsNull(pair);
        }
        public void GetFxPairByName_returnProperDto_forExistingItem()
        {
            //Arrange
            EFCurrencyRepository repository = new EFCurrencyRepository();
            FxPairDto            baseDto    = getDefaultFxPairDto();

            insertFxPairToTestDb(baseDto);

            //Act
            FxPairDto dto = repository.GetFxPairBySymbol(baseDto.Name);

            //Assert
            var areEqual = baseDto.Equals(dto);

            Assert.IsTrue(areEqual);
        }
        private void insertFxPairToTestDb(FxPairDto pair)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Name, BaseCurrency, QuoteCurrency, IsActive) VALUE({2}, {3}, {4}, {5}, {6})";
            string       insertSql          = string.Format(INSERT_SQL_PATTERN,
                                                            UNIT_TEST_DB_NAME, FX_PAIRS_TABLE_NAME,
                                                            pair.Id, pair.Name.ToDbString(),
                                                            pair.BaseCurrency, pair.QuoteCurrency,
                                                            pair.IsActive.ToDbString());

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, FX_PAIRS_TABLE_NAME);
                context.Database.ExecuteSqlCommand(insertSql);
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Esempio n. 7
0
        public void fxPair_fromDto_hasCorrectProperties()
        {
            //Arrange.
            injectMockedServiceToCurrency();

            //Act.
            FxPairDto dto = new FxPairDto {
                Id            = DEFAULT_ID,
                Name          = DEFAULT_SYMBOL,
                BaseCurrency  = DEFAULT_BASE_CURRENCY_ID,
                QuoteCurrency = DEFAULT_QUOTE_CURRENCY_ID,
                IsActive      = DEFAULT_IS_ACTIVE
            };
            var pair = FxPair.FromDto(dto);

            //Assert.
            Assert.AreEqual(DEFAULT_ID, pair.GetId());
            Assert.AreEqual(DEFAULT_SYMBOL, pair.GetName());
            Assert.AreSame(Currency.ById(1), pair.GetBaseCurrency());
            Assert.AreSame(Currency.ById(2), pair.GetQuoteCurrency());

            //Clear
            Currency.RestoreDefaultService();
        }