Beispiel #1
0
        public void CalculateForeignCurrencyConversionWhenExchangeRatePerSegmentIsNullTest()
        {
            var exchangeRate = new ExchangeRate(
                10,
                5.00m,
                CustomerSegment.RETAIL
                );

            Assert.Throws <ArgumentNullException>(() => exchangeRate.CalculateForeignCurrencyConversion());
        }
Beispiel #2
0
        public void CalculateForeignCurrencyConversionWhenCustomSegmentIsNullTest()
        {
            var exchangeRatePerSegment = ExchangeRatePerSegmentBuilder.ExchangeRatePerSegment;
            var exchangeRate           = new ExchangeRate(
                10,
                5.00m,
                null,
                exchangeRatePerSegment
                );

            Assert.Throws <ArgumentNullException>(() => exchangeRate.CalculateForeignCurrencyConversion());
        }
Beispiel #3
0
        public void CalculateForeignCurrencyConversionWhenCustomerSegmentIsPrivateTest(
            int amount,
            decimal foreignCurrencyConversionRate,
            CustomerSegment customerSegment
            )
        {
            var exchangeRatePerSegment = ExchangeRatePerSegmentBuilder.ExchangeRatePerSegment;
            var exchangeRate           = new ExchangeRate(
                amount,
                foreignCurrencyConversionRate,
                customerSegment,
                exchangeRatePerSegment
                );
            var calculate = exchangeRate.CalculateForeignCurrencyConversion();

            Assert.Equal(
                calculate,
                (amount * foreignCurrencyConversionRate) * (1 + exchangeRatePerSegment.Private)
                );
        }
        public async Task <ExchangeRateResponse> GetForeignCurrencyConversionAsync(ForeignCurrencyConversionRequest request)
        {
            var foreignExchangeRate = await _foreignExchangeRatesService.GetLatestExchangeRateAsync(request.Currency);

            if (foreignExchangeRate == null)
            {
                _domainNotification.AddNotification("ForeignCurrencyConversion", "Foreign Exchange Rates API request error");

                return(null);
            }

            var exchangeRate = new ExchangeRate(
                request.Amount,
                foreignExchangeRate.Rates.BrazilianReal,
                request.CustomerSegment,
                _exchangeRatePerSegment
                );
            var calculateForeignCurrencyConversion = exchangeRate.CalculateForeignCurrencyConversion();

            return(new ExchangeRateResponse(calculateForeignCurrencyConversion));
        }