using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using YLErp.BLL; using YLErp.DBModels; namespace YLErp.Modules.DataProviderModule { [TestClass] public class ExchangeOptionPriceProviderTest : YLUnitTestBase { [TestMethod] public void TestGetPrice() { var valueDate = valuedateBLL.ValueDate; const string optionCode = "RBTest-P-2650"; var insertModel = new ExchangeListOption { ContractCode = optionCode, ContractSize = 10, CreateTime = DateTime.Now, ExerciseMode = "European", MarginRate = 0.05, MarketCode = "TEST_TEST", MaturityDate = valueDate.AddMonths(1), OpenDate = valueDate.AddDays(-10), OptionType = "看跌", PrevClosePrice = 12.2, Price = 12.32, PriceTick = 0.1, PriceTime = DateTime.Now, Strike = 2650, UnderlyingCode = "RBTest" }; AddClearSQL($"ContractCode='{optionCode}'"); DbContext.exchange_list_option.Add(insertModel); DbContext.SaveChanges(); var provider = new ExchangeOptionPriceProvider(); var price = provider.GetPrice("RBTest-P-2650"); Assert.AreEqual(price, 12.32); var hasPrice = provider.TryGetPrice(optionCode, out price); Assert.AreEqual(price, 12.32); var priceModel = provider.GetPriceModel("RBTest-P-2650"); Assert.AreEqual(priceModel.Price, 12.32); //场内期权没有取昨日收盘价 provider.TryGetPriceModel("RBTest-P-2650", out priceModel); Assert.AreEqual(priceModel.PreClose, null); } } }