Exemple #1
0
        public void With69ElementsAndPageSize10_GetAnElementFromEachPageDisposeCollection_AllDisposed(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            const int expected   = 69;
            var       set        = new ConcurrentBag <int>();
            var       collection = DataVirtualizingCollectionFactory.CreateCollectionWithCustomPageFetchingLogic(
                pageLoadingBehavior,
                pageRemovalBehavior,
                fetchersKind,
                indexAccessBehavior,
                expected,
                10,
                (offset, pSize) =>
                Enumerable
                .Range(offset, pSize)
                .Select(i => Disposable.Create(() => set.Add(i)))
                .ToArray(),
                Disposable.Empty);

            // Act
            for (var i = 0; i <= expected; i += 10)
            {
                var _ = collection[i];
            }
            collection.Dispose();

            Thread.Sleep(500);

            // Assert
            Assert.Equal(expected, set.Count);
        }
        public async Task BuildingCollectionWith6969Elements_Offset69SlidingRight_Offset70(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            69,
                            scheduler);

            await collection.InitializationCompleted;

            // Act
            collection.SlideRight();
            var _ = collection[0];
            await Task.Delay(50);

            // Assert
            Assert.Equal(70, collection[0]);
        }
        public async Task BuildingCollectionWith6969Elements_124thEntry_123(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100);

            await collection.InitializationCompleted;

            // Act
            var placeholder = collection[123];
            await Task.Delay(50);

            // Assert
            Assert.Equal(-1, placeholder);
            Assert.Equal(123, collection[123]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset69WindowSize10IncreaseBy2_CountIncreasedLastElement80(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            69,
                            scheduler);

            // Act
            collection.IncreaseWindowSizeBy(2);

            Thread.Sleep(500); // wait for preloading

            // Assert
            Assert.Equal(12, collection.Count);
            Assert.Equal(80, collection[11]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset69WindowSize10Decrease_CountDecreasedLastElement77(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            69,
                            scheduler);

            // Act
            collection.DecreaseWindowSize();

            Thread.Sleep(500); // wait for preloading

            // Assert
            Assert.Equal(9, collection.Count);
            Assert.Equal(77, collection[8]);
            Assert.Throws <IndexOutOfRangeException>(() => collection[9]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset0SlidingLeft_Offset0(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            0,
                            scheduler);

            // Act
            collection.SlideLeft();

            // Assert
            Assert.Equal(0, collection[0]);
        }
Exemple #7
0
        public void BuildingCollectionWith6969Elements_Reset_SwitchedCountFetchingOffsetAdjusted(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            bool switched = false;

            int CountFetcher() =>
            switched
                    ? 70
                    : 6969;

            using var collection = SlidingWindowFactory.CreateCollectionWithCustomCountFetcher(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      CountFetcher,
                      10,
                      10,
                      69);

            var previous = collection[0];

            switched = true;

            // Act
            collection.Reset();

            // Assert
            Assert.Equal(69, previous);
            Assert.Equal(60, collection[0]);
        }
Exemple #8
0
        public void BuildingCollectionWith6969Elements_Offset69WindowSize10DecreaseBy2_CountDecreasedLastElement76(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      10,
                      10,
                      69);

            // Act
            collection.DecreaseWindowSizeBy(2);

            Thread.Sleep(500); // wait for preloading

            // Assert
            Assert.Equal(8, collection.Count);
            Assert.Equal(76, collection[7]);
            Assert.Throws <IndexOutOfRangeException>(() => collection[8]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset6959WindowSize10Increase_CountIncreasedLastElement6968(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            6959,
                            scheduler);

            await collection.InitializationCompleted;

            // Act
            collection.IncreaseWindowSize();
            var _ = collection[10];
            await Task.Delay(50);

            // Assert
            Assert.Equal(11, collection.Count);
            Assert.Equal(6968, collection[10]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset69WindowSize10IncreaseBy2_CountIncreasedLastElement80(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      10,
                      10,
                      69);

            await collection.InitializationCompleted;

            // Act
            collection.IncreaseWindowSizeBy(2);
            var _ = collection[11];
            await Task.Delay(50);

            // Assert
            Assert.Equal(12, collection.Count);
            Assert.Equal(80, collection[11]);
        }
        public async Task BuildingCollectionWith6969Elements_Offset69WindowSize10DecreaseBy2_CountDecreasedLastElement76(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            69,
                            scheduler);

            await collection.InitializationCompleted;

            // Act
            collection.DecreaseWindowSizeBy(2);
            var _ = collection[7];
            await Task.Delay(50);

            // Assert
            Assert.Equal(8, collection.Count);
            Assert.Equal(76, collection[7]);
            Assert.Throws <IndexOutOfRangeException>(() => collection[8]);
        }
        public async Task BuildingCollectionWherePageFetcherIgnoresGivenPageSize23_70thEntry_69(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalIntegerWhereFetchersIgnorePageSize(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      23);

            await collection.InitializationCompleted;

            // Act
            var placeholder = collection[69];
            await Task.Delay(50);

            // Assert
            Assert.Equal(-1, placeholder);
            Assert.Equal(69, collection[69]);
        }
        public async Task BuildingCollectionWith6969Elements_124thEntry_123(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            100,
                            scheduler);

            scheduler.AdvanceBy(20);
            Assert.True(collection.InitializationCompleted.IsCompletedSuccessfully);

            // Act
            var placeholder = collection[123];
            await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false);

            scheduler.AdvanceBy(20);

            // Assert
            Assert.Equal(-1, placeholder);
            Assert.Equal(123, collection[123]);
        }
