示例#1
0
        public void WhenDataSourceInvalid_ThrowsRatesSyncException()
        {
            var rateService = new RateService(new MockFExConfig {
                DataSource = RateDataSource.Unset
            }, new Mock <ILoggingService>().Object, Guid.NewGuid());

            Assert.Throws <RateSyncException>(() => rateService.GetRates("blah"));
        }
示例#2
0
        public void WhenDataSourceHMRC_ReturnsRates()
        {
            var rateService = new RateService(new MockFExConfig {
                DataSource = RateDataSource.Hmrc
            }, new Mock <ILoggingService>().Object, Guid.NewGuid());
            var result = rateService.GetRates("blah");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Items.Count, Is.GreaterThan(1));
            Assert.That(result.Period, Is.Not.Null);
        }
        public async void Rates_Are_From_Properly_From_QuietStone()
        {
            var service = new RateService(_unitOfWork, _transactionDataProvider.Object, _logger);

            var rates = (await service.GetRates()).ToList();

            var usdToCad = rates.Single(x => x.From == KnownCurrencies.USD && x.To == KnownCurrencies.CAD);

            Assert.Equal(2, rates.Count);
            Assert.Equal(44.5m, usdToCad.Rate);
        }
        public void GetRates_ApplicationException_Test()
        {
            // Arrange
            var exception = new ApplicationException();
            var client = new Mock<IRateClient>();
            client.Setup(t => t.GetRate(DateTime.Today)).Throws(exception);
            var rateService = new RateService(client.Object);

            // Assert
            var ex = Assert.Throws<ApplicationException>(() => rateService.GetRates(Currency.RUB, new[] { DateTime.Today }));
            Assert.AreEqual(ex, exception);
        }
        public void GetRates_Test()
        {
            // Arrange
            var rate = Mock.Of<Rate>();
            var rateResponce = Mock.Of<RateSourceData>(t => t.Parse(Currency.RUB) == rate);
            var client = Mock.Of<IRateClient>(t => t.GetRate(DateTime.Today) == rateResponce);
            var rateService = new RateService(client);

            // Act
            var result = rateService.GetRates(Currency.RUB, new[] { DateTime.Today });

            // Assert
            Assert.AreEqual(result.Single(), rate);
        }
        public async void Rates_Are_From_DB_If_QuietStone_Fail_To_Return_Rates()
        {
            _transactionDataProvider.Setup(x => x.GetRates())
            .Returns(Task.Run(() =>
            {
                throw new GNBException("some fake message", ErrorCode.UnableToRetrieveRatesFromQuietStone);
                return(new List <Rate>());
            }));

            var service = new RateService(_unitOfWork, _transactionDataProvider.Object, _logger);

            var rates = (await service.GetRates()).ToList();

            var usdToCad = rates.Single(x => x.From == KnownCurrencies.USD && x.To == KnownCurrencies.CAD);

            Assert.Equal(3, rates.Count);
            Assert.Equal(10.5m, usdToCad.Rate);
        }
示例#7
0
        public void Execute()
        {
            trace.Trace(TraceEventType.Information, (int)EventId.StartingRateSync, "Syncing Rates");

            trace.Trace(TraceEventType.Information, (int)EventId.GettingRatesFromApi, "Getting Rates from API");
            var rates = rateService.GetRates(GetOrganisationUniqueName());

            trace.Trace(TraceEventType.Information, (int)EventId.GettingCurrenciesFromCrm, "Getting Currencies from CRM");
            var currencies = repo.GetCurrencies();

            trace.Trace(TraceEventType.Information, (int)EventId.SyncingCurrencies, "Sync Currencies with Latest Rate Date");
            currencies = rateSyncer.Sync(currencies, rates);

            trace.Trace(TraceEventType.Information, (int)EventId.SavingCurrencies, "Saving updated currencies to CRM");
            repo.SaveCurrencies(currencies);

            new JobCompleter(organisationService, config, trace).Complete(trace.HasWarnings
                                ? RunStatus.Warning
                                : RunStatus.Success);
        }