public virtual void TestSeekTimeStampWrongKind()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            try
            {
                DateTime dateTime = new DateTime(0, DateTimeKind.Local);

                cursor.Seek(dateTime);
                Assert.Fail("Seeking with a date time with local DateTimeKind must fail");
            }
            catch (ArgumentException)
            {
                // ok
            }
            try
            {
                DateTime dateTime = new DateTime(0, DateTimeKind.Unspecified);

                cursor.Seek(dateTime);
                Assert.Fail("Seeking with a date time with unspecified DateTimeKind must fail");
            }
            catch (ArgumentException)
            {
                // ok
            }
        }
        public virtual void TestSeekingMilesAfterEnd()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            TimeSpan fullDistance = DefaultTimeSeries.TimeInterval.EndTime -
                                    DefaultTimeSeries.TimeInterval.StartTime;

            // go into the middle of the timeseries
            cursor.Seek(DefaultTimeSeries.TimeInterval.StartTime + new TimeSpan(fullDistance.Ticks / 2));
            Assert.IsNotNull(cursor.Current);

            // seek will always step to the last valid entry
            cursor.Seek(fullDistance, SeekPosition.CURRENT);
            Assert.IsNotNull(cursor.Current);
            Assert.IsFalse(cursor.MoveNext());
            Assert.IsNull(cursor.Current);
        }
        public void TestSeekTimeSpanSpecialValueAtEnd()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            // show that cursor works as expected for a time series with "normal" values
            cursor.Seek(TimeSpan.FromTicks(-1), SeekPosition.END); // go to second last element
            Assert.IsTrue(cursor.MoveNext());                      // go to last element
            Assert.IsNotNull(cursor.Current);
            Assert.IsFalse(cursor.MoveNext());

            InsertDefaultEntryByTimeStamp(MaximumTimeStamp);

            // show that cursor still works
            cursor.Seek(TimeSpan.FromTicks(-1), SeekPosition.END); // go to second last element
            Assert.IsTrue(cursor.MoveNext());                      // go to last element
            Assert.IsNotNull(cursor.Current);
            Assert.IsFalse(cursor.MoveNext());
        }
        public virtual void TestSeekTimeStamp()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            // seek time stamp shall return the entry with the correct time stamp
            foreach (long timeStamp in DefaultTimeStamps)
            {
                cursor.Seek(DateTimeHelper.ToDateTime(timeStamp));
                Assert.AreEqual(timeStamp, DateTimeHelper.ToLong(cursor.Current.TimeStamp));
            }

            // seek time stamp shall return the entry with the next smaller time stamp
            foreach (long timeStamp in DefaultTimeStamps)
            {
                cursor.Seek(DateTimeHelper.ToDateTime(timeStamp + 1));
                Assert.AreEqual(timeStamp, DateTimeHelper.ToLong(cursor.Current.TimeStamp));
            }
        }
        public virtual void TestSeekingMilesBeforeBegin()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            TimeSpan fullDistance = DefaultTimeSeries.TimeInterval.EndTime -
                                    DefaultTimeSeries.TimeInterval.StartTime;

            // go into the middle of the timeseries
            cursor.Seek(DefaultTimeSeries.TimeInterval.StartTime + new TimeSpan(fullDistance.Ticks / 2));
            Assert.IsNotNull(cursor.Current);

            // you cannot reach a valid entry far before the beginning
            cursor.Seek(-fullDistance, SeekPosition.CURRENT);
            Assert.IsNull(cursor.Current);

            // one step must be enough to get to the first entry
            Assert.IsTrue(cursor.MoveNext());
            Assert.IsNotNull(cursor.Current);
        }
        public virtual void TestSeekTimeStampBeforeStart()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            Assert.IsTrue(cursor.MoveNext());
            Assert.IsNotNull(cursor.Current);

            // get the first timestamp
            DateTime timeStamp = cursor.Current.TimeStamp;

            // try to seek before the start
            Assert.IsFalse(cursor.Seek(timeStamp - new TimeSpan(100)));
            Assert.IsNull(cursor.Current);
        }
        public virtual void TestSeekTimeStampBehindEnd()
        {
            ITimeSeriesEntryCursor cursor = CreateCursor();

            InsertAllDefaultEntries();

            cursor.SetToEnd();
            Assert.IsNull(cursor.Current);
            Assert.IsTrue(cursor.MovePrevious());
            Assert.IsNotNull(cursor.Current);

            // remember the entry and get its timestamp
            ITimeSeriesEntry timeSeriesEntry = cursor.Current;
            DateTime         timeStamp       = timeSeriesEntry.TimeStamp;

            // try to seek behind the end; will result in pointing to the last entry (see documentation of Seek(TimeStamp))
            Assert.IsTrue(cursor.Seek(timeStamp + new TimeSpan(100)));
            Assert.IsNotNull(cursor.Current);

            // check that we are indeed at the last entry
            Assert.IsTrue(TimeSeriesComparisons.CompareTimeSeriesEntry(timeSeriesEntry, cursor.Current));
        }