Example #1
0
        public static MockItemsSource CreateDataSource(WinRTCollection data, bool supportsUniqueIds)
        {
            MockItemsSource mock = null;

            if (supportsUniqueIds)
            {
                mock = new MockItemsSourceWithUniqueIdMapping
                {
                    GetSizeFunc   = () => data.Count,
                    GetAtFunc     = (index) => data[index],
                    GetItemIdFunc = (index) =>
                    {
                        if (supportsUniqueIds)
                        {
                            return(data[index].ToString());
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }
                    }
                };
            }
            else
            {
                mock = new MockItemsSource
                {
                    GetSizeFunc   = () => data.Count,
                    GetAtFunc     = (index) => data[index],
                    GetItemIdFunc = (index) =>
                    {
                        if (supportsUniqueIds)
                        {
                            return(data[index].ToString());
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }
                    }
                };
            }

            data.VectorChanged += (s, e) => mock.OnItemsSourceChanged(e.ConvertToDataSourceChangedEventArgs());

            return(mock);
        }
Example #2
0
        public static MockItemsSource CreateDataSource <T>(ObservableCollection <T> data, bool supportsUniqueIds)
        {
            var mock = new MockItemsSource
            {
                GetSizeFunc            = () => data.Count,
                GetAtFunc              = (index) => data[index],
                HasKeyIndexMappingFunc = () => supportsUniqueIds,
                GetItemIdFunc          = (index) =>
                {
                    if (supportsUniqueIds)
                    {
                        return(data[index].ToString());
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            };

            data.CollectionChanged += (s, e) => mock.OnItemsSourceChanged(e);

            return(mock);
        }