public static IEnumerable <Exchange> RetrieveExchanges(DateTime dateToRetrieve, string targetCurrencyCode) { Trace.WriteLine("Call to OpenExchangeRates to retrieve a date: " + dateToRetrieve); OpenExchangeRatesServer.Response oerResponse = OpenExchangeRatesServer.GetResponse(dateToRetrieve, AppIdKeepSecret); var exchangesOfDate = new List <Exchange>(oerResponse.Rates.Count); foreach (var rateKvPair in oerResponse.Rates) { var exchange = new Exchange() { Date = dateToRetrieve, CurrencyCode = rateKvPair.Key, Rate = rateKvPair.Value }; exchangesOfDate.Add(exchange); } return(exchangesOfDate); }
public void GetResponse_DNS_Failure_Throws_Appropriate_Exception() { OpenExchangeRatesServer.GetResponse("http://nonExistantName.nonExistant"); }
public void GetResponse_Timeout_Throws_Appropriate_Exception() { OpenExchangeRatesServer.GetResponse("http://localhost", new TimeSpan(1)); }
private static void InvokeGetResponseWith(int statusCode, string responseMessage = "This is a default test message.") { OpenExchangeRatesServer.IHttpClient client = new HttpClientMock(statusCode, responseMessage); OpenExchangeRatesServer.GetResponse(client, "http://forTesting"); }