예제 #1
0
        public void ParseCurrenciesSource_WithIncorrectSource_ReturnExpectedException()
        {
            CurrencyParsingService parsingService = new CurrencyParsingService();
            string source = new TestDailySource().IncorectDailySource;

            Assert.That(() => parsingService.ParseCurrenciesSource(source), Throws.Exception);
        }
예제 #2
0
        public void ParseCurrenciesSource_WithProvidedCorrectSource_ReturnExpectedResults()
        {
            string source = new TestDailySource().CorrectSource;

            CurrencyParsingService        parsingService = new CurrencyParsingService();
            HashSet <SingleDayCurrencies> result         = parsingService.ParseCurrenciesSource(source);

            SingleDayCurrencies expected = new SingleDayCurrencies
            {
                Date       = "2020-07-16",
                Currencies = new List <Currency>
                {
                    new Currency
                    {
                        Code  = "USD",
                        Ratio = 1.1414m
                    }
                }
            };

            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result.First().Date, expected.Date);
            Assert.AreEqual(result.First().Currencies.Count, 1);
            Assert.AreEqual(result.First().Currencies.First().Code, expected.Currencies.First().Code);
            Assert.AreEqual(result.First().Currencies.First().Ratio, expected.Currencies.First().Ratio);
        }
        public void TryGetCurrencies_NoDateProvided_ShouldReturnDailyCurrencies()
        {
            ILogger <CurrencyFetchingService> loggerMock             = Mock.Of <ILogger <CurrencyFetchingService> >();
            ICurrencyCachingService           currencyCachingService = Mock.Of <ICurrencyCachingService>();
            ICurrencyParsingService           currencyParsingService = new CurrencyParsingService();
            Mock <IOptions <UrlsConfig> >     urlsConfigMock         = new Mock <IOptions <UrlsConfig> >();
            Mock <IOptions <CacheKeyConfig> > cacheConfigMock        = new Mock <IOptions <CacheKeyConfig> >();

            urlsConfigMock.SetupGet(x => x.Value).Returns(new UrlsConfig
            {
                DailyCurrencies   = _dailyCurrencies,
                CurrenciesHistory = null,
            });

            cacheConfigMock.SetupGet(x => x.Value).Returns(new CacheKeyConfig
            {
                Format = _cacheKeyDateFormat,
            });

            CurrencyFetchingService currencyFetchingService = new CurrencyFetchingService(
                currencyCachingService,
                currencyParsingService,
                loggerMock,
                urlsConfigMock.Object,
                cacheConfigMock.Object
                );

            bool result = currencyFetchingService.TryGetCurrencies(null, out SingleDayCurrencies currencies, out string error);

            Assert.IsTrue(result);
            Assert.IsNull(error);
            Assert.IsTrue(!string.IsNullOrEmpty(currencies.Date));
        }
예제 #4
0
        public void ParseCurrenciesSource_WithNoCurrenciesSource_ShouldReturnEmptyList()
        {
            CurrencyParsingService parsingService = new CurrencyParsingService();
            string source = new TestDailySource().NoCurrenciesSource;
            HashSet <SingleDayCurrencies> result = parsingService.ParseCurrenciesSource(source);

            Assert.IsEmpty(result);
        }
예제 #5
0
        public void ParseCurrenciesSource_NoSourceProvided_ReturnExpectedException()
        {
            CurrencyParsingService parsingService = new CurrencyParsingService();

            Assert.That(() => parsingService.ParseCurrenciesSource(null), Throws.Exception);
        }