public void TestLoadHistoricalDataWithQuote()
        {
            _hist     = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
            _lasttime = _timenow - 10000 * _interval;

            //download 700 bars and save to first file
            var r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            var quote = _hist.Load(_symbol, _interval, 0, 1000);

            Assert.IsTrue(quote != null && quote.Count == 700);

            //download 700 bars and save to first file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 1000);

            //download 700 bars and save to 2nd file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 700);

            //download 700 bars and save to 2nd file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 1000);
        }
        public void TestUpdateHistoricalDataNoQuoteFilesWithDownloadFail()
        {
            _count = -1; // download return null
            var r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;

            Assert.IsFalse(r);
        }
        public void TestUpdateHistoricalDataWithExistingQuoteFilesDownloadSuccess()
        {
            //create quote file and save to folder
            var filename = this.GetQuoteFileName(_symbol, _interval, 0);
            var q        = new QuoteBasicBase(_symbol, _interval) as IQuoteBasicBase;
            var ts1      = _timenow - 10000 * _interval;

            for (int j = 0; j < 700; j++)
            {
                q.AddUpdate(ts1 + j * _interval, 0, 0, 0, 0, 0);
            }
            q.SaveToFile(filename);

            _lasttime = q.LastTime + _interval;
            _hist     = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
            var fn = string.Empty;

            _hist.OnQuoteSaved += (object sender, string exch, string file) => fn = file;

            //append to the existing quote file
            var r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;

            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 0));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 1400);

            //since the number is larger than maxNumbars, a new file is created
            r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 1));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 700);

            r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 1));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 1400);
        }