public double CalculateForeignCurrencyAmount(CurrencyExchangeDirection direction, double localCurrencyAmount, double sellValue, double buyValue)
        {
            double effectiveRate = 0;

            if (direction == CurrencyExchangeDirection.BuyForeign)
            {
                //Client if buying from the market, it will pay the value the market is selling
                effectiveRate = sellValue;
            }
            else if (direction == CurrencyExchangeDirection.SellForeign)
            {
                //Client is selling to the market, it will receive the value the market is buying
                effectiveRate = 1 / buyValue;
            }
            else
            {
                throw new NotImplementedException("Invalid exchange direction!");
            }

            double ForeignCurrencyAmount = localCurrencyAmount / effectiveRate;

            return(ForeignCurrencyAmount);
        }
Exemple #2
0
        public void CalculateForeignCurrencyAmount_Should_Take_Direction_And_Different_Rates_Into_Consideration(CurrencyExchangeDirection direction, double localCurrencyAmount, double sellValue, double buyValue, double expectedAmount)
        {
            //Arrange
            Mock <ICurrencyExchangeTransactionsRepository> mockCcyExchgTransaction = new Mock <ICurrencyExchangeTransactionsRepository>();
            Mock <IRatesRepository> mockRatesRepo           = new Mock <IRatesRepository>();
            CurrencyExchangeService currencyExchangeService = new CurrencyExchangeService(mockCcyExchgTransaction.Object, mockRatesRepo.Object);

            //Act
            double actualAmount = currencyExchangeService.CalculateForeignCurrencyAmount(direction, localCurrencyAmount, sellValue, buyValue);

            //Assert
            Assert.Equal(Math.Round(expectedAmount, 5), Math.Round(actualAmount, 5));
        }