2017-09-13 15:47:34 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-09-15 16:06:57 +09:00
|
|
|
|
namespace BTCPayServer.Services.Rates
|
2017-09-13 15:47:34 +09:00
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class MockRateProvider : IRateProvider
|
|
|
|
|
{
|
|
|
|
|
List<Rate> _Rates;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public MockRateProvider(params Rate[] rates)
|
|
|
|
|
{
|
|
|
|
|
_Rates = new List<Rate>(rates);
|
|
|
|
|
}
|
|
|
|
|
public MockRateProvider(List<Rate> rates)
|
|
|
|
|
{
|
|
|
|
|
_Rates = rates;
|
|
|
|
|
}
|
|
|
|
|
public Task<decimal> GetRateAsync(string currency)
|
|
|
|
|
{
|
|
|
|
|
var rate = _Rates.FirstOrDefault(r => r.Currency.Equals(currency, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
if (rate == null)
|
|
|
|
|
throw new RateUnavailableException(currency);
|
|
|
|
|
return Task.FromResult(rate.Value);
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public Task<ICollection<Rate>> GetRatesAsync()
|
|
|
|
|
{
|
|
|
|
|
ICollection<Rate> rates = _Rates;
|
|
|
|
|
return Task.FromResult(rates);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|