Exemple #14
0
        public async Task BuildingCollectionWherePageFetcherIgnoresGivenPageSize23_70thEntry_69(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalIntegerWhereFetchersIgnorePageSize(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            23,
                            10,
                            60,
                            scheduler);

            scheduler.AdvanceBy(20);
            Assert.True(collection.InitializationCompleted.IsCompletedSuccessfully);

            // Act
            var placeholder = collection[9];
            await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false);

            scheduler.AdvanceBy(20);

            // Assert
            Assert.Equal(-1, placeholder);
            Assert.Equal(69, collection[9]);
        }
Exemple #15
0
        public async Task BuildingCollectionWith6969Elements_MinusFirstEntry_ThrowsIndexOutOfRangeException(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var scheduler = new TestScheduler();

            await using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            100,
                            10,
                            6959,
                            scheduler);

            scheduler.AdvanceBy(20);
            await collection.InitializationCompleted.ConfigureAwait(false);

            Assert.True(collection.InitializationCompleted.IsCompletedSuccessfully);

            // Act + Assert
            Assert.Throws <IndexOutOfRangeException>(() => collection[-1]);
        }
        public async Task BuildingCollectionWith6969Elements_Reset_NothingChanged(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      10,
                      10,
                      69);

            await collection.InitializationCompleted;

            var _ = collection[0];
            await Task.Delay(50);

            // Act
            collection.Reset();
            await Task.Delay(50);

            var __ = collection[0];
            await Task.Delay(50);

            // Assert
            Assert.Equal(69, collection[0]);
        }
Exemple #17
0
        public void BuildingCollectionWith6969Elements_Offset6959WindowSize10Increase_CountIncreasedLastElement6968(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      10,
                      10,
                      6959);

            // Act
            collection.IncreaseWindowSize();

            Thread.Sleep(500); // wait for preloading

            // Assert
            Assert.Equal(11, collection.Count);
            Assert.Equal(6968, collection[10]);
        }
