コード例 #1
0
        public void Setup()
        {
            formatter = new Mock <IFormatter>();
            formatter.Setup(x => x.Format(It.IsAny <string>())).Returns("5,512");

            var countryCodes = new Dictionary <string, string[]>()
            {
                { "USD", new string[] { "US" } },
                { "CNY", new string[] { "CN" } },
                { "BOB", new string[] { "BO" } }
            };

            var currencyCodes = new Dictionary <string, string>()
            {
                { "US", "USD" },
                { "CN", "CNY" },
                { "BO", "BOB" }
            };

            converter = new Mock <ICurrencyCodeConverter>();
            converter.Setup(x => x.ToCountryCode(It.IsAny <string>()))
            .Returns <string>(code => countryCodes[code]);
            converter.Setup(x => x.ToCurrencyCode(It.IsAny <string>()))
            .Returns <string>(code => currencyCodes[code]);

            display = new CurrencyConverterDisplay(converter.Object);
        }
コード例 #2
0
        public ConverterPanel GetCurrencyConverterPanel()
        {
            //not thread safe
            if (ExchangeRateLoader == null)
            {
                ExchangeRateLoader = new ExchangeRateLoader(_exchangeRateAPIURL);
                ExchangeRateLoader.Load(_exchangeRateAPIKey, new string[0]);
            }

            var currencyConverter     = new CurrencyConverter(ExchangeRateLoader);
            var currencyCodeConverter = new CurrencyCodeConverter(_countryInformation);
            var display = new CurrencyConverterDisplay(currencyCodeConverter);
            var units   = currencyConverter.Rates.Select(rate => rate.Key).ToArray();

            return(GetConverterPanel(currencyConverter, display, units));
        }