Esempio n. 1
0
        public void TestRollingIndexSkip()
        {
            const int size = 10;

            const int testSize = 25;

            var rollingIndex = new RollingIndex <string>(size);

            var items = new List <string>();
            int i;

            for (i = 0; i < testSize; i++)
            {
                var item = $"item {i}";

                rollingIndex.Add(item, i);

                items.Add(item);
            }


            var(_, err) = rollingIndex.Get(0);
            Assert.Equal(StoreErrorType.TooLate, err.StoreErrorType);

            // 1

            var skipIndex1 = 9;

            var expected1 = items.Skip(skipIndex1 + 1).ToArray();

            var(cached1, err1) = rollingIndex.Get(skipIndex1);
            Assert.Null(err1);


            var convertedItems = new List <string>();

            foreach (var it in cached1)
            {
                convertedItems.Add(it);
            }
            convertedItems.ToArray().ShouldCompareTo(expected1);

            // 2

            var skipIndex2 = 15;

            var expected2 = items.Skip(skipIndex2 + 1).ToArray();

            var(cached2, err2) = rollingIndex.Get(skipIndex2);
            Assert.Null(err2);

            convertedItems = new List <string>();
            foreach (var it in cached2)
            {
                convertedItems.Add(it);
            }
            convertedItems.ToArray().ShouldCompareTo(expected2);

            // 3

            var skipIndex3 = 27;

            string[] expected3 = { };
            var(cached3, err3) = rollingIndex.Get(skipIndex3);

            Assert.Null(err3);

            convertedItems = new List <string>();
            foreach (var it in cached3)
            {
                convertedItems.Add(it);
            }
            convertedItems.ToArray().ShouldCompareTo(expected3);
        }