Exemplo n.º 1
0
        public void TestMethod_KLine()
        {
            //SQLCEWrapper _sqlCeWrapper = new SQLCEWrapper();
            //_sqlCeWrapper.CreateDatabase();

            //_sqlCeWrapper.CreateKLineTable();
            string filePath = Path.Combine(Environment.CurrentDirectory, "TestKine.sdf");
            if(File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            DateTime startTime = new DateTime(2015, 1, 1);
            DateTime endTime = new DateTime(2015, 12, 31);
            List<IStockKLine> kLines = ExampleStockKLineMin1(startTime, endTime).ToList();
            System.Diagnostics.Debug.Print(string.Format("KLine data count is {0}", kLines.Count));

            KLineRepository repository = new KLineRepository(filePath);
            repository.AddRange(kLines);
            //_sqlCeWrapper.InsertIntoDatas(kLines);

            List<IStockKLine> getKLines = repository.Get(kLines[60].Time, kLines[120].Time).ToList();

            Assert.IsTrue(repository.Exists(kLines[0]));
            Assert.IsFalse(repository.Exists(GetUpdateData(kLines[0].Time.AddYears(1))));

            var updateData = GetUpdateData(kLines[0].Time);

            repository.UpdateRange(new IStockKLine[] { updateData });
            IList<IStockKLine> result0 = repository.GetAll().ToList();

            Assert.IsTrue(repository.Exists(updateData));

            List<IStockKLine> updateKLines = GetUpdateDatas(kLines).ToList();
            repository.UpdateRange(updateKLines);

            //string p_strSQL = "SELECT * FROM KLineTable;";
            //DataSet dataSet = _sqlCeWrapper.SelectDataSet(p_strSQL);
            IList<IStockKLine> result = repository.GetAll().ToList();

            //if (dataSet != null && dataSet.Tables.Count > 0)
            //{
            //    foreach (DataTable table in dataSet.Tables)
            //        System.Diagnostics.Debug.Print(string.Format("table Rows count is {0}", table.Rows.Count));
            //}
            if(result != null && result.Count > 0)
            {
                System.Diagnostics.Debug.Print(string.Format("KLine Data count is {0}", result.Count));
            }
            Assert.AreEqual(kLines.Count, result.Count);

            //_sqlCeWrapper.DeleteDatabase();
        }