Exemple #18
0
        public void With6969ElementsAndPageSize100_GetAnElementFromEachPage_NoneDisposed(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var set = new ConcurrentBag <int>();

            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithCustomPageFetchingLogic(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100,
                      (offset, pSize) =>
                      Enumerable
                      .Range(offset, pSize)
                      .Select(i => Disposable.Create(() => set.Add(i)))
                      .ToArray(),
                      Disposable.Empty);

            // Act
            for (var i = 0; i <= 6900; i += 100)
            {
                var _ = collection[i];
            }

            // Assert
            Assert.Empty(set);
        }
        internal static ISlidingWindow <T> CreateCollectionWithCustomPageFetchingLogicAndCustomLeastRecentlyUsed <T>(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior,
            int count,
            int pageSize,
            int initialWindowSize,
            int initialWindowOffset,
            Func <int, int, T[]> pageFetchingLogic,
            T placeholder,
            int pageLimit,
            int removalCount,
            IScheduler scheduler)
        {
            var pageLoadingBehaviorCollectionBuilder = SlidingWindowBuilder.Build <T>(
                initialWindowSize,
                initialWindowOffset,
                pageSize,
                new EventLoopScheduler(),
                scheduler);
            var pageHoldingBehaviorCollectionBuilder =
                StandardPageHoldingBehaviorCollectionBuilder(
                    pageLoadingBehaviorCollectionBuilder,
                    pageLoadingBehavior,
                    (_, __) => placeholder);
            var fetchersKindCollectionBuilder =
                StandardFetcherKindCollectionBuilder(
                    pageHoldingBehaviorCollectionBuilder,
                    pageRemovalBehavior,
                    pageLimit,
                    removalCount);
            var indexAccessBehaviorCollectionBuilder =
                StandardIndexAccessBehaviorCollectionBuilder(
                    fetchersKindCollectionBuilder,
                    fetchersKind,
                    pageFetchingLogic,
                    () => count);

            var dataVirtualizingCollection =
                StandardDataVirtualizingCollection(
                    indexAccessBehaviorCollectionBuilder,
                    indexAccessBehavior,
                    () => placeholder);

            return(dataVirtualizingCollection);
        }
        internal static ISlidingWindow <int> CreateCollectionWithIncrementalIntegerWhereFetchersIgnorePageSize(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior,
            int count,
            int pageSize,
            int initialWindowSize,
            int initialWindowOffset,
            IScheduler scheduler)
        {
            var pageLoadingBehaviorCollectionBuilder = SlidingWindowBuilder.Build <int>(
                initialWindowSize,
                initialWindowOffset,
                pageSize,
                new EventLoopScheduler(),
                scheduler);
            var pageHoldingBehaviorCollectionBuilder =
                StandardPageHoldingBehaviorCollectionBuilder(
                    pageLoadingBehaviorCollectionBuilder,
                    pageLoadingBehavior,
                    (_, __) => - 1);
            var fetchersKindCollectionBuilder =
                StandardFetcherKindCollectionBuilder(
                    pageHoldingBehaviorCollectionBuilder,
                    pageRemovalBehavior,
                    10,
                    1);
            var indexAccessBehaviorCollectionBuilder =
                StandardIndexAccessBehaviorCollectionBuilder(
                    fetchersKindCollectionBuilder,
                    fetchersKind,
                    (offset, pSize) =>
                    Enumerable
                    .Range(offset, pageSize)         // <--- This is different! pageSize instead of pSize!
                    .ToArray(),
                    () => count);

            var dataVirtualizingCollection =
                StandardDataVirtualizingCollection(
                    indexAccessBehaviorCollectionBuilder,
                    indexAccessBehavior,
                    () => - 1);

            return(dataVirtualizingCollection);
        }
        public async Task BuildingCollectionWith6969Elements_Reset_SwitchedPageFetching(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var  scheduler = new TestScheduler();
            bool switched  = false;

            int[] PageFetcher(int offset, int size) =>
            switched
                    ? Enumerable.Range(offset + 1, size).ToArray()
                    : Enumerable.Range(offset, size).ToArray();

            await using var collection = SlidingWindowFactory.CreateCollectionWithCustomPageFetchingLogic(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            6969,
                            10,
                            10,
                            69,
                            PageFetcher,
                            -1,
                            scheduler);

            await collection.InitializationCompleted;

            var _ = collection[0];
            await Task.Delay(50);

            switched = true;

            // Act
            collection.Reset();
            await Task.Delay(50);

            var __ = collection[0];
            await Task.Delay(50);

            // Assert
            Assert.Equal(70, collection[0]);
        }
        internal static ISlidingWindow <int> CreateCollectionWithCustomCountFetcher(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior,
            Func <int> countFetcher,
            int pageSize,
            int initialWindowSize,
            int initialWindowOffset,
            IScheduler scheduler)
        {
            var pageLoadingBehaviorCollectionBuilder = SlidingWindowBuilder.Build <int>(
                initialWindowSize,
                initialWindowOffset, pageSize,
                new EventLoopScheduler(),
                scheduler);
            var pageHoldingBehaviorCollectionBuilder =
                StandardPageHoldingBehaviorCollectionBuilder(
                    pageLoadingBehaviorCollectionBuilder,
                    pageLoadingBehavior,
                    (_, __) => - 1);
            var fetchersKindCollectionBuilder =
                StandardFetcherKindCollectionBuilder(
                    pageHoldingBehaviorCollectionBuilder,
                    pageRemovalBehavior,
                    10,
                    1);
            var indexAccessBehaviorCollectionBuilder =
                StandardIndexAccessBehaviorCollectionBuilder(
                    fetchersKindCollectionBuilder,
                    fetchersKind,
                    (offset, pSize) =>
                    Enumerable
                    .Range(offset, pSize)
                    .ToArray(),
                    countFetcher);

            var dataVirtualizingCollection =
                StandardDataVirtualizingCollection(
                    indexAccessBehaviorCollectionBuilder,
                    indexAccessBehavior,
                    () => - 1);

            return(dataVirtualizingCollection);
        }
        public async Task With69ElementsAndPageSize10_GetAnElementFromEachPageDisposeCollection_AllDisposed(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var       scheduler  = new TestScheduler();
            const int expected   = 69;
            var       set        = new ConcurrentBag <int>();
            var       collection = DataVirtualizingCollectionFactory.CreateCollectionWithCustomPageFetchingLogic(
                pageLoadingBehavior,
                pageRemovalBehavior,
                fetchersKind,
                indexAccessBehavior,
                expected,
                10,
                (offset, pSize) =>
                Enumerable
                .Range(offset, pSize)
                .Select(i => Disposable.Create(() => set.Add(i)))
                .ToArray(),
                Disposable.Empty,
                scheduler);

            scheduler.AdvanceBy(20);
            Assert.True(collection.InitializationCompleted.IsCompletedSuccessfully);

            // Act
            for (var i = 0; i <= expected; i += 10)
            {
                var _ = collection[i];
                await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false);

                scheduler.AdvanceBy(20);
            }
            await collection.DisposeAsync();

            await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false);

            scheduler.AdvanceBy(20);

            // Assert
            Assert.Equal(expected, set.Count);
        }
        public void BuildingCollectionWith6969Elements_MinusFirstEntry_ThrowsIndexOutOfRangeException(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100);

            // Act + Assert
            Assert.Throws <IndexOutOfRangeException>(() => collection[-1]);
        }
        public void BuildingCollectionWith6969Elements_6001thEntry_6000(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100);

            // Act + Assert
            Assert.Equal(6000, collection[6000]);
        }
        public void BuildingCollectionWherePageFetcherIgnoresGivenPageSize23_70thEntry_69(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalIntegerWhereFetchersIgnorePageSize(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      23);

            // Act + Assert
            Assert.Equal(69, collection[69]);
        }
        public async Task BuildingCollectionWith6969Elements_Reset_SwitchedCountFetchingCountAdjusted(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            var  scheduler = new TestScheduler();
            bool switched  = false;

            int CountFetcher() =>
            switched
                    ? 9
                    : 6969;

            await using var collection = SlidingWindowFactory.CreateCollectionWithCustomCountFetcher(
                            pageLoadingBehavior,
                            pageRemovalBehavior,
                            fetchersKind,
                            indexAccessBehavior,
                            CountFetcher,
                            10,
                            10,
                            69,
                            scheduler);

            await collection.InitializationCompleted;

            var _ = collection[0];
            await Task.Delay(50);

            switched = true;

            // Act
            collection.Reset();
            await Task.Delay(50);

            var __ = collection[0];
            await Task.Delay(50);

            // Assert
            Assert.Equal(0, collection[0]);
            Assert.Equal(9, collection.Count);
        }
