示例#1
0
        public void LoadJson_GivePathToJSONFile()
        {
            // Arange
            var       path      = "C:\\Users\\kater\\Documents\\dot-net\\CurrencyExchangeRate\\CurrencyExchangeRate\\Data\\ExchangeRates.json";
            FetchData fetchData = new FetchData();
            //Act
            var result = fetchData.LoadJson(path);

            //Assert
            result.Should().NotBeEmpty();
        }
示例#2
0
        static void Main(string[] args)
        {
            var     path   = "C:\\Users\\kater\\Documents\\dot-net\\CurrencyExchangeRate\\CurrencyExchangeRate\\Data\\ExchangeRates.json";
            ILogger logger = new ConsoleLogger();
            DisplayMessageService displayMessageService = new DisplayMessageService(logger);

            displayMessageService.WriteCommand("Usage: Exchange <currency pair> <amount to exchange>");
            var       userResponse  = displayMessageService.ReadCommand();
            FetchData fetchData     = new FetchData();
            var       exchangeRates = fetchData.LoadJson(path);
            InputProcessingService inputProcessingService = new InputProcessingService();
            ParseInputService      parseInput             = new ParseInputService(inputProcessingService, exchangeRates);
            var userCurrencyInputObject = parseInput.ParseInput(userResponse);
            ExchangeRateCalculationService exchangeRateCalculationService = new ExchangeRateCalculationService();
            var result = exchangeRateCalculationService.CalculateExchangeRate(userCurrencyInputObject);

            displayMessageService.WriteCommand($"The result is {result}");
            displayMessageService.ReadCommand();
        }
        public void ExchangeRateCalculationService_GivenCurrencies_CalculateCorrectExchange(string currencyFrom, string currencyTo, int result)
        {
            //Arange
            var       path                 = "C:\\Users\\kater\\Documents\\dot-net\\CurrencyExchangeRate\\CurrencyExchangeRate\\Data\\ExchangeRates.json";
            FetchData fetchData            = new FetchData();
            var       exchangeRates        = fetchData.LoadJson(path);
            var       currencyExchangeFrom = exchangeRates.Where(c => c.ISO == currencyFrom).FirstOrDefault();
            var       currencyExchangeTo   = exchangeRates.Where(c => c.ISO == currencyTo).FirstOrDefault();
            var       amount               = 2;
            var       userInputObject      = new UserCurrencyInput()
            {
                Amount = amount,
                ExchangeCurrencyFrom = currencyExchangeFrom,
                ExchangeCurrencyTo   = currencyExchangeTo
            };

            //Act
            var rateCalculation = new ExchangeRateCalculationService();
            var rateResult      = rateCalculation.CalculateExchangeRate(userInputObject);

            //Assert
            result.Should().Be(result);
        }