从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
namespace YLErp.Modules.DataProviderModule
|
||||
{
|
||||
[TestClass]
|
||||
public class EodCurrencyProviderTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestGetCurrency()
|
||||
{
|
||||
using (var db = DbContextFactory.GetYLDbContext())
|
||||
{
|
||||
db.Database.ExecuteSqlRaw("delete from eod_currency_rate where ValueDate<='1971-01-01'");
|
||||
var rate = new eod_currency_rate
|
||||
{
|
||||
ValueDate = new DateTime(1970, 12, 31),
|
||||
BuyRate = 6.45,
|
||||
ForeignCurrency = "USD",
|
||||
LocalCurrency = "CNH",
|
||||
OptDate = DateTime.Now,
|
||||
OptId = 0,
|
||||
OptName = "系统",
|
||||
Rate = 6.45,
|
||||
SellRate = 6.45
|
||||
};
|
||||
|
||||
var rates = new eod_currency_rate[5];
|
||||
rates[0] = rate;
|
||||
|
||||
for (var i = 1; i < 5; i++)
|
||||
{
|
||||
var rate2 = rates[i - 1].Clone();
|
||||
rate2.ValueDate = rate2.ValueDate.AddDays(-i * 2);
|
||||
rate2.BuyRate = rate2.SellRate = rate2.Rate -= 0.1;
|
||||
rates[i] = rate2;
|
||||
}
|
||||
|
||||
db.eod_currency_rate.AddRange(rates);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
var provider = new EodCurrencyProvider(new DateTime(1970, 12, 31), false);
|
||||
var bl = provider.TryGetCurrencyRate("usd", "cnh", out var rr);
|
||||
Assert.IsTrue(bl);
|
||||
Assert.AreEqual(rr.Rate, 6.45);
|
||||
|
||||
bl = provider.TryGetCurrencyRate("usd", "cny", out _);
|
||||
Assert.IsFalse(bl);
|
||||
|
||||
provider = new EodCurrencyProvider(new DateTime(1970, 12, 24), true);
|
||||
bl = provider.TryGetCurrencyRate("usd", "cnh", out rr);
|
||||
Assert.IsTrue(bl);
|
||||
Assert.AreEqual(rr.Rate, 6.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user