Files
zszq-trs/UnitTestProject/Modules/EodModule/EodCurrencyRateServiceTest.cs
2024-05-09 14:06:26 +08:00

65 lines
2.4 KiB
C#

namespace YLErp.Modules.EodModule
{
[TestClass]
public class EodCurrencyRateServiceTest
{
[TestMethod]
public void TestGetEodCurrencyRate()
{
using (var db = DbContextFactory.GetYLDbContext())
{
db.Database.ExecuteSqlRaw("delete from eod_currency_rate where ValueDate<='1971-01-01'");
var rate1 = 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] = rate1;
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 service = new EodCurrencyRateService(OptUserInfo.SystemUser);
var rate = service.GetEodCurrencyRate("USD", "CNH", new DateTime(1970, 12, 31));
Assert.IsTrue(rate != null && rate.Rate == 6.45);
service.GetEodCurrencyRate("USD", "CNH", new DateTime(1970, 12, 31), true);
Assert.IsTrue(rate != null && rate.Rate == 6.45);
rate = service.GetEodCurrencyRate("CNH", "USD", new DateTime(1970, 12, 31));
Assert.IsTrue(rate != null && rate.Rate == 1 / 6.45);
rate = service.GetEodCurrencyRate("CNH", "USD", new DateTime(1970, 12, 31), true);
Assert.IsTrue(rate != null && rate.Rate == 1 / 6.45);
rate = service.GetEodCurrencyRate("USD", "CNY", new DateTime(1970, 12, 31));
Assert.IsTrue(rate == null);
rate = service.GetEodCurrencyRate("USD", "CNY", new DateTime(1970, 12, 31), true);
Assert.IsTrue(rate == null);
rate = service.GetEodCurrencyRate("USD", "CNH", new DateTime(1970, 12, 1), true);
Assert.IsTrue(rate == null);
}
}
}