Ejemplo n.º 1
0
        public async Task GetExchangeRateAsync_Should_Return_Correct_Exchange_Rate_With_Markup()
        {
            // arrange
            var exchangeRateResponse = new ExchangeRateResponse {
                DestinationCountry = "IN", SourceCountry = "US", ExchangeRate = 1.0m
            };

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

            _mockMarkupRepository.GetMarkupPercentageAsync("US", "IN", _cxlToken)
            .Returns(Task.FromResult(5m));

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

            // assert
            Assert.AreEqual(0.95, result);
        }
Ejemplo n.º 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);
        }