public IEnumerable<StockKLineDto> Post([FromBody]KLineArgs args) { #if DEBUG /*test code for communication * ************************************/ var dto = new StockKLineDto() { Amount = 138887, High = 19.99, Open = 88.88 }; var result = new List<StockKLineDto>(); result.Add(dto); return result; /*test code for communication************************************/ #else var appService = new KLineAppService(); return appService.Get(KLineType.Min60, args.StockCode, args.StartDate, args.EndDate).ToDto(); #endif }
public void TestMethod_Day() { string stockCode_600036 = "600036"; string stockCode_000400 = "000400"; DateTime startTime = new DateTime(2014, 1, 1); DateTime endTime = new DateTime(2015, 12, 31); List<IStockKLine> insertDatas = ExampleStockKLineDay(startTime, endTime).ToList(); //var kLineFileInfos_600036 = DataFiles.GetKLineFileInfo(KLineType.Day, stockCode_600036, startTime, endTime); //List<string> dataFiles_600036 = kLineFileInfos_600036.Select(p=>p.FullPath).ToList(); List<string> dataFiles_600036 = new List<string> { new Day1KLineFile(stockCode_600036).GetFilePath() }; CleanupFiles(dataFiles_600036); //var kLineFileInfos_000400 = DataFiles.GetKLineFileInfo(KLineType.Day, stockCode_000400, startTime, endTime); //List<string> dataFiles_000400 = kLineFileInfos_000400.Select(p => p.FullPath).ToList(); List<string> dataFiles_000400 = new List<string> { new Day1KLineFile(stockCode_000400).GetFilePath() }; CleanupFiles(dataFiles_000400); var appService = new KLineAppService(); #region // 测试插入数据 appService.Add(KLineType.Day, stockCode_600036, insertDatas); Assert.IsTrue(appService.Exists(KLineType.Day, stockCode_600036, insertDatas[insertDatas.Count - 1])); int count = 100; for (int i = 0; i < count; i++) { appService.Add(KLineType.Day, stockCode_000400, insertDatas[i]); } Assert.IsTrue(appService.Exists(KLineType.Day, stockCode_000400, insertDatas[count -1])); #endregion #region // 测试更新数据 List<StockKLineDto> kLineUpdates = GetKLineUpdates(insertDatas); appService.Update(KLineType.Day, stockCode_600036, kLineUpdates); Assert.IsTrue(appService.Exists(KLineType.Day, stockCode_600036, kLineUpdates[0])); StockKLineDto kLineUpdate = insertDatas[0] as StockKLineDto; kLineUpdate.Open = 0; appService.Update(KLineType.Day, stockCode_000400, kLineUpdate); kLineUpdate.Close = 100; appService.Update(KLineType.Day, stockCode_000400, kLineUpdate); Assert.IsTrue(appService.Exists(KLineType.Day, stockCode_000400, kLineUpdate)); #endregion #region // 测试读取数据 var securities_600036 = appService.Get(KLineType.Day, stockCode_600036, insertDatas[0].Time, insertDatas[insertDatas.Count - 1].Time).ToList(); Assert.IsNotNull(securities_600036); Assert.IsTrue(securities_600036.Count == insertDatas.Count); Assert.AreEqual(kLineUpdates[0].Low, securities_600036[0].Low); var securities_000400 = appService.Get(KLineType.Day, stockCode_000400, insertDatas[0].Time, insertDatas[count - 1].Time).ToList(); Assert.IsNotNull(securities_000400); Assert.IsTrue(securities_000400.Count == count); Assert.AreEqual(kLineUpdate.Open, securities_000400[0].Open); Assert.AreEqual(kLineUpdate.Close, securities_000400[0].Close); #endregion #region // 测试删除数据 appService.Delete(KLineType.Day, stockCode_600036, insertDatas); var securities_600036_afterDeleted = appService.Get(KLineType.Day, stockCode_600036, insertDatas[0].Time, insertDatas[insertDatas.Count - 1].Time).ToList(); Assert.IsNotNull(securities_600036_afterDeleted); Assert.IsTrue(securities_600036_afterDeleted.Count == 0); #endregion }