using System.Security.Cryptography; namespace YLErp.Modules.AppModule { [TestClass] public class InitEodPriceTest { [TestMethod("eod_commodity_future_price")] public void Test_eod_commodity_future_price() { using var yldb = DbContextFactory.GetYLDbContext(); var underlyingCode = "RB2512"; var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode); Assert.IsNotNull(underlying, "标的数据不存在"); var basePrice = 5000; var updownStep = 400; var startDate = new DateTime(2022, 1, 1); var endDate = new DateTime(2024, 1, 1); var sql = $@"delete from eod_commodity_future_price where FutureContractId='{underlyingCode}' and ValueDate between '{startDate:yyyy-MM-dd}' and '{endDate:yyyy-MM-dd}';"; yldb.Database.ExecuteSqlRaw(sql); for (var date = startDate; date < endDate; date = date.AddDays(1)) { var dayOfWeek = date.DayOfWeek; if (dayOfWeek == DayOfWeek.Sunday || dayOfWeek == DayOfWeek.Saturday) { continue; } var price = basePrice + RandomNumberGenerator.GetInt32(-updownStep, updownStep); yldb.eod_commodity_future_price.Add(new eod_commodity_future_price { ClosePrice = price, DataSource = "测试", HighPrice = price * 1.03, LowPrice = price * 0.97, SettlePrice = price, ReferencePrice = price, OptDate = DateTime.Now, OptId = 0, OptName = "测试", UnderlyingCode = underlyingCode, UnderlyingId = underlying.id, ValueDate = date }); } var changes = yldb.SaveChanges(); Assert.IsTrue(changes > 20); } [TestMethod("eod_stock_price")] public void Test_eod_stock_price() { using var yldb = DbContextFactory.GetYLDbContext(); var underlyingCode = "000001.SZ"; var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode); Assert.IsNotNull(underlying, "标的数据不存在"); var startDate = new DateTime(2022, 1, 1); var endDate = new DateTime(2024, 1, 1); var sql = $@"delete from eod_stock_price where StockId='{underlyingCode}' and ValueDate between '{startDate:yyyy-MM-dd}' and '{endDate:yyyy-MM-dd}';"; yldb.Database.ExecuteSqlRaw(sql); var price = 18d; var updownStep = 10; for (var date = startDate; date < endDate; date = date.AddDays(1)) { var dayOfWeek = date.DayOfWeek; if (dayOfWeek == DayOfWeek.Sunday || dayOfWeek == DayOfWeek.Saturday) { continue; } price += RandomNumberGenerator.GetInt32(-updownStep, updownStep)/10d; yldb.eod_stock_price.Add(new eod_stock_price { ClosePrice = price, DataSource = "测试", HighPrice = price * 1.03, LowPrice = price * 0.97, SettlePrice = price, ReferencePrice = price, OptDate = DateTime.Now, OptId = 0, OptName = "测试", UnderlyingCode = underlyingCode, ValueDate = date, UnderlyingStatus = "正常" }); } var changes = yldb.SaveChanges(); Assert.IsTrue(changes > 20); } } }