public IExchangePair ArgumentsToExchangePair(string[] args) { var wrongArgumentsException = new Exception("Incorrect argument format.\nUsage - 'Exchange EUR/DKK 12345.6789'\n"); var cultureInfo = new CultureInfo("en-US"); const char currenciesSeperator = '/'; if (args.Length != 2) { throw wrongArgumentsException; } string[] currencies = args[0].Split(currenciesSeperator); // All ISO currency codes are made form 3 letters so this checks if the format is correct if (currencies.Length != 2 || currencies[0].Length != 3 || currencies[1].Length != 3) { throw wrongArgumentsException; } try { var amount = Convert.ToDecimal(args[1], cultureInfo); return(_factory.CreateExchangePair(_factory.CreateCurrency(currencies[0].ToUpper()), _factory.CreateCurrency(currencies[1].ToUpper()), amount)); } catch (FormatException) { throw wrongArgumentsException; } }
public ExchangeRates(IExchangeEntityFactory factory) { _entityFactory = factory; _rates = new Dictionary <ICurrency, decimal>() { { _entityFactory.CreateCurrency("Danske kroner", "DKK"), 100.0m }, //This is the main currency { _entityFactory.CreateCurrency("Euro", "EUR"), 743.94m }, { _entityFactory.CreateCurrency("Amerikanske dollar", "USD"), 663.11m }, { _entityFactory.CreateCurrency("Britiske pund", "GBP"), 852.85m }, { _entityFactory.CreateCurrency("Svenske kroner", "SEK"), 76.10m }, { _entityFactory.CreateCurrency("Norske kroner", "NOK"), 78.40m }, { _entityFactory.CreateCurrency("Schweiziske franc", "CHF"), 683.58m }, { _entityFactory.CreateCurrency("Japanske yen", "JPY"), 5.9740m }, }; }