示例#1
0
        /// <summary>
        /// Create a collection backed from a <see cref="ReactiveList{T}"/>
        /// </summary>
        /// <typeparam name="TItem">The type of item stored.</typeparam>
        /// <typeparam name="TKey">The key type</typeparam>
        /// <param name="readPageObservable"></param>
        /// <param name="keySelector"></param>
        /// <param name="maxPageSize"></param>
        /// <param name="onException"></param>
        /// <param name="collectionTouchedStrategy"></param>
        /// <returns></returns>
        /// <remarks>Uses a <see cref="KeyedReactiveListBacked{TItem,TKey}"/> using the provided onException and maxPageSize values.</remarks>
        public static ReadOnlyCollectionFromBackingStore <TItem> FromKeyedReactiveListPager <TItem, TKey>(Func <PageReadRequest, IObservable <PageReadResult <TItem> > > readPageObservable, Func <TItem, TKey> keySelector, int maxPageSize = 10, Func <PageReadRequest, Exception, IObservable <bool> > onException = null,
                                                                                                          ICollectionItemTouchedStrategy collectionTouchedStrategy = null)
            where TItem : class
        {
            // create the provider of the changesets
            var provider = KeyedReactiveListBacked.FromObservable(readPageObservable, keySelector, maxPageSize, onException);

            // this is our list which acts as the backing store for the above stuff...
            return(Create(provider, collectionTouchedStrategy));
        }
        public KeyedReactiveListChangeSetProviderTests()
        {
            var scheduler = Scheduler.Immediate;

            _pagingController = new Mock <IPagingController <CollectionModel> >();

            _pagingController.Setup(p => p.MaxPageSize).Returns(DefaultPageSize);

            _provider = new KeyedReactiveListBacked <CollectionModel, string>(_pagingController.Object, (m) => m.Key, scheduler, scheduler);

            _itemFirstSet = new List <CollectionModel>()
            {
                new CollectionModel()
                {
                    Key = "Key#1", Instance = "1"
                },
                new CollectionModel()
                {
                    Key = "Key#2", Instance = "1"
                }
            };

            _itemSecondSet = new List <CollectionModel>()
            {
                new CollectionModel()
                {
                    Key = "Key#3", Instance = "1"
                },
                new CollectionModel()
                {
                    Key = "Key#4", Instance = "1"
                }
            };

            _itemReplacementFirstSet = new List <CollectionModel>()
            {
                new CollectionModel()
                {
                    Key = "Key#1", Instance = "2"
                },
                new CollectionModel()
                {
                    Key = "Key#2", Instance = "2"
                }
            };

            _itemReplacementSecondSet = new List <CollectionModel>()
            {
                new CollectionModel()
                {
                    Key = "Key#3", Instance = "2"
                },
            };
        }