Exemple #28
0
        internal static IDataVirtualizingCollection <int> CreateCollectionWithIncrementalInteger(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior,
            int count,
            int pageSize,
            IScheduler scheduler)
        {
            var pageLoadingBehaviorCollectionBuilder = DataVirtualizingCollectionBuilder.Build <int>(
                pageSize,
                new EventLoopScheduler(),
                scheduler);
            var pageHoldingBehaviorCollectionBuilder =
                StandardPageHoldingBehaviorCollectionBuilder(
                    pageLoadingBehaviorCollectionBuilder,
                    pageLoadingBehavior,
                    (_, __) => - 1);
            var fetchersKindCollectionBuilder =
                StandardFetcherKindCollectionBuilder(
                    pageHoldingBehaviorCollectionBuilder,
                    pageRemovalBehavior,
                    10,
                    1);
            var indexAccessBehaviorCollectionBuilder =
                StandardIndexAccessBehaviorCollectionBuilder(
                    fetchersKindCollectionBuilder,
                    fetchersKind,
                    (offset, pSize) =>
                    Enumerable
                    .Range(offset, pSize)
                    .ToArray(),
                    () => count);

            var dataVirtualizingCollection =
                StandardDataVirtualizingCollection(
                    indexAccessBehaviorCollectionBuilder,
                    indexAccessBehavior,
                    () => - 1);

            return(dataVirtualizingCollection);
        }
        public void BuildingCollectionWith6969Elements_124thEntry_123(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = SlidingWindowFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100,
                      10,
                      120);

            // Act + Assert
            Assert.Equal(123, collection[3]);
        }
        public async Task BuildingCollectionWith6969Elements_6970thEntry_ThrowsIndexOutOfRangeException(
            PageLoadingBehavior pageLoadingBehavior,
            PageRemovalBehavior pageRemovalBehavior,
            FetchersKind fetchersKind,
            IndexAccessBehavior indexAccessBehavior)
        {
            // Arrange
            using var collection = DataVirtualizingCollectionFactory.CreateCollectionWithIncrementalInteger(
                      pageLoadingBehavior,
                      pageRemovalBehavior,
                      fetchersKind,
                      indexAccessBehavior,
                      6969,
                      100);

            await collection.InitializationCompleted;

            // Act + Assert
            Assert.Throws <IndexOutOfRangeException>(() => collection[6969]);
        }