public void history_rate_returns_curreyncy_price_if_history_data_only_for_later_dates() { var usd = new CurrencyData() { Name = "USD", Price = 5 }; var history = new CurrencyRateHistory { CurrencyData = usd, Price = 8, Updated = new DateTime(2014, 1, 1) }; _currency.Save(usd); _currency.SaveHistoryItem(history); var rate = _currency.GetCurrencyHistoricalRate(new DateTime(2012, 1, 1), "USD"); Assert.That(rate, Is.EqualTo(5)); }
private void StoreToDatabaseCurrencyHistory(IEnumerable <CurrencyHistoryData> history) { foreach (var historyData in history) { var currencyName = historyData.CurrencyName; var currency = CurrencyRateRepository.GetCurrencyOrCreate(currencyName); foreach (var hdi in historyData.History.OrderBy(i => i.Date)) { var historyItem = new CurrencyRateHistory { CurrencyData = currency, Price = hdi.Price, Updated = hdi.Date }; currency.LastUpdated = hdi.Date; currency.Price = hdi.Price; CurrencyRateRepository.SaveHistoryItem(historyItem); } } }
} // GetCurrencyHistoricalRate public void SaveHistoryItem(CurrencyRateHistory historyItem) { EnsureTransaction(() => Session.Save(historyItem)); } // SaveHistoryItem