コード例 #1
0
        public async Task GetExchangeRateAsync_Should_Return_Correct_Exchange_Rate()
        {
            // arrange
            var exchangeRateResponse = new ExchangeRateResponse {
                DestinationCountry = "IN", SourceCountry = "US", ExchangeRate = 70.10m
            };

            _mockProvider.GetExchangeRateAsync("US", "IN", _cxlToken)
            .Returns(Task.FromResult(exchangeRateResponse));

            // act
            var result = await _service.GetExchangeRateAsync("US", "IN", _cxlToken);

            // assert
            Assert.AreEqual(exchangeRateResponse.ExchangeRate, result);
        }
コード例 #2
0
        public async Task <decimal> GetExchangeRateAsync(string fromCountryCode, string toCountryCode, CancellationToken cxlToken)
        {
            if (string.IsNullOrEmpty(fromCountryCode) || string.IsNullOrEmpty(toCountryCode))
            {
                throw new ArgumentNullException("countryCode");
            }

            var exchangeRate = await _provider.GetExchangeRateAsync(fromCountryCode, toCountryCode, cxlToken);

            if (exchangeRate == null)
            {
                throw new Exception("Unable to fetch exchange rate from provider");
            }

            var markup = await _markupRepository.GetMarkupPercentageAsync(fromCountryCode, toCountryCode, cxlToken);

            var markupAmount = exchangeRate.ExchangeRate * markup * 0.01m;

            return(exchangeRate.ExchangeRate - markupAmount);
        }